Antlr - Installation (Version 4)

Card Puncher Data Processing

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





Discover More
Card Puncher Data Processing
Antlr - Generated class

From the grammar The lexer rules will create the lexer class The parser rules will create the parser class The classes generated will contain a method for each rule in the grammar. See from...
Idea Antlr Right Click Options
Antlr - Getting Started (Hello World)

A getting started page that brings you in the world of Antlr. antlr/antlr4/blob/master/doc/getting-started.mdantlr4 getting-started Create a grammar file called Hello.g4 and define the grammar...
Card Puncher Data Processing
Antlr - antlr4.(bat|sh)

antlr4.(bat|sh) is the command line script of Antlr. See Installation Doc where D... is a grammar options. Example for the language:...



Share this page:
Follow us:
Task Runner