For programming Assignment 1 Part 1 you need to
write recursive descent parser / evaluator for the following grammar:
A -> VARIABLE "=" A | E | EVAL VARIABLE
E -> “+” E T | “-'” E T | T
T -> “*” T F | "/" T F | F
F-> EXP “(“ F G “)” | G
G -> VARIABLE | DOUBLE | “(“ E “)“ | [ INVERSE] TRIG “(“ E “)“
| rads “(“ E “)” |
TRIG -> “cos'”| “sin'”| "tan"
INVERSE -> “arc”
EVAL -> “eval”
- Assume "+"/
"-" means regular double precision addition/subtraction ,
"*" means double precision multiplication
- Assume "/ "
means double precision division - don't assume that the denominator is
- Assume "^ "
means double precision exponentiation
- Assume Trig
operators have their natural meaning and take arguments expressed in
radians , and rads(degrees) converts a double precision degree value
- Assume a DOUBLE is
any valid double as defined by Java
- A VARIABLE is any
string viable variable name in Java and can't be "cos" ,
"sin" , "rads" , etc
- References to
unassigned variables should not generate an error.
- The action associated
with A is to print to standard out the value of the expression, if the
value of the expression can be computed. If the value can not be computed,
print out a symbolic (algebraic) representation as discussed in class.
- Remember that you
must build the parse tree first before any semantic actions
- Use JLex for lexical analysis
assignment using javacc
for the parser and lexer.
What You Should Hand In (and
program - Assignments 1and 2 (h/c)
- should be well
- should include
comments at the top that give the EBNF and a brief explanation of
- A sample run of your
program generated from my input (h/c)
- In addition to the
hardcopy to be turned in for this first project you need to mail me the
following as attachments
- Your source code
file(s) as a jar file
- A README file that
explains how to build and run the executable
implementation must be in Java and use JLex and javacc
data will be posted the week of 26 July.
( Note that there can be more than one
expression per line and more than one line per expression, tokens don't span
Due Dates, etc
Dates- see above
may work in group of up to two.
LATE PROGRAMS WILL BE ACCEPTED under any circumstance without written
student caught cheating will receive a zero!
If you have any questions