0

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.

Community
  • 1
  • 1
Roger Costello
  • 3,007
  • 1
  • 22
  • 43
  • it would help if you link the page that says so – Andrey Aug 07 '15 at 10:47
  • Why do you ask the same question twice? Although some might consider this not be an exact duplicate: What you assume to happen does not happen. As I explained in my answer to your other question, you must first compile the java target, compile the `*.java` files into `*.class` files and then the testrig inspects those. So your question here is somewhat obsolete. – cfi Aug 07 '15 at 11:38

0 Answers0