嗨,谁能帮我解决 Java8Lexer.py 文件中的以下错误?
我想在 python 环境(Jupytor Notebook)中为我的 java 源代码创建 AST 树。但是,我的 Java8Lexer.py 文件中出现一些语法错误,该文件是使用以下命令与解析器、侦听器和访问者文件一起自动生成的:
%%bash java -jar /path/antlr-4.12.0-complete.jar -Dlanguage=Python3 -visitor Java8.g4
当我运行下面的代码时,我的 Java8Lexer.py 文件出现错误
from antlr4 import *
from antlr4.tree.Trees import Trees
from Java8Lexer import Java8Lexer
from Java8Parser import Java8Parser
错误是:
Traceback (most recent call last):
File ~/opt/anaconda3/lib/python3.9/site-packages/IPython/core/interactiveshell.py:3398 in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
Input In [25] in <cell line: 3>
from Java8Lexer import Java8Lexer
File ~/Java8Lexer.py:634
return Character.isJavaIdentifierStart(Character.toCodePoint((chr)_input.LA(-2), (chr)_input.LA(-1)))
^
SyntaxError: invalid syntax
在 Lexer.py 文件中定义的以下方法的最后一行:
def JavaLetter_sempred(self, localctx:RuleContext, predIndex:int): if predIndex == 0: return Character.isJavaIdentifierStart(_input.LA(-1)) if predIndex == 1: return Character.isJavaIdentifierStart(Character.toCodePoint((char)_input.LA(-2),(char)_input.LA(-1)))