I'm using jison (a javascript equivalent of Bison) and I'm having the following precedence problem. I'll illustrate it using the calculator demo http://zaach.github.com/jison/try/
It works fine as is. The precedence is
%left '+' '-'
%left '*' '/'
%left '^'
%left UMINUS
and the grammar is
e
: e '+' e
{$$ = $1+$3;}
| e '-' e
{$$ = $1-$3;}
| e '*' e
{$$ = $1*$3;}
| e '/' e
{$$ = $1/$3;}
| e '^' e
{$$ = Math.pow($1, $3);}
| '-' e %prec UMINUS
{$$ = -$2;}
If I change the '*' line to be
| e '*' e %prec TIMESPREC
{$$ = $1*$3;}
and change the precedence to
%left '+' '-'
%left TIMESPREC '/'
%left '^'
%left UMINUS
it doesn't work any more. Isn't it supposed to work the same? This could be useful, e.g., if one wanted to eventually have an algebra syntax where 2 x + 3 is parsed as (2x)+3.
Thanks!