COMP712 AJS Syntax

COMP712 Programming Languages Interpreter Project
COMP712 Programming Languages Interpreter Implementation Project
This document specifies a programming language called AJS (A JavaScript) which is a subset of ECMAScript 2018. The goal of the project is to implement an interpreter for AJS using Racket with the help of the SLLgen lexer and parser generator and the Datatype macro extension introduced by D. Friedman and M Wand in their book Essentials of Programming Languages, third edition.
The syntax is written in a variant of BNF described in A Human Engineered Variant of BNF, ACM SIGPLAN Notices, Vol. 15, issue 10, Oct. 1980, pp. 57-62. In the grammar below, bold font is used for keywords, italics for syntactic variables, ε for nothing, x … for zero or more repetitions of x.
names if-statement
block expression
::= statement…
::= const name = expression ;
| function name ( names ) block | return expression ;
| if-statement
| expression ;
::= | name ( , name )… ::= if ( expression ) block
else ( block | if-statement ) ::= { statement }
::= number
| true | false
| expression binary-operator expression | unary-operator expression
| expression binary-logical expression
| expression ( expressions )
| ( name | ( names ) ) => expression
| (name|(names))=>block
| expression ? expression : expression | ( expression )
::= +|-|*|/|%|===|!== | >|<|>=|<= ::= ε | expression ( , expression )... Constant declaration Function declaration Return statement Conditional statement Block statement Expression statement Name list Conditional statement Block statement Primitive number Primitive Boolean Primitive string Primitive list Name expression Binary operator combination Unary operator combination Logical composition Function application Lambda expression Lambda expression Conditional expression Parenthesized expression Binary operator Unary operator Logical composition Argument expressions binary-operator Unary-operator Binary-logical Expressions 程序代写 CS代考 加微信: cstutorcs COMP712 Programming Languages Interpreter Project Restrictions (a) Returnstatementsareonlyallowedinbodiesoffunctions. (b) Therecannotbeanewlinecharacterbetweenreturnandexpressioninreturnstatements. (c) There cannot be any newline characters between ( name | ( parameters ) ) and => in function
definition expressions.
(d) Implementations of AJS are allowed to treat function declaration as syntactic sugar for
constant declaration. Programmers need to ensure that functions are not called before their corresponding function declaration is evaluated.
Name (identifier) must start with _, $ or a letter and contain only _, $, letters or digits. Keywords are not allowed as names. Keywords include any of the words in bold in the syntax rules above.
Only decimal numbers are used, with an optional decimal point. Scientific notation is not allowed. Example numbers are therefore, 1234, -3456, and 567.8.
String is a possibly empty sequence of characters within double-quotes. For example, “This is a string.” Newline and other special characters can be represented as follows:
• Newline: \n
• Single quote: \’
• Double quote: \”
Single-line comments start with // and therefore any characters until the next newline character is ignored.
Library Function
There is no need to provide any sort of library function other than the arithmetic and Boolean operators shown in the syntax.
E. Lai Page | 2
程序代写 CS代考 加QQ: 749389476