next up previous
Next: Tracking current context Up: Identifier classification Previous: Identifier classification

Reporting the classification

The specification given in Section 1.1.3 results in a scanner that invokes the token processor IdnOrType when it recognizes a character sequence obeying the definition of a C identifier. A token processor is responsible for reporting the syntactic classification of the token and its internal representation (if any) to the parser.

Invoking the token processor mkidn establishes the internal representation of the identifier. Here are the steps for classifying it:

  1. If the identifier is bound to typedef_name in the current context, classify it as a typedef_name.

  2. If the identifier lies within a struct_declaration_list, but not within the parameter list of a function declarator, classify it as a member_def.

  3. If the identifier lies within an init_declarator_list in a declaration having a typedef storage class specifier, but not within the parameter list of a function declarator, classify it as a typedef_def.

  4. Otherwise classify it as an identifier.

After classifying the identifier, IdnOrType saves some information for later binding:

IdnOrType(char *start, int length, int *syncode, int *rep)[28]:

/* Obtain the internal representation of an identifier
 *   On entry-
 *     start points to the character string for the identifier
 *     length=length of the character string for the identifier
 *     syncode points to a location containing the initial terminal code
 *     Context.SynCode in [member_def, typedef_def, identifier]
 *   On exit-
 *     syncode has been set to the terminal code
 *     rep has been set to the internal coding
 *     Context.Symbol=string table index of the token
 ***/
{
  mkidn(start, length, syncode, rep);

  *syncode = GetSynCode(KeyInEnv(CurrentEnv, *rep), Context.SynCode);
  if (*syncode == identifier && Context.SynCode != identifier)
    *syncode = Context.SynCode;

  Instance information for binding[41]
}
This macro is invoked in definition 55.

CurrentEnv, the set of bindings currently valid, is described in Section 1.3.3.

IdnOrType may deliver a classification that is not allowed by the grammar. In that case, the generated parser will call Reparatur in an attempt to get the token reclassified. Two reclassifications are possible:

Reparatur(POSITION *coord, int *syncode, int *rep)[29]:

/* Repair a syntax error by changing the lookahead token
 *   On entry-
 *     coord points to the coordinates of the lookahead token
 *     syncode points to the classification of the lookahead token
 *     rep points to the representation of the lookahead token
 *   If the lookahead token has been changed then on exit-
 *     Reparatur=1
 *     coord, syncode and rep reflect the change
 *   Else on exit-
 *     Reparatur=0
 *     coord, syncode and rep are unchanged
 ***/
{
  if (*syncode == typedef_name && Context.SynCode == member_def) {
    *syncode = member_def;
    return 1;
  }
  if (*syncode != identifier) { *syncode = identifier; return 1; }
  return 0;
}
This macro is invoked in definition 55.


next up previous
Next: Tracking current context Up: Identifier classification Previous: Identifier classification
2008-08-30