[英]How to collect 'returns' from ANTLR grammar
If I have a ANTLR grammar where I have rules like this with a 'returns' statement: 如果我有ANTLR语法,而我有类似这样的规则,并带有“ returns”语句:
string_decl returns [Pair s] : STR id EQUAL ex=str_literal ';'{$s = new Pair($id.text, $ex.text);} ;
And then in my main I have code like this: 然后在我的主要我有这样的代码:
Lexer lexer = new Lexer(CharStreams.fromFileName(inputFileName));
CommonTokenStream tokens = new CommonTokenStream(lexer);
Parser parser = new Parser(tokens);
System.out.println(parser.program()); //prints out empty array ?
How do I print out a list of all of my 'returns'? 如何打印所有“退货”清单?
The returns
value is modeled as member of the rule context. returns
值被建模为规则上下文的成员。 See if you have a String_declContext.s
member. 查看您是否具有String_declContext.s
成员。 See also Rule Attribute Definitions in the ANTLR4 documentation. 另请参阅ANTLR4文档中的“ 规则属性定义 ”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.