D
David Librik
A well-known hitch in parsing C is the fact that one must know whether a
symbol is a typedef or an identifier in order to parse certain kinds of
declaration syntax. The usual approach is for the parser to keep a symbol
table which the lexer consults, in order for the latter to return
TYPEDEF_NAME or IDENTIFIER; this is known in the compiler world as "the
lexer hack."
However, it isn't necessary to know any more than that; in particular, the
specific type of a symbol does not need to be tracked.
Does C11's _Generic interfere with this? That is, are there situations
where a given symbol may be resolved as an identifier or a typedef
depending on the type of some other symbol, which serves as the
controlling expression in a _Generic?
For instance, if the following were legal:
typedef int _Generic(x+y, int:a, double:b);
it would be necessary to determine the types of x and y, and apply the
usual arithmetic conversions, _at parse time_ to determine what to tell
the lexer to do when it sees 'a' or 'b'.
Even if this is not legal, can an example be constructed which
demonstrates that parsing is now "type-complete"? Or are we still safe?
- David Librik
(e-mail address removed)
symbol is a typedef or an identifier in order to parse certain kinds of
declaration syntax. The usual approach is for the parser to keep a symbol
table which the lexer consults, in order for the latter to return
TYPEDEF_NAME or IDENTIFIER; this is known in the compiler world as "the
lexer hack."
However, it isn't necessary to know any more than that; in particular, the
specific type of a symbol does not need to be tracked.
Does C11's _Generic interfere with this? That is, are there situations
where a given symbol may be resolved as an identifier or a typedef
depending on the type of some other symbol, which serves as the
controlling expression in a _Generic?
For instance, if the following were legal:
typedef int _Generic(x+y, int:a, double:b);
it would be necessary to determine the types of x and y, and apply the
usual arithmetic conversions, _at parse time_ to determine what to tell
the lexer to do when it sees 'a' or 'b'.
Even if this is not legal, can an example be constructed which
demonstrates that parsing is now "type-complete"? Or are we still safe?
- David Librik
(e-mail address removed)