This is a parser for a very simple language, having expressions with
four operators, assignment, variables and constants. The basic
grammer is this:
Asst | → | Id:=Expr; |
Expr | → | Expr(+|−)Term|Term |
Term | → | Term(*|/)Fact|Fact |
Fact | → | id|lit|(Expr) |
But the parsing technique used, recursive descent, cannot tolerate left
recursive rules. So we modify the grammer to:
Asst | → | Id:=Expr; |
Expr | → | Term{(+|-)Term} |
Term | → | Fact{(*|/)Fact} |
Fact | → | id|lit|(Expr) |
The idea is to build functions which match each left side symbol
by trying to match the right-hand side.
This program prints an abstract syntax for its input.