是否可以将antlr4 python运行时与python 2.6一起使用,或者是最小化所需版本python 2.7?我想在python 2.6.6附带的CentOS 6.3上使用它。如果不可能,是否知道使用了python 2.7的哪些特性?
答案 0 :(得分:0)
最后我可以自己回答这个问题。在centos6.3(有python 2.6.6)上使用antlr4-python2运行时是不可能的,我已经安装了它并尝试了this example。结果如下:
[lg@localhost py]$ python test.py data.txt
Traceback (most recent call last):
File "test.py", line 15, in <module>
main(sys.argv)
File "test.py", line 10, in main
tree = parser.r()
File "/home/lg/antlr/py/HelloParser.py", line 74, in r
self.enterRule(localctx, 0, self.RULE_r)
File "/usr/lib/python2.6/site-packages/antlr4/Parser.py", line 367, in enterRule
self._ctx.start = self._input.LT(1)
File "/usr/lib/python2.6/site-packages/antlr4/CommonTokenStream.py", line 85, in LT
self.lazyInit()
File "/usr/lib/python2.6/site-packages/antlr4/BufferedTokenStream.py", line 209, in lazyInit
self.setup()
File "/usr/lib/python2.6/site-packages/antlr4/BufferedTokenStream.py", line 212, in setup
self.sync(0)
File "/usr/lib/python2.6/site-packages/antlr4/BufferedTokenStream.py", line 134, in sync
fetched = self.fetch(n)
File "/usr/lib/python2.6/site-packages/antlr4/BufferedTokenStream.py", line 146, in fetch
t = self.tokenSource.nextToken()
File "/usr/lib/python2.6/site-packages/antlr4/Lexer.py", line 131, in nextToken
tokenStartMarker = self._input.mark()
AttributeError: 'builtin_function_or_method' object has no attribute 'mark'
[lg@localhost py]$
答案 1 :(得分:0)
您使用的示例写得不好。 input
是内置Python函数的名称。给Lexer
一个FileStream
,它可能会起作用。