help-bison
[Top][All Lists]
Advanced

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

Re: Change to shift instead of reduce


From: Adam Smalin
Subject: Re: Change to shift instead of reduce
Date: Tue, 4 Jun 2013 14:47:58 -0400

I put the below in my main project just to test it out so I don't have a
self contained source but the below should explain everything.

>From my understanding since '.' is more important then DOLLAR it will win.
Precedence is chosen the order nonassoc/left/right where the first seen is
least important. The conflict `VarName . '.'` VS `'$' VarName .`. So giving
the end of rule prec token it will see that its 'DOLLAR' which makes it not
give the ambiguity error. It sees '.' is a higher precedence then DOLLAR so
it will shift rather then reduce.

I think I said the above right

%nonassoc DOLLAR
%left '.'

%%
program: mEOS main
main: | mainLoop mEOS
mainLoop:
      mainElement
    | mainLoop mainElement
mainElement:
      '$' VarName     %prec DOLLAR    { printf("varname\n"); }
    | mainElement2
mainElement2:
      VAR             { printf("var\n"); }
    | Token         { printf("token\n"); }

Token: '.'
VarName: VAR
    | VarName  '.' VAR

EOS:   '\n' | ';'
mEOS:       | mEOS EOS

%%


On Tue, Jun 4, 2013 at 5:46 AM, Akim Demaille <address@hidden> wrote:

>
> Le 4 juin 2013 à 11:04, Adam Smalin <address@hidden> a écrit :
>
> > Nevermind I figured that out
>
> Great!
>
> Please, do try to make small self-contained examples when you
> can.
>
>


reply via email to

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