help-bison
[Top][All Lists]
Advanced

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

Re: reduce/reduce error confusing declaration with subscription


From: Tom Lieber
Subject: Re: reduce/reduce error confusing declaration with subscription
Date: Sun, 28 Dec 2008 03:07:27 -0500

On Sat, Dec 27, 2008 at 9:02 AM, Luca <address@hidden> wrote:
> Tom Lieber ha scritto:
>> I'm creating a parser for a C-like language, basing it on this ANSI C
>> grammar:
>>
>>  http://www.lysator.liu.se/c/ANSI-C-grammar-y.html
>>
>> I would like to change the syntax for declaring variables so that
>> instead of writing this:
>>
>>  int a[4], b[4];
>>
>> You write this:
>>
>>  int[4] a, b;
>
> Modify the grammar in the following way:
>
> declaration
>   : declaration_specifiers ';'
>   | declaration_specifiers init_declarator_list ';'
>   | declaration_specifiers '[' constant_expression ']' init_declarator_list
> ';'
>   ;
>
> I have added the third production: "int[4] a, b;" is parsed without generate
> conflicts in bison or syntax errors in the parser.

Thanks, but that's not recursive (so I can't stack pointers and
brackets like "int[4][4] a, b;"), and it's less general than I'd need
for it to carry over to other places in the grammar like function
definitions and another place I'll want it.

> Anyway I think it is more convenient for you to rewrite a C-like grammar
> subset rather than try to modify the ANSI C grammar according to your
> purposes.

The grammar I'm going for is very nearly C. This change, some
additional places where you can put declarations, and removal of
prototypes, structs, and enums are pretty much the only differences
between this language and ANSI C.

Are you saying there is an easier way to structure a grammar this
complex than the way the ANSI C one does (order of operations by
nesting)? That seems to be the only special thing about that grammar
compared to all the calculator language tutorials floating about,
which use %left and %prec, which I've had less luck expanding into a
full language.

-- 
Tom Lieber
http://AllTom.com/




reply via email to

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