在解析器语法中,我想在中定义几个变量locals
clause.
一个简化的示例如下所示:
body
locals [
Map<String, String> bodyContent = new HashMap<String, String>();
long counter = 0;
]
: BODY_CAPTION NEWLINE line ;
line : key='MyKey' TAB value='MyValue' NEWLINE
{
$body::bodyContent.put($key.text, $value.text);
$body::counter++;
} ;
这给出了错误:
unknown attribute 'counter' for rule 'body' in '$body::counter'
如果我交换中的行locals
像这样的条款
locals [
long counter = 0;
Map<String, String> bodyContent = new HashMap<String, String>();
]
它给出了错误:
unknown attribute 'bodyContent' for rule 'body' in '$body::bodyContent'
显然,ANTLR 只识别第一个局部变量定义locals
clause.
有没有办法在下面定义多个局部变量locals
?
是的,但它们像参数列表一样以逗号分隔returns
clause.
locals [
Map<String, String> bodyContent = new HashMap<String, String>(),
long counter = 0
]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)