Luke Palmer wrote: > Also, if this is going to be an explanation rather than just a picture, > I suggest you go with Perl's usual versatile power, and store the > operators in a declarative data source. > > grammar RPN { > my @operator = << + - * / >>; > > rule input { <line>* } > rule line { <exp>? \n } > rule exp :w{ <NUM> | <@operator> } > > rule NUM { \d+ }
This becomes too weak. rule exp :w{ <NUM> | <exp> <exp> <@binary_operator> } is stronger. But it involves left-recursion, so it's typically better adapted to yacc-like parser generators. Probably not to P6 rules...