Construction of RD Parser
The following are the steps for constructing an RD Parser:
The RHS of the rule is directly converted into program code, symbol by symbol.
- If the input symbol is non-terminal, then a call to procedure corresponding to the non-terminal is the mode.
- If the input is terminal, then it is matched with lookahead input.
- The lookahead pointer has to be advanced on matching the input symbol.
- If the production rule has many alternatives, then all the alternatives have to be combined into a single body of the procedure.
- The parser should be activated by a procedure corresponding to the start symbol.
Example:
Construct an RDP for
E ⟶ E + T / T
T ⟶ T * F / F
F ⟶ (Є) / id
Eliminating the immediate left recursion we get,
E ⟶ +TE’
E’ ⟶ +TE’ / Є
T ⟶ FT’
T’ ⟶ FT’ / Є
F ⟶ (Є) /id
Reference Link