The good news: I applied your technique and it seems to work! The new grammar will parse everything the old one did and the new syntax too.
The bad news: it's incredibly slow! The test suite which used to run in a few seconds now takes so long that I have to kill it on the complex grammar test.
expression : logical_expr /^\$/ { \$return = \$item[1]; }
logical_expr : comparison_expr logical_op logical_expr
{ [ \$item[2][0], \$item[2][1], \$item[1], \$item[3] ]
+}
| comparison_expr
{ \$item[1] }
comparison_expr : math_expr comparison_op comparison_expr
{ [ \$item[2][0], \$item[2][1], \$item[1], \$item[3]
+ ] }
| math_expr
{ \$item[1] }
math_expr : paren_expr math_op math_expr
{ [ \$item[2][0], \$item[2][1], \$item[1], \$item[3]
+ ] }
| paren_expr
{ \$item[1] }
paren_expr : '(' logical_expr ')' { \$item[2] }
| atom
logical_op : /\\|\\||or|&&|and/ { [ ${\BIN_OP}, \$item[1] ] }
comparison_op : /le|ge|eq|ne|lt|gt/ { [ ${\BIN_OP}, \$item[1] ] }
| />=?|<=?|!=|==/ { [ ${\BIN_OP}, \$item[1] ] }
math_op : /[-+*\\/\%]/ { [ ${\BIN_OP}, \$item[1] ] }
atom : function_call | var | literal
function_call : function_name '(' args ')'
{ [ ${\FUNCTION_CALL}, \$item[1], \$item[3] ] }
| function_name ...'(' logical_expr
{ [ ${\FUNCTION_CALL}, \$item[1], [ \$item[3] ] ] }
| function_name '(' ')'
{ [ ${\FUNCTION_CALL}, \$item[1] ] }
function_name : /[A-Za-z_][A-Za-z0-9_]*/
{ \$item[1] }
args : <leftop: logical_expr ',' logical_expr>
var : /[A-Za-z_][A-Za-z0-9_]*/ { \\\$item[1] }
literal : /-?\\d*\\.\\d+/ { \$item[1] }
| /-?\\d+/ { \$item[1] }
| <perl_quotelike> { \$item[1][2] }
Any ideas what might be going wrong?
-sam