ANTLRWorks - How to work with Python 2.5 grammar

600 Views Asked by At

I need to find ANTLR grammar for Python (I found this, on antlr site http://www.antlr3.org/grammar/1200715779785/Python.g) Then i need to test grammar and to add AST. I planned to do this in ANTLRWorks, but I can't figure it out. In this grammar says that i need additional file PythonTokenStream.java and I found that too but I don't know how to set it up. My question is:

  • How to test python code examples with this grammar in ANTLRWorks (I did this by opening grammar with ANTLRWorks , Generate>Generate Code, Run>Debug)?
  • How to use this additional PythonTokenStream.java file?

I'm totaly new with ANTLR so every help is welcome.

1

There are 1 best solutions below

1
On

A useful example use of ANTLR for python is the parser used in the jython library: https://bitbucket.org/jython/jython. It makes use of the same grammar file. Check out the repository and look in the src/org/python/antlr directory. You should run the build script (cd into the root directory and run ant) and then look in build/gensrc. ANTLR works by generating a bunch of source files into this directory using the grammar file. You can look at build.xml to get a sense of the process.