where when I parsed 4+1*2 before I got
Now I get$VAR1 = [ '4', '+', [ '1', '*', '2' ] ];
Ick... any good way to clean that up? It gets really nasty with more complex statements.$VAR1 = [ [ [ [ '4' ] ], '+', [ [ '1' ], '*', [ '2' ] ] ] ];
startrule: comparison_expr comparison_expr: additive_expr (comparison_op additive_expr { [ @item[1..2] ] })(s?) { [ $item[1], map { @ $_ } @{$item[2]} ] } comparison_op: />=?|<=?|!=|==?|le|ge|eq|ne|lt|gt/ additive_expr: multiplicative_expr (additive_op multiplicative_expr { [ @item[1..2] ] })(s +?) { [ $item[1], map { @ $_ } @{$item[2]} ] } additive_op: /[+-]/ multiplicative_expr: modulus_expr (multiplicative_op modulus_expr { [ @item[1..2] ] })(s? +) { [ $item[1], map { @ $_ } @{$item[2]} ] } multiplicative_op: /[*\/]/ modulus_expr: paren_expr ('%' paren_expr { [ @item[1..2] ] })(s?) { [ $item[1], map { @ $_ } @{$item[2]} ] } paren_expr: '(' comparison_expr ')' { $item[2] } | number number: /[+-]?\d+/ { $item[1] }
In reply to Re^2: Order of Precedence in Parse::RecDescent grammar
by suaveant
in thread Order of Precedence in Parse::RecDescent grammar
by suaveant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |