python - ANTLR 3.5.1(最新的 3.x 版本)和 Python 运行时 3.1.3(仅可用的 Python 运行时)

标签 python antlr antlr3

看起来 3.5.1 是最新的 3.x 版本,3.1.3 是唯一可用的版本 ( http://www.antlr.org/download/Python/ )。但是,当我尝试使用示例运行解析器时,我收到一条提示,说我的运行时版本与我的 ANTLR 版本不兼容:

$ PYTHONPATH=/home/dustin/build/antlr3/antlr_python_runtime-3.1.3 python SimpleCalcParser.py /tmp/lang 
Traceback (most recent call last):
  File "SimpleCalcParser.py", line 231, in <module>
    main(sys.argv)
  File "SimpleCalcParser.py", line 220, in main
    lexer = SimpleCalcLexer(char_stream)
  File "/home/dustin/development/antlr/antlr3/hello_world_python/SimpleCalcLexer.py", line 31, in __init__
    super(SimpleCalcLexer, self).__init__(input, state)
  File "/home/dustin/build/antlr3/antlr_python_runtime-3.1.3/antlr3/recognizers.py", line 1072, in __init__
    BaseRecognizer.__init__(self, state)
  File "/home/dustin/build/antlr3/antlr_python_runtime-3.1.3/antlr3/recognizers.py", line 184, in __init__
    self.antlr_version_str))
RuntimeError: ANTLR version mismatch: The recognizer has been generated by V3.0.1, but this runtime is V3.1.3. Please use the V3.0.1 runtime.

有人能让我走上正确的道路吗?由于可供下载的版本很少,我似乎无能为力。

最佳答案

如果您想使用 Python 运行时,您必须使用 ANTLR 3.1.3 生成 [Python] 词法分析器和解析器。

在此处下载 3.1.3:http://www.antlr3.org/download/antlr-3.1.3.jar

以下问答提供了一个有效的 Python 示例:ANTLR parsing MismatchedTokenException

关于python - ANTLR 3.5.1(最新的 3.x 版本)和 Python 运行时 3.1.3(仅可用的 Python 运行时),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19670153/

相关文章:

python - 当列名包含空格时删除多列 pandas

python - 在Python中解析XML : Multiple same attributes

netbeans - ANTLR netbeans 配置找不到或加载主类 org.antlr.Tool

java - 如何列出 Java 方法/函数中的所有局部变量?

parsing - 类香料语言识别器的语法

java - 提取特定规则或标记前的隐藏评论内容(Antlr、Java)

python - 使用 scipy.integrate.quad 积分 gamma 函数

python - 如何为 ConvLSTM2D 模型 reshape 多元时间序列数据

porting - ANTLR4语法集中的当前不支持规则引用

java - 在 ANTLR 中处理 EOF、空格和换行符