Next | Higher-Order Parsing | 17 |
The next simplest parser looks for a particular token:
sub lookfor_PLUS { my $tokens = shift; my $tok = first($tokens); if ($tok->type eq "+") { return ("+", rest($tokens)); } else { return; # failure } }
sub lookfor_NUMBER { my $tokens = shift; my $tok = first($tokens); if ($tok->type eq "NUMBER") { return ($tok->value, rest($tokens)); } else { return; # failure } }
Note that the "value" returned by lookfor_NUMBER is the value of the number token it finds
Next | Copyright © 2007 M. J. Dominus |