Failure of LL(1) Parsing
In this class, We discuss Failure of LL(1) Parsing.
For Complete YouTube Video: Click Here
The reader should have prior knowledge of constructing an LL(1) parsing table. Click Here.
Can LL(1) be constructed to all the grammar? No.
The below table shows the part of the LL(1) table construction.
In our last class, we discussed parsing input strings for acceptance.
In the parsing, we check the production present in the block of the parse table.
The above table shows two productions in one block. We had confusion about which production we needed to consider.
LL(1) is a predictive parser, so it should not have confusion to predict the production required.
Below we discuss a few more conditions.
If grammar is left recursive?
We need to eliminate left recursion and construct LL(1) because LL(1) needs to construct First and Follow Symbols.
After eliminating left recursion, it may or may not be possible to construct LL(1) table. We need to construct and check for possibilities.
If one block got more than two productions during the construction, the grammar is not LL(1).
If the grammar contains left factoring?
Eliminate left factoring and construct LL(1) grammar.
A – aα | aβ
The above example is left factoring.
With the input symbol ‘a’, we have two productions.
So LL(1) table will get two productions in the same block.
We need to eliminate left factoring and construct LL(1) table.
If the grammar is ambiguous?
No, we can not construct LL(1) table for ambiguous grammar.
The below grammar is ambiguous grammar.
S – A | a
A – a
The productions S – A and S – a come to the same block in the LL(1) table, and the First symbol for both productions is the same.