| Next | Higher-Order Parsing | 25 |
Here's expression():
# expression → "(" expression ")"
# | term ("+" expression | nothing)
$expression = alt(conc(lookfor("(")),
$Expression,
lookfor(")"),
conc($Term,
alt(conc(lookfor("+"), $Expression),
\¬hing));
This doesn't look great, but:
When you consider how much it's doing, it's amazingly brief, and
We can use operator overloading and rewrite it as:
$expression = L("(") - $Expression - L(")")
| $Term - (L("+") - $Expression | $nothing);
| Next | ![]() |
![]() |
Copyright © 2007 M. J. Dominus |