Scroll to navigation

ANTLR(1) General Commands Manual ANTLR(1)

NAME

ANTLR - ANother Tool for Language Recognition, version 4

SYNOPSIS

antlr4[options] file.g4 [ file2.g4 file3.g4 ...]

DESCRIPTION

ANTLR (ANother Tool for Language Recognition) is a parser generatorfor reading, processing, executing, or translating structured textor binary files. It's widely used to build languages, tools, andframeworks. From a grammar, ANTLR generates a parser that can buildand walk parse trees.

OPTIONS

Specify output directory where all output is generated.

ANTLR generates output files in the current directory by default. This optionspecifies the output directory where ANTLR should generate parsers, listeners,visitors, and tokens files.

Specify location of grammars, tokens files.

When looking for tokens files and imported grammars, ANTLR normally looks inthe current directory. This option specifies which directory to look in instead.It is only used for resolving grammar references for the import statement andthe tokenVocab option. The path to the primary grammar must always be fullyspecified.

Generate rule augmented transition network diagrams.

This option generates DOT graph files that represent the internal ATN (augmentedtransition network) data structures that ANTLR uses to represent grammars. Thefiles come out as Grammar.rule .dot. If the grammar is a combined grammar, thelexer rules are named Grammar Lexer.rule .dot.

Specify grammar file encoding; e.g., euc-jp.

By default ANTLR loads grammar files using the UTF-8 encoding, which is a verycommon character file encoding that degenerates to ASCII for characters that fitin one byte. If that grammar file is not the default encoding for your locale,you need this option so that ANTLR can properly interpret grammar files. Thisdoes not affect the input to the generated parsers, just the encoding of thegrammars themselves.

Specify output style for messages in antlr, gnu, vs2005.

ANTLR generates warning and error messages using templatesfrom directory tool/resources/org/antlr/v4/tool/templates/messages/formats.By default, ANTLR uses the antlr.stg (StringTemplate group) file. You can changethis to 'gnu' or 'vs2005' to have ANTLR generate messages appropriate for Emacsor Visual Studio. To make your own called X, create resourceorg/antlr/v4/tool/templates/messages/formats/X and place it in the CLASSPATH.

Show exception details when available for errors and warnings.

Generate parse tree listener (default).

Don't generate parse tree listener.

Generate parse tree visitor.

ANTLR can generate both parse tree listeners and visitors; this option and-listener aren’t mutually exclusive.

Don't generate parse tree visitor (default).

Specify a package/namespace for the generated code.

Use this option to specify a package or namespace for ANTLR-generated files.Alternatively, you can add a @header {...} action but that ties the grammarto a specific language. If you use this option and @header, make sure thatthe header action does not contain a package specification otherwise thegenerated code will have two of them.

Generate file dependencies.

Instead of generating a parser and/or lexer, generate a list of filedependencies, one per line. The output shows what each grammar depends on andwhat it generates. This is useful for build tools that need to know ANTLRgrammar dependencies.

If you use -lib libdir with -depend and grammar option tokenVocab=A, then the dependencies include the library path as well.


-Xforce-atn use the ATN simulator for all predictions
-Xlog dump lots of logging info to antlr-timestamp.log

Set or override a grammar-level option.

This option is useful for generating parsers in different languages withoutaltering the grammar itself (with --Dlanguage=CSharp for example).

Treat warnings as errors.

As part of a large build, ANTLR warning messages could go unnoticed. Turn onthis option to have warnings treated as errors, causing the ANTLR tool to reportfailure back to the invoking commandline shell.

Launch StringTemplate visualizer on generated code.

For those building a code generation target, this option brings up a windowshowing the generated code and the templates used to generate that code.It invokes the StringTemplate inspector window.

Wait for STViz to close before continuing.

Use the ATN simulator for all predictions.

ANTLR normally builds traditional “switch on token type” decisions wherepossible (one token of lookahead is sufficient to distinguish between allalternatives in a decision). To force even these simple decisions intothe adaptive LL(*) mechanism, use this option.

Dump lots of logging info to antlr-timestamp.log.

This option creates a log file containing lots of information messages fromANTLR as it processes your grammar. If you would like to see how ANTLRtranslates your left-recursive rules, turn on this option and look in theresulting log file.

SEE ALSO

http://www.antlr4.org