first commit
This commit is contained in:
32
perl/Examples/Chap8/expr-parser-2.pl
Normal file
32
perl/Examples/Chap8/expr-parser-2.pl
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
|
||||
###
|
||||
### simple-expr-parser-2.pl
|
||||
###
|
||||
|
||||
## Chapter 8 section 4
|
||||
|
||||
use Parser ':all';
|
||||
use Lexer ':all';
|
||||
|
||||
my ($expression, $term, $factor);
|
||||
my $Expression = parser { $expression->(@_) };
|
||||
my $Term = parser { $term ->(@_) };
|
||||
my $Factor = parser { $factor ->(@_) };
|
||||
$expression = alternate(concatenate($Term,
|
||||
lookfor(['OP', '+']),
|
||||
$Expression),
|
||||
$Term);
|
||||
|
||||
$term = alternate(concatenate($Factor,
|
||||
lookfor(['OP', '*']),
|
||||
$Term),
|
||||
$Factor);
|
||||
|
||||
$factor = alternate(lookfor('INT'),
|
||||
concatenate(lookfor(['OP', '(']),
|
||||
$Expression,
|
||||
lookfor(['OP', ')']))
|
||||
);
|
||||
|
||||
$entire_input = concatenate($Expression, \&End_of_Input);
|
||||
Reference in New Issue
Block a user