Chapter 4: Syntax Analysis

Left recursion

. A top down parser with production A A α may loop forever

. From the grammar A A α | b left recursion may be eliminated by transforming the grammar to

A b R

R α R | ε

Left recursion is an issue of concern in top down parsers. A grammar is left-recursive if we can find some non-terminal A which will eventually derive a sentential form with itself as the left-symbol. In other words, a grammar is left recursive if it has a non terminal A such that there is a derivation

A + A a for some string a . These derivations may lead to an infinite loop. Removal of left recursion:

For the grammar A A a | ß , left recursion can be eliminated by transforming the original grammar as:

A ß R

R a R | ε