Lab | Assigned | Lab Due (Start of class) |
||
---|---|---|---|---|
29 | Jan | 12 | Feb |
Any argument could itself be a parenthesized, prefix expression. The string
Expression | Meaning |
(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 |
Parse.java | The skeleton for your predictive parser. |
addhaque.cup | The CUP grammar specification file. |
TestFiles | The directory of test files for this project |
make | Brings your work up-to-date by compiling modified files. |
java tdn file | Runs your top-down (recursive-descent) parser on file |
java bup file | Runs your bottom-up parser on file |
cd ~cs431/hw2/Soln followed by either of the above commands |
Runs my solution for you |
CUP specification for AddHaque: addhaque.cup | |
import java_cup.runtime.*; import hw2.*; import Common.Listing; terminal Integer number; terminal plus, minus, sum, product, times, negate, mean; terminal lparen, rparen; non terminal Integer Program, File, Lists, List, Expression; non terminal Integer Atom, Operand, Operands; start with Program; |
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 ; |