in reply to Re: Order of Precedence in Parse::RecDescent grammar
in thread Order of Precedence in Parse::RecDescent grammar
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] }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Order of Precedence in Parse::RecDescent grammar
by blokhead (Monsignor) on Jun 01, 2005 at 18:21 UTC |