CIS 461/561 Assignment 5
Bottom Up Parsing and LR Grammars
Problem 1 (50 points)
(This is problem 5.1 from the Louden text.)
Consider the following grammar:
E → ( L ) | a
L → L , E | E
- Construct the DFA of LR(0) items for this grammar.
- Construct the SLR(1) parsing table.
- Show the parsing stack and the actions of an SLR(1) parser
for the input string ((a),a,(a,a)).
- Is this grammar an LR(0) grammar?
If not, describe the LR(0) conflict.
If so, construct the LR(0) parsing table and
describe how a parse might differ from an SLR(1) parse.
Problem 2 (50 points)
(This is based on problem 5.28 from the Louden text.)
Add the following to the CUP integer calculator specification
based on the yacc/bison one given in the text.
The version in the text is for yacc and C,
but here is a Java CUP version to use as a base.
- Integer division with the symbol /.
- Integer mod with the symbol %.
- Integer exponentiation with the symbol ^.
(Warning: this operator has higher precedence than
multiplication and is right associative.)
- Unary minus with the symbol -.
Consider using Double or BigInteger classes so your calculator can deal
with results larger than an int.