Does C11's _Generic further complicate parsing?

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)
 
B

Ben Bacarisse

David Librik said:
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,

It's not. _Generic is a form of expression.
can an example be constructed which
demonstrates that parsing is now "type-complete"? Or are we still
safe?

No, it's fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top