Next: , Up: Java Parsers


10.2.1 Java Bison Interface

(The current Java interface is experimental and may evolve. More user feedback will help to stabilize it.)

The Java parser skeletons are selected using the %language "Java" directive or the -L java/--language=java option.

When generating a Java parser, bison basename.y will create a single Java source file named basename.java. Using an input file without a .y suffix is currently broken. The basename of the output file can be changed by the %file-prefix directive or the -p/--name-prefix option. The entire output file name can be changed by the %output directive or the -o/--output option. The output file contains a single class for the parser.

You can create documentation for generated parsers using Javadoc.

Contrary to C parsers, Java parsers do not use global variables; the state of the parser is always local to an instance of the parser class. Therefore, all Java parsers are “pure”, and the %pure-parser and %define api.pure directives does not do anything when used in Java.

Push parsers are currently unsupported in Java and %define api.push_pull have no effect.

GLR parsers are currently unsupported in Java. Do not use the glr-parser directive.

No header file can be generated for Java parsers. Do not use the %defines directive or the -d/--defines options.

Currently, support for debugging and verbose errors are always compiled in. Thus the %debug and %token-table directives and the -t/--debug and -k/--token-table options have no effect. This may change in the future to eliminate unused code in the generated parser, so use %debug and %verbose-error explicitly if needed. Also, in the future the %token-table directive might enable a public interface to access the token names and codes.