LL(1) or Not Examples

In this class, We discuss LL(1) or Not Examples.

For Complete YouTube Video: Click Here

The reader should have prior knowledge of the failure of LL(1). Click Here.

We take a few examples and understand how to check LL(1) or not?

Example:

1) A – α | β | Γ

First(α) = a

First(β) = a

The productions A – β and A – α both come to the same block.

S – aSa | bS | c

All three productions first symbols are different, and the three productions come to different blocks in the table.

The below diagram shows the LL(1) table.

2) if the productions are of form A – α | ε

We need to calculate first and follow symbols.

If first and follow have common symbols, then not LL(1). because A – ε, and A – α come in the same block.

Example:

S – aAbB | bAaB | ε

A – S

B – S

First(S) = {a,b,ε}

Follow(S) = (a,b,$)

We have common symbols. So S – ε, and S -aAbB come to the same block.

Example 3:

S – A

A – Bb | Cd

B – aB | ε

C – cC | ε

Take the production A – Bb | Cd.

Each production has different first symbols. So each production comes to a different block in the table.

A – Bb First(B) = {a, ε}

If we place epsilon in B we get First(A – Bb) ={a,b}

Similarly, for other production A – Cd, we get the First symbols c,d.

Non-Terminal B and C have epsilon production.

From the above second condition, First and follow symbols for the non-terminal B should be different.

Similarly, we check for non-terminal C.

No block contains two productions, so LL(1).

Example 4:

S – iEtSS’ | a

S’ – eS | ε

E – b

The First(S’) = {e, ε}

Follow(S’) = {e}

Same symbols for First and Follow. So not an LL(1) Grammar.