1

I have a grammar:

S → SL | ε
L → A; | E; | C;
E → (EBE) | N | V
A → let V =E
C → while E do S | while E do S else S
B → + | - | * | >
V → x | y | z
N → ND | N0 | D
D → 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 

I am trying to build the parse table for me to be able to prove that it is not an LL(1) grammar. I am currently stuck of finding the FIRST set for S. I keep getting S in the set and cannot reach a terminal of G. What would FIRST(SL) be?

When I do FIRST(SL), I keep going back to FIRST(S), which goes to FIRST(SL) ⋃ FIRST(ε) = FIRST(S) ⋃ {ε}, and the FIRST(S) will repeat itself over and over.

1 Answer 1

1

Capital letters represent non-terminals. Small letters represent terminals.

First and Follow are the TERMINAL symbols that precede or succeed a terminal or a non terminal (in a pre order traversal of the parse tree).

For all A -> xYZ
First (A) = {x}
For all A-> Xyz
First (A) = First(X)
For all A-> εYZ
First (A) = First(Y)

Take the union of all these terminal symbols.

Sign up to request clarification or add additional context in comments.

3 Comments

I'm sorry but can you elaborate further? I'm not sure what you mean. Those just look like the basic rules for the FIRST set. Thank you!
I understand, but when if I do FIRST(SL), I keep going back to FIRST(S), which goes to FIRST(SL) ⋃ FIRST(ε) = FIRST(S) ⋃ {ε}, and the FIRST(S) will repeat itself over and over.
The third rule is what you want. If both the first and the follow sets are the same, then the grammar is not in LL(1) :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.