]> git.draconx.ca Git - cdecl99.git/commit
Restrict the contexts in which typedef names can appear.
authorNick Bowler <nbowler@draconx.ca>
Sat, 25 Jun 2011 12:52:17 +0000 (08:52 -0400)
committerNick Bowler <nbowler@draconx.ca>
Sat, 25 Jun 2011 13:08:57 +0000 (09:08 -0400)
commit1286c76a984392842c814af8479d270fe47b46cc
treeb9bb5a60ab8a3bab9a6e622a52630ede6c024b68
parentc82ec7af7cb9f910a3b4f73521d17a443d650f0f
Restrict the contexts in which typedef names can appear.

This should resolve a rather nasty ambiguity in the C grammar:

  [declaration] -> [declaration-specifiers] ;
                -> [type-specifier] [declaration-specifiers] ;
                -> int [declaration-specifiers] ;
                -> int [type-specifier] ;
                -> int [typedef-name] ;
                -> int [identifier] ;
                -> int x ;

versus

  [declaration] -> [declaration-specifiers] [init-declarator-list] ;
                -> [type-specifier] [init-declarator-list] ;
                -> int [init-declarator-list] ;
                -> int [init-declarator] ;
                -> int [declarator] ;
                -> int [direct-declarator] ;
                -> int [identifier] ;
                -> int x ;

The standard resolves this ambiguity by having a constraint that is not
part of the context-free grammar.  This ambiguity gets really nasty with
things like int f (x); -- is it a declaration of x with two type
specifiers or a declaration of f (a function with one parameter) with
with one type specifier?

A side-effect of this change is that the parser will now reject
declarations without any type specifiers at all, which probably makes
the error messages a bit less informative.
src/parse.y