I'm writing a parser for ActionScript3, and I'm stuck
with the following problem.
In ActionScript, you can omit the semicolon (;). Furthermore, function
pointers are allowed.
I have the following (simplified) grammar:
PROGRAM : EXPRESSION
| PROGRAM ';' EXPRESSION
| PROGRAM EXPRESSION //omit ;
EXPRESSION : T_IDENTIFIER '(' EXPRESSION ')' // functioncall
| T_IDENTIFIER // variable
| '(' EXPRESSION ')'
| EXPRESSION "++"
| EXPRESSION "--"
| EXPRESSION '+' EXPRESSION
| EXPRESSION '-' EXPRESSION
| EXPRESSION '/' EXPRESSION
(etc.)
Now, when parsing the code
function ( var++ )
it's naturally unclear to the parser whether to treat this as
"function(var++);" or "function;var++;"
Interestingly enough, bison seems to choose the latter (from the
-r report):
state 1
4 EXPRESSION: T_IDENTIFIER . '(' EXPRESSION ')'
5 | T_IDENTIFIER . [$end, T_IDENTIFIER, ';', '(',
')', "++", "--", '+', '-', '/']
'(' shift, and go to state 5
'(' [reduce using rule 5 (EXPRESSION)]
$default reduce using rule 5 (EXPRESSION)
Is there some way to tell bison to prefer shifting to reducing in this
case?