Parrot Perl6Grammar compiler and parsers #12

Subrules

grammar Calc::Grammar;
regex TOP     { <integer> <addop> <integer> }
regex integer { \d+ }
regex addop   { [ '+' | '-' ] }

Execution:

$ ./calc --target=parse
> 3+4
"parse" => PMC 'Calc;Grammar' => "3+4" @ 0 {
    <integer> => ResizablePMCArray (size:2) [
        PMC 'Calc;Grammar' => "3" @ 0,
        PMC 'Calc;Grammar' => "4" @ 2
    ]
    <addop> => PMC 'Calc;Grammar' => "+" @ 1
}

Note that we now have some structured output

Copyright © 2009
http://www.pmichaud.com/2009/pres/