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: Akim Demaille
Subject: Re: Change to shift instead of reduce
Date: Wed, 5 Jun 2013 09:03:06 +0200

Le 4 juin 2013 à 20:47, Adam Smalin <address@hidden> a écrit :

> 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.

Be sure to read the whole section about precedence.

http://www.gnu.org/software/bison/manual/html_node/Precedence.html

> From my understanding since '.' is more important then DOLLAR it will win.

The wording is "'.' has higher precedence than '$'".

> 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

I think you did, yes.

> %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.
>> 
>> 
> _______________________________________________
> address@hidden https://lists.gnu.org/mailman/listinfo/help-bison




reply via email to

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