my $file; { open(my $fh, '<', ...) or die ...; local $/; $file = <$fh>; }
But it also seems that your grammar isn't complete. You've defined some basic blocks, but not how they fit together. If you just want a tokenizer, you can use something like
use strict; use warnings; use Parse::RecDescent; $::RD_ERRORS = 1; $::RD_WARN = 1; $::RD_HINT = 1; my $grammar = <<'__EOI__'; { use strict; use warnings; } tokenize : token(s?) /\Z/ { $item[1] } token : ident | binops | lbinops | number | integer | /./ { [ skip => $items[1] ] } ident : /[a-zA-Z][a-zA-Z0-9_]*/ { [ @items ] } binops : /\*\*|[+\-\/*%]/ { [ @items ] } lbinops : />=?|<=?|!|&&|\|\||==/ { [ @items ] } number : /-?[0-9]*\.[0-9]+/ { [ @items ] } integer : /-?[0-9]/ { [ @items ] } __EOI__ ... my @tokens = $parser->tokenize($file);
In reply to Re^3: Parsing and Translation pt.2
by ikegami
in thread Parsing and Translation pt.2
by speedyshady
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |