[antlr-interest] The Python target is in fact Jython target?

Tzu-Chien Chiu tzuchien.chiu at gmail.com
Tue Jun 19 02:42:36 PDT 2007


Hello, all.

I was looking for a decent Python parser for C source files, and I found ANTLR.

I am not an expert of Python nor Jython, but it seems to me that the
Python runtime package 'antlr3' comes with ANTLR source distribution
is for Jython because it imports java.util.Set and java.utl.HashSet.

However, due to the lack of support of distutils for Jython, I cannot
install runtime package 'antlr3' by Jython.

Traceback (innermost last):
 File "test.py", line 2, in ?
ImportError: no module named antlr3

Any idea?


Some references:

[1] A message in 2003 said the Python code generation target is in
fact for Jython. Is this status up to date?
[antlr-interest] Re: python generator for ANTLR progressing again
http://www.antlr.org/pipermail/antlr-interest/2003-October/005371.html

[2] I managed to install distutils to Jython with this patch
http://mail.python.org/pipermail/distutils-sig/2001-October/002613.html
but I still failed. The error message is:

C:\temp\Distutils-1.0.2>c:\jython2.2b2\jython.bat setup.py install
Traceback (innermost last):
 File "setup.py", line 31, in ?
 File "C:\temp\Distutils-1.0.2\distutils\core.py", line 101, in setup
 File "C:\temp\Distutils-1.0.2\distutils\dist.py", line 130, in __init__
AttributeError: 'instance' object has no attribute 'get___doc__'


[3] The files and error message generated by "Python"

Traceback (most recent call last):
 File "C:\temp\test.py", line 4, in <module>
   from CParserParser import CParserParser
 File "C:\temp\CParserParser.py", line 57
   self.Set types = None
                ^
SyntaxError: invalid syntax

<code file="test.py">
import string
import antlr3
from CParserLexer import CParserLexer
from CParserParser import CParserParser

char_stream = antlr3.ANTLRFileStream("MCLoader.cpp")
lexer = CParserLexer(char_stream)
tokens = antlr3.CommonTokenStream(lexer)
parser = CParserParser(tokens)
parser.entry_rule()
</code>

<code file="CParserParser.py">
# $ANTLR 3.0 CParser.g 2007-06-18 19:07:46

from antlr3 import *
from antlr3.compat import set, frozenset

import java.util.Set;
import java.util.HashSet;
....
class Symbols_scope(object):
   def __init__(self):
       self.Set types = None // Line 57
</code>


More information about the antlr-interest mailing list