| Next | Higher-Order Parsing | 27 |
Here's something else that's common in programming languages
Comma-separated expression lists
Or semicolon-separated statement blocks
Or ...
sub list_of {
my ($item, $separator) = @_;
$separator = lookfor("COMMA") unless defined $separator;
conc($item, repeat($separator, $item), optional($separator));
}
Now comma-separated lists:
$list = conc(lookfor("("),
list_of($EXPRESSION),
lookfor(")"));
Semicolon-separated statement blocks:
$block = conc(lookfor("{"),
list_of($STATEMENT, lookfor(";")),
lookfor("}"));
We have now gone beyond Parse::RecDescent
| Next | ![]() |
![]() |
Copyright © 2007 M. J. Dominus |