CpS 450 Lecture Notes

Recursive Descent Parsing


A parser determines whether a sequence of tokens is legal given a grammar

Recursive Descent Parsing

A grammar in which each nonterminal appears only once on the LHS of a production can easily be transformed into a recursive descent parser:

Points to consider:

Common Prefix Removal





Left Recursion Removal

See p. 123 in textbook.

To refactor a grammar containing left recursion to one that does not contain left recursion, consider:

A → A a
    → B

where a and B are strings of terminals and nonterminals and B does not begin with an A.

Rewrite the grammar by replacing the original rule with a new rule that generates B first, and a new rule that generates 0 or more copies of a, using right recursion.