在ANTLR规则中传回多个值 [英] Returning multiple values in ANTLR rule
本文介绍了在ANTLR规则中传回多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的ANTLR规则
I have an ANTLR rule like this
receive returns[Evaluator e,String message]
: RECEIVE FILENAME {$e= new ReceiveEvaluator($FILENAME.text);}
;
我添加了一个新的返回消息,我想在其中放入文件内容.我可以做的一种方法是,当我在树上行走时,通过调用Evaluate()方法使评估器返回String.
I have added a new return message and I want to put the file content in that. One way I could do is make the evaluator return the String when I walk the tree by calling the evaluate() method.
我想知道我是否可以立即执行此操作-但不知道如何设置多个返回值并在以后访问它们.
I was wondering if I could do it strightaway here - but am not aware how to set multiple return values and access them later.
谢谢 哈里
推荐答案
以下是设置和使用多个返回值的方法:
Here's how to set- and use multiple return values:
parse
: r=receive {
Evaluator e = $r.evaluator;
String m = $r.message;
}
;
receive returns[Evaluator evaluator, String message]
: RECEIVE f=FILENAME {
$evaluator = new ReceiveEvaluator($f.text);
$message = "Some message here...";
}
;
这篇关于在ANTLR规则中传回多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文