Is the grammar G = { S->L=R, S->R, R->L, L->*R | id } an LL(1) grammar?

Let’s determine whether the grammar
*G = { S → L = R | R, R → L, L → R | id }
is LL(1) using the formal criteria.


Step 1: Rewrite the Grammar

Let’s list the productions clearly:

S → L = R  
S → R  
R → L  
L → * R  
L → id

Step 2: Identify the Left Recursion

Notice:

  • S → L = R
  • S → R, and R → L ⇒ So, S → L

Now both S → L = R and S → L (indirectly), i.e., both productions of S begin with L.

And L → *R | id ⇒ FIRST(L) = { *, id }

This means:

  • S → L = R → starts with FIRST(L) = { *, id }
  • S → R → L → also starts with FIRST(L) = { *, id }

Thus, FIRST/FIRST conflict occurs between the two S productions.


Step 3: Apply LL(1) Grammar Rules

A grammar is LL(1) if, for each non-terminal A, and each pair of productions A → α and A → β:

  1. FIRST(α) ∩ FIRST(β) = ∅
  2. At most one of α or β derives ε (epsilon)
  3. If ε ∈ FIRST(β), then FIRST(α) ∩ FOLLOW(A) = ∅, and vice versa

Check for Conflicts

Let’s check S → L = R and S → R:

  • R → L, so S → L = R and S → L
  • Therefore, both alternatives of S derive strings starting with L
  • L → *R | id ⇒ *FIRST(L) = { , id }

Thus, *FIRST(L=R) ∩ FIRST(L) = { , id }
⇒ Not disjoint ⇒ FIRST/FIRST conflict


Final Answer:

No, the grammar is NOT LL(1) because:

  • It has FIRST/FIRST conflict for productions of S
  • It is left-recursive indirectly (via S → R → L and S → L = R)

Hence, this grammar cannot be parsed by an LL(1) parser without modifications like left recursion elimination and left factoring.

Leave a Reply

Your email address will not be published. Required fields are marked *