Table of Contents

About

Installation of Antlr tool

Type

Idea

Create a grammar file with the extension g4 and Idea should propose you to install the Antlr plugin

Right click on your g4 file, you should see the Antlr option.

Idea Antlr Right Click Options

More … Antlr - Idea Plugin

Windows

Download antlr

Create the commands

Create short convenient commands for the ANTLR Tool, and TestRig, using:

doskey

doskey commands

doskey antlr4=java -cp "C:\antlr\antlr-4.8-complete.jar" org.antlr.v4.Tool $*
doskey grun=java -cp ".;C:\antlr\antlr-4.8-complete.jar" org.antlr.v4.runtime.misc.TestRig $*

where:

  • cp is the classpath (not need if it's already in the environment variable)
    • points to the antlr library
    • and to the current directory for grun
batch files

antlr4.bat (where CLASSPATH)

set classpath=C:\antlr\antlr-4.8-complete.jar
java org.antlr.v4.Tool %*

grun.bat

set classpath=.;C:\antlr\antlr-4.8-complete.jar
java org.antlr.v4.runtime.misc.TestRig %*

Testing

Either launch org.antlr.v4.Tool directly:

antlr
ANTLR Parser Generator  Version 4.8
 -o ___              specify output directory where all output is generated
 -lib ___            specify location of grammars, tokens files
 -atn                generate rule augmented transition network diagrams
 -encoding ___       specify grammar file encoding; e.g., euc-jp
 -message-format ___ specify output style for messages in antlr, gnu, vs2005
 -long-messages      show exception details when available for errors and warnings
 -listener           generate parse tree listener (default)
 -no-listener        don't generate parse tree listener
 -visitor            generate parse tree visitor
 -no-visitor         don't generate parse tree visitor (default)
 -package ___        specify a package/namespace for the generated code
 -depend             generate file dependencies
 -D<option>=value    set/override a grammar-level option
 -Werror             treat warnings as errors
 -XdbgST             launch StringTemplate visualizer on generated code
 -XdbgSTWait         wait for STViz to close before continuing
 -Xforce-atn         use the ATN simulator for all predictions
 -Xlog               dump lots of logging info to antlr-timestamp.log
 -Xexact-output-dir  all output goes into -o dir regardless of paths/package

and perform the Getting started

Documentation / Reference