help-bison
[Top][All Lists]
Advanced

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

reduce/reduce error confusing declaration with subscription


From: Tom Lieber
Subject: reduce/reduce error confusing declaration with subscription
Date: Sat, 27 Dec 2008 01:48:56 -0500

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;

The same goes for pointers. So asterisks and brackets will be stacked
after the data type like "int*[4]*" for a pointer to a 4-element array
of pointers to ints.

My problem is that I get a reduce/reduce warning now for my rules for
IDENTIFIER starting a declaration like "mytype[] a, b, c" and for
array subscripting like "x[1] = 2". "mytype" and "x" are both
IDENTIFIERs. I don't see why it is ambiguous, though... Why doesn't it
wait until it can tell whether it's a declaration (statement) or an
assignment_expression (expression_statement)? The -v output is below:

  state 19

     29 type_specifier: IDENTIFIER .
     98 primary_expression: IDENTIFIER .

      LIST        reduce using rule 29 (type_specifier)
      IDENTIFIER  reduce using rule 29 (type_specifier)
      '*'         reduce using rule 29 (type_specifier)
      '['         reduce using rule 29 (type_specifier)
      '['         [reduce using rule 98 (primary_expression)]
      $default    reduce using rule 98 (primary_expression)

The way I tried to make the change was to move '*' and '[' ']' from
the declarator and direct_declarator rules to the
declaration_specifiers rule, like this:

declaration_specifiers:
          storage_class_specifier type_specifier
        | type_specifier
        | declaration_specifiers '*'
        | declaration_specifiers '[' ']'
        | declaration_specifiers '[' expression ']'
        ;

Any help on disambiguating this?

By the way, what state does it go to after making those reductions?

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




reply via email to

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