Reputation: 105
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
Reputation: 3704
For Windows:
It is assumed that you have installed Java you may check this from command line like picture below:
1- Go to http://www.antlr.org and download the Complete Antlr jar file like picture below
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:
5- Open Advanced system settings
6- Open Environment variables
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:
8- Now find and edit Path variable, simply add C:\Javalib;
to end of the line, like picture below:
9- Now let's test and see if it works! Simply write antlr in the command line, you should see something like this:
Done!
Upvotes: 5
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