Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to eliminate this Left Recursion for LL Parser

How do you eliminate a left recursion of the following type. I can't seem to be able to apply the general rule on this particular one.

A -> A | a | b

By using the elimination rule you get:

A  -> aA' | bA'
A' -> A'  | epsilon

Which still has left recursion.

Does this say anything about the grammar being/not being LL(1)?

Thank you.

like image 983
Airwavezx Avatar asked Sep 05 '25 03:09

Airwavezx


1 Answers

Notice that the rule

A → A

is, in a sense, entirely useless. It doesn't do anything to a derivation to apply this rule. As a result, we can safely remove it from the grammar without changing what the grammar produces. This leaves

A → a | b

which is LL(1).

like image 122
templatetypedef Avatar answered Sep 07 '25 21:09

templatetypedef