Does C11's _Generic further complicate parsing?

Discussion in 'C Programming' started by David Librik, May 25, 2014.

  1. David Librik

    David Librik Guest

    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
     
    David Librik, May 25, 2014
    #1
    1. Advertisements

  2. It's not. _Generic is a form of expression.
    No, it's fine.
     
    Ben Bacarisse, May 25, 2014
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.