Next | Higher-Order Parsing | 23 |
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 |