Skip to content

[C] declarationSpecifiers is too greedy, take initDeclaratorList as typedefName #4676

@kevemueller

Description

@kevemueller

I am parsing C with the current C grammar in Java language and try to make sense of the parse tree.
I believe to have found a bug similar to #1979, in which a typedef appears instead of a directDeclarator.
As illustration, first a good parse:

typedef unsigned const int* x;

parses as:

Image

Note the clear distinction between declarationSpecifiers and initDeclaratorList.

Whereas the following

typedef unsigned const int x;

parses as

Image

The initDeclaratorList is missing, instead of being a directDeclarator the x is treated as yet another typeSpecifier.

The same erratic behaviour can be observed with

extern int* x;
extern int x;

The former being parsed properly, the latter not.

I am currently trying to write some post-processing logic to detect this, but it is not easy to distinguish the cases and it definitely messes with the situation at the wrong place (in the visitor) instead of in the grammar.

Any help is appreciated, this is currently a major blocker for proceeding with ANTLR (and this grammar).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions