繁体   English   中英

在python 2.6中使用antlr4 python运行时

[英]use antlr4 python runtime with python 2.6

是否可以将antrr4 python运行时与python 2.6一起使用,还是最低要求的python 2.7版本? 我想在python 2.6.6随附的CentOS 6.3上使用它。 如果不可能,是否知道使用了python 2.7的哪些功能?

最后我可以自己回答。 无法在centos6.3(具有python 2.6.6)上使用antlr4-python2运行时,我已经安装了它并尝试了本示例 结果如下:

[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]$ 

您使用的示例写得不好。 input是内置Python函数的名称。 Lexer一个FileStream ,它可能会起作用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM