CS 132 Fall 2004, Midterm Solution ================================== Question 1 ---------- A ::= y D D ::= x D | epsilon parsing table First Follow Nullable x y $ A {y} {$} No - yD - D {x} {$} Yes xD - epsilon Question 2 ---------- First Follow Nullable A {y,z} {x,$} Yes B {y} {y,z} Yes C {y,z} {x,$} No The grammar is NOT LL(1) because: B is nullable and y is in both First(B ::= yAx) and Follow(B) Question 3 ---------- Here is a sketch of the Java code: void A() { B(); if ( token == 'r' ) { get-next-token(); } else { error(); } if ( token != EOF ) error(); } void B() { if ( token == 'y' ) { get-next-token(); } else { error(); } C(); } void C() { if ( token == 'r' ) { get-next-token(); } else { if ( token == 'y' ) { B(); if ( token == 'r' ) { get-next-token(); } else { error(); } } else error(); } }