Now what I want to do is put the calls to $parser->startrule() inside a loop so that I can use it kind of like a command shell. When I ran my perl script I noticed that if there were some extra characters at the end of the buffer that were preceeded by whitespace the parse was succesfull eg. print a a How can I make sure that the call to $parser->startrule() will fail if there are extra characters at the end of the buffer?my $grammar = <<'_EOGRAMMAR_'; # Terminals (macros that can't expand further) # OP : m([-+*/%]) # Mathematical operators INTEGER : /[-+]?\d+/ # Signed integers VARIABLE : /\w[a-z0-9_]*/i # Variable expression : INTEGER OP expression { return main::expression(@item) } | VARIABLE OP expression { return main::expression(@item) } | INTEGER | VARIABLE { return $main::VARIABLE{$item{VARIABLE}} } print_instruction : /print/i expression { print $item{expression}."\n" } assign_instruction : VARIABLE "=" expression { $main::VARIABLE{$item{VARIABLE}} = $item{expre +ssion} } instruction : print_instruction | assign_instruction startrule: instruction(s /;/) _EOGRAMMAR_
In reply to how to match entire buffer with Parse::RecDescent by expo1967
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |