The language generated by this grammar includes Lisp-like prefix expressions such as
Any argument could itself be a parenthesized, prefix expression. The string
Here is an informal description of the language:
|(plus a b)||a + b|
|(minus a b)||a - b|
|(negate a)||- a|
|(sum a1 a2 ... aN)||sum of a1 through aN|
|(product a1 a2 ... aN)||product of a1 through aN|
|(mean a1 a2 ... aN)||(sum of a1 through aN) divided by N|
All values computed in this language are integer-valued, including the result computed by a mean expression.
|RecursiveDescent.java||The skeleton for your top-down, predictive parser.|
|addhaque.cup||The CUP grammar specification file from which a bottom-up parser is automatically constructed.|
|TestFiles||The directory of test files for this project|
|tdn.java||Contains the main for your top-down (recursive-descent) parser. There is a corresponding ant target tdn that executes the top-down parser on each test file in the TestFiles directory.|
The text contains techinques for this part in Section 5.5
Note: A Symbol type has two components:
- is the int reflecting the type of the symbol as defined in the sym class. That class is generated automatically in the autogen package when you run the build.
- is the object associated with the symbol. For example, for the number type, this is an Integer object
- Be certainly only to modify the RecursiveDescent.java file for this lab. No other files should be changed!
- Beware the use of global variables in either of the files you modify: global variables generally don't work well when there is recursion.
|CUP specification for AddHaque: addhaque.cup|
Program ::= File ; File ::= Lists ; Lists ::= Lists List | List ; List ::= lparen Expression rparen ; Expression ::= plus Operand Operand | minus Operand Operand | times Operand Operand | negate Operand | sum Operands | product Operands | mean Operands ; Operand ::= Atom ; Operands ::= Operands Operand | Operand ; Atom ::= List | number ;