Michel Mina
Michel Mina

Reputation: 105

How to install antlr4?

I read a lot in the antlr4 doc on github and I kind of understood how it works. The thing is I am not a pro java coder, I am trying to use antlr4 with python.

Anyway I reached a deadend on the step to execute this

antlr4 -Dlanguage=Python2 Hello.g4

I downloaded the antlr4 complete.jar but I don't know how to setup or use it. so any help?

Upvotes: 4

Views: 15705

Answers (2)

Ali.Ghodrat
Ali.Ghodrat

Reputation: 3704

For Windows:

It is assumed that you have installed Java you may check this from command line like picture below:

enter image description here

1- Go to http://www.antlr.org and download the Complete Antlr jar file like picture below

Antlr download page

2- Download Antlr.bat file: http://www.filedropper.com/antlr To be able to call Antlr from the command line from any directory.

3- Download Grun.bat file from http://www.filedropper.com/grun To be able to test the grammar and display various views of the parse tree.

4- Create a folder in C drive and name it "Javalib" and move all three files that you have downloaded to this folder, like picture below: enter image description here

5- Open Advanced system settings

enter image description here

6- Open Environment variables

enter image description here

7- From system variable, edit CLASSPATH variable and simply add line below to the variable value C:\Javalib\antlr-4.7.1-complete.jar; just like picture below:

enter image description here

8- Now find and edit Path variable, simply add C:\Javalib; to end of the line, like picture below:

enter image description here

9- Now let's test and see if it works! Simply write antlr in the command line, you should see something like this:

enter image description here

Done!

Upvotes: 5

Mike Lischke
Mike Lischke

Reputation: 53572

I found the -jar paramater easiest to use, so my command line (in a batch file) looks so:

set LOCATION=antlr4-4.5.4-SNAPSHOT.jar
java -jar %LOCATION% -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest TLexer.g4 TParser.g4

taken from the C++ ANTLR runtime demo. You don't need to change your classpath, nor have to add any environment variables (or doskeys).

Upvotes: 5

Related Questions