antlr";java.lang.NoSuchFieldError“;论语法动作

antlr";java.lang.NoSuchFieldError“;论语法动作,java,parsing,exception-handling,antlr4,Java,Parsing,Exception Handling,Antlr4,我试图在语法动作中使用规则引用 string_decl_list : (string_decl)+; string_decl : ('STRING' id ':=' str ';') {//table.currentScope().define(new BaseDescriptor(), id.text, ValueType.STRING); System.out.println($str.text); }; str : STRINGLITERAL;

我试图在语法动作中使用规则引用

string_decl_list  : (string_decl)+;
string_decl       : ('STRING' id ':=' str ';') 
{//table.currentScope().define(new BaseDescriptor(), id.text, ValueType.STRING);
 System.out.println($str.text);
};
str               : STRINGLITERAL;
我的语法是这样的。汇编工作很好。但是当我试图解析我的文件时

出现了一个例外

Exception in thread "main" java.lang.NoSuchFieldError: str
at MicroParser.string_decl(MicroParser.java:368)
at MicroParser.string_decl_list(MicroParser.java:312)
at MicroParser.decl(MicroParser.java:246)
at MicroParser.pgm_body(MicroParser.java:187)
at MicroParser.program(MicroParser.java:107)
at Compiler.main(Compiler.java:32)
Java Result: 1
我想我这样做是为了规则参考,有人能帮我吗?我不知道如何解决它

你得到错误了吗

 Exception in thread "main" java.lang.NoSuchFieldError: str
因为您没有解析器规则“str”的返回值

试着这样做:

 str returns [String str] :  STRINGLITERAL { $str = new String($STRINGLITERAL.text); } ;

你是说把这个放进语法文件?很抱歉迟了答复。