in reply to Re^3: how to match entire buffer with Parse::RecDescent
in thread how to match entire buffer with Parse::RecDescent

I put in your suggested change and it does not solve anything for me. When I parse "a=2 print a" I get the value "2" printed bu I also get a parsing error. I am running on a Windows 10 64 bit system with perl 5, version 16, subversion 3 (v5.16.3) built for MSWin32-x64-multi-thread
  • Comment on Re^4: how to match entire buffer with Parse::RecDescent

Replies are listed 'Best First'.
Re^5: how to match entire buffer with Parse::RecDescent
by vr (Curate) on Mar 05, 2019 at 22:39 UTC

    OK, I'm at another computer, same system as yours, no older files but copied your code and my replacement from this thread, and downloaded portable Strawberry Perl v5.16.3

    C:\>perl rec.pl Enter --> a=2 print 2 2 Enter --> C:\>perl -MParse::RecDescent -wE "say $Parse::RecDescent::VERSION" 1.967015 C:\>perl -v This is perl 5, version 16, subversion 3 (v5.16.3) built for MSWin32-x +64-multi-thread

    Edit: I think failure to parse should prevent any changes to your "symbol table" i.e. %VARIABLE and suppress output from "print":

    # ... expression : INTEGER OP expression { main::expression(@item) } | VARIABLE OP expression { main::expression(@item) } | INTEGER | VARIABLE <defer: $main::VARIABLE{$item{VARIABLE}} ||= 0 > { $main::VARIABLE{$item{VARIABLE}}} print_instruction : /print/i expression <defer: print $item{expression}."\n" > assign_instruction : VARIABLE "=" expression <defer: $main::VARIABLE{$item{VARIABLE}} = $item +{expression} > # ...

    Enter --> a=1 Enter --> a=2 print a blah blah ERROR (line 1): Invalid instruction: Was expecting assign instr +uction, or print instruction Error returned by parsing Enter --> print a 1

    Though perhaps it's laughable because lacks serious studying about how it really must be built.