3. Objectives
To Eliminate Left recursion by rewriting the offending
production.
The non-terminal A and its productions are said to be left
recursive.
To replace left recursive by non left recursive production.
3
4. What is Left Recursion? 4
A grammar is left-recursive if and only if there exists a nonterminal
symbol that can derive to a sentential form with itself as the leftmost
symbol .
Symbolically, where indicates the operation of making one or more
substitutions, and is any sequence of terminal and nonterminal
symbols.
Consider a nonterminal A with two productions
A->A𝜶|β
So, the nonterminal A and its production are said to be left recursive.
5. Left Recursion’s Formula
There is a formal technique for eliminating left-recursion from
productions . It’s a direct left recursion.
Each rule which contains a left-recursive option
A --> Aα|β
Introduce a new nonterminal A' and rewrite the rule as
A --> βA'
A' --> αA' | ε
5
6. Working Procedure
For implementing the code we use C language
In the code segment, we declare char type variable.
Here we use sprintf() and strtok() function.
If we give a non-terminal left recursive expression as an input, then the
recursive value is eliminating.
Then a non-left recursive expression we get as an output.
6