first commit

This commit is contained in:
douboer
2025-09-17 16:08:16 +08:00
parent 9395faa6b2
commit 3ff47c11d5
1318 changed files with 117477 additions and 0 deletions

View 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);