Calling Convention
Previous: <Lexical=>Lexical> * Next: <Token Values=>TokenValue> * Up: <Lexical=>Lexical>

#Wrap on
{fH4}Calling Convention for {fCode}yylex{f}{f}

The value that {fCode}yylex{f} returns must be the numeric code for the type
of token it has just found, or 0 for end-of-input.

When a token is referred to in the grammar rules by a name, that name
in the parser file becomes a C macro whose definition is the proper
numeric code for that token type.  So {fCode}yylex{f} can use the name
to indicate that type.  \*Note <Symbols=>Symbols>.

When a token is referred to in the grammar rules by a character literal,
the numeric code for that character is also the code for the token type.
So {fCode}yylex{f} can simply return that character code.  The null character
must not be used this way, because its code is zero and that is what
signifies end-of-input.

Here is an example showing these things:

#Wrap off
#fCode
yylex ()
\{
  
  if (c == EOF)     \/\* Detect end of file. \*\/
    return 0;
  
  if (c == '+' || c == '-')
    return c;      \/\* Assume token type for `+' is '+'. \*\/
  
  return INT;      \/\* Return the type of the token. \*\/
  
\}
#f
#Wrap on

This interface has been designed so that the output from the {fCode}lex{f}
utility can be used without change as the definition of {fCode}yylex{f}.

