help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

resolving shift/reduce in ActionScript3


From: Matthias Kramm
Subject: resolving shift/reduce in ActionScript3
Date: Wed, 26 Nov 2008 14:43:46 +0100
User-agent: Mutt/1.5.6i

Hi All,

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? 
(I'd rather not go down the GLR road just yet. I know I could add a
 second '(' token and make the lexer generate that instead of the
 "normal" '(' whenever at the "start" of an expression- but I was hoping 
 there might be an easier way I'm missing)

Thanks,

Matthias






reply via email to

[Prev in Thread] Current Thread [Next in Thread]