There are two possible ways to interface a Bison-generated Java parser
with a scanner: the scanner may be defined by
%code lexer, or
defined elsewhere. In either case, the scanner has to implement the
Lexer inner interface of the parser class.
In the first case, the body of the scanner class is placed in
%code lexer blocks. If you want to pass parameters from the
parser constructor to the scanner constructor, specify them with
%lex-param; they are passed before
%parse-params to the
In the second case, the scanner has to implement the
which is defined within the parser class (e.g.,
The constructor of the parser object will then accept an object
implementing the interface;
%lex-param is not used in this
In both cases, the scanner has to implement the following methods.
This method is defined by the user to emit an error message. The first parameter is omitted if location tracking is not active. Its type can be changed using
%define api.location.type "class-name
Return the next token. Its type is the return value, its semantic value and location are saved and returned by the their methods in the interface.
%define lex_throwsto specify any uncaught exceptions. Default is
Return respectively the first position of the last token that
yylexreturned, and the first position beyond it. These methods are not needed unless location tracking is active.
The return type can be changed using
%define api.position.type "class-name