CMSC 431-
Assignment 1
Summer 2004
Assignment 1
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 ,
- Assume
"*" means double precision multiplication
- Assume "/ "
means double precision division - don't assume that the denominator is
non-zero.
- 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
to radians.
- 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 2
Repeat
assignment using javacc
for the parser and lexer.
What You Should Hand In (and
when)
- Your
program - Assignments 1and 2 (h/c)
- should be well
documented
- should include
comments at the top that give the EBNF and a brief explanation of
the technique
- 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
Notes
Implementation Details
- Your
implementation must be in Java and use JLex and javacc
Input data
Sample
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
lines.
Due Dates, etc
- Due
Dates- see above
- You
may work in group of up to two.
- NO
LATE PROGRAMS WILL BE ACCEPTED under any circumstance without written
approval.
- Any
student caught cheating will receive a zero!
If you have any questions
mail me.