You may change this variable and thereby cause the changed token to be returned to the parser instead of the original one. Calling this method switches you to the specified lexical state. However, care must be taken when using this method to switch states from the parser since the lexical analysis could be many tokens ahead of the parser in the presense of large lookaheads. In general, calling this method should be resorted to only when you cannot do it any other way. Using this method of switching states also causes you to lose some of the semantic checking that JavaCC does when you use the standard syntax.
Lexical actions have access to a set of class level declarations.
This allows these tokens to be recovered during parsing while at the same time these tokens do not participate in the parsing. JavaCC has been bootstrapped to use this feature to automatically copy relevant comments from the input grammar file into the generated files. This is clarified by the following example.