Midterm2 Spring2021 AnthonyLe
Midterm2 Spring2021 AnthonyLe
2. Given the following productions, and the string w = ‘abab’. Is this grammar ambiguous
and if so, explain ambiguity and show why? (30)
3. Remove all left recursions and backtracking in the following productions if needed. (30)
4. Define the First and Follow sets for each non-terminal symbol (30)
D − ONE
O − xy | b |
N − Ez | cd |
E − m | fg |
5. Given the following productions, construct the parsing table for table driven predictive
parser - it is a top-down parser. (30)
1) S − S & C 2) S − S @ C 3) S − C 4) C − x
6. Given the following production rules, write a recursive descent function that returns a
boolean value for the productions Q. Write the function using syntactically correct C, C++,
C#, python (for 20 points maximum) or pseudo code (15 points). Use any of the pre-existing
functions lexer(), getNextChar(), currentChar(), first(), follow(), token(), backup(), error()
or match() only if needed. (20 points total)
1) E − TQ 2) Q − #TQ 3) Q − ) − id
7. Given the following predictive parsing table, parse the string “ {xyx} ”
to see if it accepted. (30 points)
x y { } $
S CB CB
B yCB
C x {S}