## ANTLR

### Description

Invokes the ANTLR Translator generator on a grammar file.

To use the ANTLR task, set the target attribute to the name of the grammar file to process. Optionally, you can also set the outputdirectory to write the generated file to a specific directory. Otherwise ANTLR writes the generated files to the directory containing the grammar file.

This task only invokes ANTLR if the grammar file (or the supergrammar specified by the glib attribute) is newer than the generated files.

Antlr 2.7.1 Note: To successfully run ANTLR, your best option is probably to build the whole jar with the provided script mkalljar and drop the resulting jar (about 300KB) into ${ant.home}/lib. Dropping the default jar (70KB) is probably not enough for most needs and your only option will be to add ANTLR home directory to your classpath as described in ANTLR `install.html` document.

Antlr 2.7.2 Note: Instead of the above, you will need antlrall.jar that can be created by the antlr-all.jar target of the Makefile provided with the download.

### Parameters

Attribute | Description | Required
target | The grammar file to process. | Yes
outputdirectory | The directory to write the generated files to. If not set, the files are written to the directory containing the grammar file. | No
glib | An optional super grammar file that the target grammar overrides. This feature is only needed for advanced vocabularies. | No
debug | When set to "yes", this flag adds code to the generated parser that will launch the ParseView debugger upon invocation. The default is "no". Note: ParseView is a separate component that needs to be installed or your grammar will have compilation errors. | No
html | Emit an html version of the grammar with hyperlinked actions. | No
diagnostic | Generates a text file with debugging infomation based on the target grammar. | No
trace | Forces all rules to call traceIn/traceOut if set to "yes". The default is "no". | No
traceParser | Only forces parser rules to call traceIn/traceOut if set to "yes". The default is "no". | No
traceLexer | Only forces lexer rules to call traceIn/traceOut if set to "yes". The default is "no". | No
traceTreeWalker | Only forces tree walker rules to call traceIn/traceOut if set to "yes". The default is "no". | No
dir | The directory to invoke the VM in. | No

### Nested Elements

`ANTLR` supports a nested `<classpath>` element, that represents a PATH like structure. It is given as a convenience if you have to specify the original ANTLR directory. In most cases, dropping the appropriate ANTLR jar in the normal Ant lib repository will be enough.

#### jvmarg

Additional parameters may be passed to the new VM via nested `<jvmarg>` attributes, for example:

    <antlr target="...">
      <jvmarg value="-Djava.compiler=NONE"/>
      ...
    </antlr>

would run ANTLR in a VM without JIT.

`<jvmarg>` allows all attributes described in Command line arguments.

### Example

>     <antlr
>         target="etc/java.g"
>         outputdirectory="build/src"
>     />

This invokes ANTLR on grammar file etc/java.g, writing the generated files to build/src.

Copyright © 2000-2003 Apache Software Foundation. All rights Reserved.