CS132 HW1 LL(1) Parsing Solution
Grammar
-------
S->E$ (this is very important)
E->TE'
E'->+TE'
E'->-TE'
E'->e (e is epsilon)
T->FT'
T'->*FT'
T'->/FT'
T'->e
F->num (where num->0...9)
F->(E)
Note that 0..9, +, -, *, /, (, and ) are terminals
and that everything else is non-terminal.
First Set
---------
First(S)=First(E)
First(E)={num, (}
First(E')={+,-,e}
First(T)={num, (}
First(T')={*, /, e}
First(F)={num, (}
Follow Set
----------
Follow(S)={}
Follow(E)={), $}
Follow(E')={), $}
Follow(T)={+, -, ), $}
Follow(T')={+,-,),$}
Follow(F)={*, /, +, -, ), $}
Parsing Table
-------------
+ - * / ( ) num $
E ! ! ! ! ->TE' ! ->TE' !
E' ->+TE ->-TE ! ! ! ->e ! ->e
T ! ! ! ! ->FT' ! ->FT' !
T' ->e ->e ->*FT' /FT' ! T'->e ! T'->e
F ! ! ! ! ->(E) ! F->num !
Where the character ! denotes error.
Explanation of LL(1)
--------------------
No conflict/duplicates in the entry.
Lookahead is one symbol.
No left recursion in the grammar.
Factored grammar.
==============================================
Grading Criteria for 10 points
up to -2 points for incorrect grammar/typo/symbol
Additional -2 points for no precedence in the grammar.
up to -2 points for incorrect symbol in the first set
-1 if no epsilon or didn't say which symbols are nullable
-1 if no start state
up to -2 points for incorrect symbol in the follow set
-1 each mistake
-1 if no $ or EOF
up to -2 points for the table
-1 each mistake
up to -2 for incorrect or incomplete explanation of
why the grammar is LL(1).
-1 each missing explanation
-2 if didn't explain at all