next up previous
Next: Type names Up: Declarations Previous: Declarations

Declarators

Section 6.5.4 of the standard devotes separate subsections to pointer declarators, array declarators, and function declarators but does not distinguish these constructs syntactically. It is useful for semantic analysis to separate the forms of declarator that actually declare types from those that simply place identifiers.

The standard uses an optional pointer, and defines the pointer itself recursively. That definition not only leads to a grammar conflict, but the structure it imposes on the text does not correspond to the structure required by Section 6.5.4.1 of the standard.

Syntactic elements[16]:

declarator:
  pointer_declarator /
  direct_declarator .

direct_declarator:
  TypeIdDef   $'(' $')' &'Parameters?[52](`0')' /
  IdDef       $'(' $')' &'Parameters?[52](`0')' /
  '(' declarator ')' /
  array_declarator /
  function_declarator .

pointer_declarator:
  '*' type_qualifier_list_opt declarator .

type_qualifier_list:
  type_qualifier /
  type_qualifier_list type_qualifier .

array_declarator:
  direct_declarator '[' constant_exp_opt ']' .
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.

The block scope of a function definition begins at the beginning of the parameter list. Thus a (possible) parameter list of a function must be distinguished from the function prototypes that may form part of a complex declarator. The type rules in Section 6.5.4 of the standard show that the parameter list of a function definition is always the first modifier following the declarator's identifier. That identifier may, however, itself be enclosed in parentheses to arbitrary depth. The nonterminal declarator_name represents such an identifier. It can be reduced to a direct_declarator unless it is followed by a parameter list; in that case the following parameter list (represented by parameters is possibly the parameter list of the function definition.

Syntactic elements[17]:

function_declarator:
  direct_declarator '('        empty_parameter_type_list                ')' /
  direct_declarator
    '(' &'Nest[34](`identifier',`0')' parameter_type_list &'Restore[36]' ')' /
  TypeIdDef         '(' &'Parameters?[52](`1')' parameters              ')' /
  IdDef             '(' &'Parameters?[52](`1')' parameters              ')' .

parameter_type_list:
  parameter_list /
  parameter_list ',' '...' .

parameter_list:
  parameter_declaration /
  parameter_list ',' parameter_declaration.

parameter_declaration:
  declaration_specifiers declarator &'Deferred binding[46] End parameters[53]' /
  declaration_specifiers abstract_declarator /
  declaration_specifiers  .

parameters:
  parameter_list_1 /
  parameter_list_1 ',' '...' /
  [ identifier &'Bind[47]' // ',' ] .

parameter_list_1:
  parameter_declaration /
  parameter_list_1 ',' parameter_declaration.

TypeIdDef:
  typedef_def &'Defer the binding[45]' /
  '(' TypeIdDef ')' .

IdDef:
  identifier &'Defer the binding[45]' /
  '(' IdDef ')' .
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.


next up previous
Next: Type names Up: Declarations Previous: Declarations
2008-08-30