next up previous
Next: String literals Up: Lexical structure Previous: Identifiers

Constants

The classification of constants is carried out by a syntactic rule:

Syntactic elements[3]:

constant:
  floating_constant /
  integer_constant /
  character_constant .
This macro is defined in definitions 3, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, and 27.
This macro is invoked in definition 6.

A constant is one possible form of primary_expression (that is the only context in which constant appears in the grammar), and an identifier is another. Because an enumeration constant is an identifier, there would be an ambiguity in the grammar if enumeration_constant appeared in this definition of constant (as it does in the standard): Should the identifier be reduced directly to a primary_expression, or first to an enumeration_constant?

Information about the the declaration of an identifier is needed to distinguish an enumeration constant from a variable identifier in the context represented by constant, and this information is not available to the parser. Since the distinction is irrelevant in determining the structure of the tree anyway, it can simply be ignored.

Eli provides canned descriptions for C constants that implement the definitions found in Section 6.1.3.1, 6.1.3.2, and 6.1.3.4 of the standard:

Lexical elements[4]:

floating_constant:  C_FLOAT          [mkidn]
integer_constant:   C_INT_DENOTATION [mkidn]
character_constant: C_CHAR_CONSTANT  [mkidn]
This macro is defined in definitions 2, 4, and 5.
This macro is invoked in definition 1.

This specification uses mkidn to guarantee that there is only one copy of any constant in the string table.


next up previous
Next: String literals Up: Lexical structure Previous: Identifiers
2008-08-30