Antlr - Installation (Version 4)

1 - About

Installation of Antlr tool

3 - Type

3.1 - 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.

More … Antlr - Idea Plugin

3.2 - Windows

3.2.1 - Download antlr

3.2.2 - 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 $*


  • 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 %*


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

3.2.3 - Testing

Either launch org.antlr.v4.Tool directly:

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

4 - Documentation / Reference

Data Science
Data Analysis
Data Science
Linear Algebra Mathematics

Powered by ComboStrap