I am using ANTLR to generate a Python lexer/parser (a.k.a. Python target
).
The official ANTLR page says: use Java to generate .py
files:
set CLASSPATH=.;antlr-complete.jar;%CLASSPATH%
java org.antlr.v4.Tool -Dlanguage=Python2 HelloWorld.g4
Okay, that worked fine. A bunch of .py
files were generated: HelloWorldLexer.py
, HelloWorldParser.py
, etc.
The ANTLR page then says: a graphic of the parse tree can be generated by applying Java to the .py
files:
set CLASSPATH=.;antlr-complete.jar;%CLASSPATH%
java org.antlr.v4.gui.TestRig HelloWorld message -gui < input.txt
That doesn't work, it generates this error: Can't load HelloWorld as lexer or parser
Aside from the small problem that it doesn't work (for me), how in the world can Java execute .py
files? Somehow Java must be firing up and using the Python interpreter? Perhaps if I got a better idea how Java is applied to Python files, I can figure out why I am getting the above error message. Any insights you can provide would be greatly appreciated. This is a related SO post: ANTRL4: Can't get Python ANTLR to generate a graphic of the parse tree
P.S. I installed the ANTLR Python runtime (antlr4-python2-runtime-4.5.tar.gz
) prior to doing the above.