[C2hs] A problem parsing a C header

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Fri Dec 9 06:23:04 EST 2005


On Wed, 2005-12-07 at 00:12 +0100, Alain Cremieux wrote:
> Hi,
> I have a problem with c2hs parsing a file in graphviz.
> I have preprocessed it.
> The large file chokes on line 1243 (I think)
> The small one is archi reduced, but works on the same line.
> Any hint ?

Ah ha! Found it.

Here's a minimal test case:

typedef struct path {
} path;

typedef struct Agedgeinfo_t {
 int path;
} Agedgeinfo_t;


It's because the path has already been defined as a type identifer and
the parser is looking for a non-type identifer. However since it is
obviously allowed to name a variable the same as a typedef'ed name then
the parser should instead be looking for a non-type or type identifer.

However the change to the grammar to make this possible is non-trivial.

The grammar I was working from originally makes the same mistake.
http://www.lysator.liu.se/c/ANSI-C-grammar-y.html

The gcc grammar has a very complex way of partitioning the typedef and
non-typedef cases to allow a typedefed name to be reused as an
identifier in the right context.

I'm still looking into it.

Duncan



More information about the C2hs mailing list