Hello I need some help regarding building a simple parse tree with antlr and java . I have tried to work with powershell to compile and run the grammar file ( which is the pascal.g4 file ) and I was hoping to generate some java files out of it , however at times when I tried to run it using the command " .\\antlr.bat -package pdl -o pdl .\\pascal.g4 " I get a message on the powershell stating " The system cannot find the file specified " .
I think the command I typed in might be wrong but anyway I have got the grammar file and I have got the .bat files ( grun.bat , java.bat & javac.bat ) and the antlr-4.5-complete.jar file .
I think these are basically all the files you need to build the parse tree . As for the folder location where all these files are located is C:\\Users\\Lenovo\\Documents\\test2 I have looked at some examples from others however I really now cannot go any further , can anybody please help me out here to build this .
Thank you
That batch file is little more than a hint.
Try being explicit with the paths and arguments -- and without trying to coerce Powershell into passing arguments in a manner compatible with batchfile execution.
Something like this:
@echo off
rem Execute the Antlr compiler/generator tool
SETLOCAL
set CLASSPATH=C:\Users\Lenovo\Documents\test2\antlr-4.5-complete.jar;%CLASSPATH%
cd /d C:\Users\Lenovo\Documents\test2\
"C:\Program Files\Java\jre8\bin\java.exe" org.antlr.v4.Tool pascal.g4
timeout 4
Here's the one-liner version I use, adopted from The Definitive ANTLR 4 Reference to use a relative reference to the directory containing the .CMD/.BAT file...
@java -cp %~dp0..\\ClassLib\\antlr-4.5-complete.jar;%CLASSPATH% org.antlr.v4.Tool %*
Use of %~dp0
helps avoid hardcoding an absolute path in it...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.