The grammar productions presented for Alf in the main body of this document are intended to describe the lexical structure and syntax of the language in a way that is as clear as possible to a reader of the specification. However, the resulting grammar is not necessarily appropriate as the basis for automated parsing of the language. The grammar presented in this annex is equivalent to the normative grammar for Alf, but is specifically intended for use in automated parsing.
NOTE. This grammar has been implemented using JavaCC parser generator (https://javacc.dev.java.net/). The format of the lexical and syntactic productions in this annex is therefore as required for input to this tool.
The lexical analyzer is defined as a state machine that generates a sequence of tokens that are fed to the parser. The operation of this state machine is given by the set of productions listed below. Each production has the following form:
A list of names of the states in which the production is active. The analyzer begins in the DEFAULT state.
The action of the production, which is one of the following:
SKIP – Any text matched by the production is skipped and not passed to the parser.
TOKEN – Text matched by the production forms the image of a token that is passed to the parser.
MORE – Text matched by the production is buffered until the next match of a production with a SKIP or TOKEN action, at which time all buffered text is either skipped or used in the construction of a token respectively.
A list of alternatives, each of which consists of an optional name, a regular expressionand an optional target state. If the regular expression in an alternative matches the input text at the current position, then this text is consumed, the production action is carried out and the analyzer moves to the target state. If no target state is given, then the analyzer remains in the same state. If a name is given in a matching alternative and the production action is to produce a token, then the token is given that name.
Productions are checked in order, so earlier productions have precedence over later productions.