Simple look-ahead production
|Top Previous Next|
Examples > Java > Simple look-ahead production
The Java parser isn't LL (1) conform. The decision on the alternative to be chosen depends on a look-ahead of more than a single token. The IF and the WHILE construct of the TextTransformer allows such a foresight if in the respective condition a production is invoked for the look-ahead.
For example, if an identifier is recognized as next token in the statement production, then it isn't clear at first whether this identifier represents a label or an expression. It represents a label if a colon follows it.
So the progress is made dependent on the production isLabel
isLabel ::= ident ":"
isLabel can parse the following text exactly, if a colon follows the identifier. Altogether, the grammar alternatives are therefore tied into the following IF construct:
IF( isLabel() )
ident ":" Statement
This page belongs to the TextTransformer Documentation
|Home Content German|