CIS 461/561 Home Page Last updated 2008/04/26 21:03:23

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
LL , E | E
  1. Construct the DFA of LR(0) items for this grammar.
  2. Construct the SLR(1) parsing table.
  3. Show the parsing stack and the actions of an SLR(1) parser for the input string ((a),a,(a,a)).
  4. 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.

  1. Integer division with the symbol /.
  2. Integer mod with the symbol %.
  3. Integer exponentiation with the symbol ^. (Warning: this operator has higher precedence than multiplication and is right associative.)
  4. Unary minus with the symbol -.
Consider using Double or BigInteger classes so your calculator can deal with results larger than an int.