#!/home/rir/rakudo/parrot_install/bin/perl6 { grammar Calc { token TOP { } rule expression { } token lhs { } token rhs { } token numeric { \d+[\.\d*]? } token op { '-' | '+' | '*' | '/' | 'x' } } class Calc::Actions { method TOP($/) { make $.ast } method expression($/) { make eval "$/ $/.ast() $/" } method lhs($/) { make $/ } method rhs($/) { make $/ } method numeric($/) { make $/ } method op($/) { if ( $/ eq 'x') { make '*'; } else {make $/; } } } my $m = Calc.parse( "8.8 x 5.0 - 2", :actions( Calc::Actions)); die "dying no match" unless $m; say "$m = $m.ast()"; }