next up previous
Next: External Definitions Up: Syntactic structure Previous: Initialization

Statements

Syntactic elements[20]:

statement:
  labeled_statement /
  compound_statement /
  expression_statement /
  selection_statement /
  switch_statement /
  iteration_statement /
  jump_statement.
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 left context of the identifier in a labeled_statement is identical to that of a typedef_name in a declaration. Therefore the parser cannot provide any information that would allow the lexical analyzer to distinguish the label from a named type.

In the absence of parser information, the lexical analyzer will classify an identifier as an identifier or typedef_name depending on the context. Thus the parser must accept either of these terminals as a valid label.

Syntactic elements[21]:

labeled_statement:
  identifier ':' statement /
  typedef_name ':' statement /
  'case' constant_expression ':' statement /
  'default' ':' statement.

compound_statement:
  &'New region[49]' &'Nest[34](`identifier',`1')' '{' body &'Restore[36]' &'End region[50]' '}' .

decls: declaration / decls declaration .
stmts: statement / stmts statement .
body: / decls / stmts / decls stmts .
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.

Section 6.6.3 of the standard defines the expression and null statements in one syntax rule, using the expression_opt nonterminal. This implies that a null statement is really an expression statement in which the expression happens to be empty. Semantically, however, the null statement ``performs no operation''. Two alternatives express this situation more clearly:

Syntactic elements[22]:

expression_statement:
  expression ';' /
             ';' .
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.

There is a grammar conflict here between the first and second alternatives. This conflict is resolved by the modification $'else', which prevents reduction of the first alternative if the lookahead symbol is else.

Syntactic elements[23]:

selection_statement:
  'if' '(' expression ')' statement $'else' /
  'if' '(' expression ')' statement 'else' statement.

switch_statement:
  'switch' '(' expression ')' statement.
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.

According to Section 6.6.5.3 of the standard, the effects of omitting the initializer and the step of the for statement are the same; omitting the condition has a different effect. Since these effects must be distinguished in the abstract syntax tree, the grammar uses different symbols.

Syntactic elements[24]:

iteration_statement:
  'while' '(' expression ')' statement /
  'do' statement 'while' '(' expression ')' ';' /
  'for' '(' expression_opt1 ';' expression_opt2 ';' expression_opt1 ')'
    statement.
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.

Section 6.6.6.2 of the standard defines the two versions of the return statement in one syntax rule, using the expression_opt nonterminal. These two versions have different constraints, however. Two alternatives express this situation more clearly:

Syntactic elements[25]:

jump_statement:
  'goto' identifier   ';' /
  'continue'          ';' /
  'break'             ';' /
  'return'            ';' /
  'return' expression ';' .
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: External Definitions Up: Syntactic structure Previous: Initialization
2008-08-30