stmt → if expr then stmt
| if expr then stmt else stmt
| other
| stmt | → | matched_stmt |
| | | open_stmt | |
| matched_stmt | → | if expr then matched_stmt else matched_stmt |
| | | other | |
| open_stmt | → | if expr then stmt |
|   | → | if expr then matched_stmt else open_stmt |
| E | → | E + T |
| | | T | |
| T | → | T * F |
| | | F | |
| F | → | ( E ) |
| | | id |
A → Aα | Β becomes A → ΒA' A' → αA' | ε
A → Aα1 | Aα2 | ... | Aαm | Β1 | Β2 | ... | Βn becomes A → Β1A' | Β2A' | ... | ΒnA' A' → α1A' | α2A' | ... | αmA' | ε
S → Aa | b A → AC | Sd | ε
- arrange nonterminals in some order A1 A2 ... An
- for (each i from 1 to n) {
- for ( each j from 1 to i -1) {
- replace each production of the form Ai→ Ajγ with productions Ai → δ1γ | δ2γ| ... | δkγ where Aj→ δ1 | δ2 | ... | δk aer all current Aj productions.
- }
- eliminate the immedate left recursion among the Ai productions.
- }
- }