[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Expression grammar with call
From: |
John P. Hartmann |
Subject: |
Re: Expression grammar with call |
Date: |
Fri, 29 Nov 2013 13:45:57 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 |
Yes, it looks like you are confused.
If you don't want the scanner to distinguish between function calls and
identifiers, the grammar becomes simpler:
%error-verbose
%right '='
%left '+'
%token IDENTIFIER INTEGER
%%
expression: IDENTIFIER '=' expression
| expression '+' expression
| '( ' expression ')'
| primary
primary: IDENTIFIER
| INTEGER
| IDENTIFIER '(' expression ')'
%%
On 11/29/2013 01:05 PM, Philip Herron wrote:
> actually i think i am getting confused i will make a test case to show it.
>
>
> On 29 November 2013 11:54, Philip Herron <address@hidden>wrote:
>
>> hmm not sure should i use this: does it mean i should use flex to look at
>> the next token if it '('.
>>
>> Since it looks like IDENTIFIER '(' ...?
>>
>>
>> On 29 November 2013 09:15, John P. Hartmann <address@hidden> wrote:
>>
>>> %error-verbose
>>> %right '='
>>> %left '+'
>>> %token IDENTIFIER INTEGER CALL
>>> %%
>>>
>>> expression: IDENTIFIER '=' expression
>>> | expression '+' expression
>>> | '( ' expression ')'
>>> | primary
>>>
>>> primary: IDENTIFIER
>>> | INTEGER
>>> | CALL '(' expression ')'
>>> %%
>>>
>>> On 11/29/2013 09:54 AM, Philip Herron wrote:
>>>> Hey all,
>>>>
>>>> Its been a while since i've really seriously been working with bison but
>>>> say i have the grammar:
>>>>
>>>> %right '='
>>>> %left '+'
>>>>
>>>> expression: IDENTIFIER '=' expression
>>>> | expression '+' expression
>>>> | ...
>>>> | '( ' expression ')'
>>>> | primary
>>>>
>>>> primary: IDENTIFIER
>>>> | INTEGER
>>>>
>>>> What way should i go about adding support for something like:
>>>>
>>>> x = call ( )
>>>>
>>>> I get a shift/reduce conflict on this. Currently i have and it mostly
>>> works.
>>>>
>>>> parameter: expression
>>>>
>>>> parameter_list: parameter_list ',' parameter
>>>> | parameter
>>>>
>>>> call: IDENTIFIER '(' parameter_list ')'
>>>>
>>>> primary: IDENTIFIER
>>>> | INTEGER
>>>> | call
>>>>
>>>> Then if i want something like:
>>>>
>>>> x = mytype { x = 1, y = 2; }
>>>>
>>>> I was able to use %right '{' for this to work. But i am not sure how
>>> calls
>>>> should be implemented.
>>>>
>>>> Thanks
>>>>
>>>> --Phil
>>>> _______________________________________________
>>>> address@hidden https://lists.gnu.org/mailman/listinfo/help-bison
>>>>
>>>
>>>
>>> _______________________________________________
>>> address@hidden https://lists.gnu.org/mailman/listinfo/help-bison
>>>
>>
>>
>