In: Computer Science
Consider the following grammar G:
E -> E + T | T
T -> T F | F
F -> F* | a | b
This grammar can be used to generate regular expressions over
the alphabet {a,b} with standard precedence rules.
Show your solution for each of the following 5 points:
1. Remove left recursion and write the
resulting grammar G1.
2. For the grammar G1, compute and write the
sets FIRST for every right hand side of every production,
and the sets FOLLOW for every
left hand side (i.e. any non-terminal).
3. Find and write the table for a predictive
parser
4. Is G1 LL(1)? Justify your answer.
5. If the answer to (4) above is yes, then trace
parsing of: a* + ab*
1) Left Recursive Grammar leads to unterminated state. and the grammar is look like as follows
A ---> Aα/β (here A is repeated contineously)
for example consider this , above line can be look like this...
A(){
A() // this leads to unterminated condition
α
}
>>> In order to remove left recursion the grammar which is in the form A ---> Aα/β will be converted to following form.
A ---> βA'
A' ---> ε/αA'
>>> We need to identify what is alfa and what is beta and just replace it in the original form.
>>> after I have done all that the converted grammar is as follows.
E ---> TE'
E' ---> ε/+TE'
T ---> FT'
T' ---> ε/FT'
F ---> aF'/bF' (here we have two beta's)
F' ---> ε/*
2)Follow sets are
First(E) = {a,b}, First(E') = {ε,+}, First(T) = {a,b}, First(T') = {ε,a,b}, First(F) = {a,b}, First(F') = {ε,*}.
Follow(E) = {$} and follow of all other variables also is {$}.
3)
4)yes it is LL(1)
5)