CS536 Homework 6 Solution


Question 1:

    1. The shortest input that can be parsed is: NAME IDNUM EOF
    2. The parse tree is:
    1. The shortest sequence of tokens that would stump tha parser is: NAME IDNUM INTLIT
    2. The parse tree is:
    3. The parser cannot choose between these two rules:
      grades → oneGrade
      grades → oneGrade COMMA grades
  1. The rules with a common prefix are the ones with grades on the left. Here are the transformed rules:
    grades → oneGrade grades'
    grades' → ε | COMMA grades
  2. The rules with immediate left recursion are the ones with stars on the left. Here are the transformed rules:
    stars → STAR stars'
    stars' → STAR stars' | ε

Question 2:

Nonterminal X FIRST(X) FOLLOW(X)
program { EOF
stmts ID, if, ε }
stmt ID, if }, ID, if
exp ID ;, )
tail +, -, ε ;, )