http://qs321.pair.com?node_id=414890


in reply to Re^2: Left-associative binary operators in Parse::RecDescent
in thread Left-associative binary operators in Parse::RecDescent

Yeah, that's a good point. You'll need to get rid of the left-recursion. To do that, you'd need to get rid of binary_op and subexpression in your subexpression rule. Next, you'll need to factor out all of the paren stuff into a single rule, and then use that rule within the binary_op rule instead of subexpression. Here's an example:

paren: '(' binary_op ')' { \$item [2] } # parens belong here, and o +nly here! | subexpression subexpression: function_call | var | literal | <error> binary_op : paren (op paren { [ \@item[1..2] ] })(s?) # any +parenned expression will sink down here { [ \$item[1], map { \@\$_ } \@{\$item[2]} ] }