- or download this
my %actions =
'*' => { $^a * $^b },
...
'-' => { $^a - $^b };
...
make %actions{$<op>.ast}.(|$/<lhs rhs>)
- or download this
rule expression { <lhs=.numeric> <op> <rhs=.numeric> }
- or download this
method numeric($/) { make +$/ }
# ^ convert to a number
...
}
make $value;
}
- or download this
use v6;
grammar Calc {
...
say "$m<expression> = $m.ast()";
# vim: ft=perl6