Go to the first, previous, next, last section, table of contents.


Tokens

In the first example, only plain characters were used as tokens. Normally, however, tokens will consist of more than a single character. For example, numbers larger than 9 will take at least two characters. To tell the parser about such tokens, the `%token' directive is used to declare the names of the tokens. By convention, these names are in upper-case, whereas the non-terminal names are lower-case.

In the following example, the grammar accepts sentences with any number of `NUMBER' tokens. Note that it is up to the lexer to recognize such tokens in the input and return the proper token value to the parser.

%class ex2

%token NUMBER

language: NUMBER*;

The lexer for this parser must know about the NUMBER token as well. For our parser class `ex2', gp also generates a class `ex2Defines' that contains the definitions of the token values. Our lexer simply inherits from that class to access these values (see `ex2/Lexer.t').


Go to the first, previous, next, last section, table of contents.