我想在javaCC生成的解析器中实现规则编码: 不要在for-loop块中更改循环变量。
for循环块的规则生产javacc是:
void MyMethod () : {}
{
"(" Argument () ")" {}
(Statement ()) *
}
void Statement () : {}
{
expressionFOR()
}
void expressionFOR() :{}
{
<For> <id> "= " 1 <to> 100
int J
int kk =SUM( , J)
......
}
非常感谢你
答案 0 :(得分:0)
假设您使用的是带有MULTI = false和VISITOR = true的JJTree,您可以沿此行写一个访问者
public void visit(SimpleNode node, Object data) {
if( this is a for loop node ) {
push the for loop variable onto a stack of variables
node.childrenAccept(this, null) ;
pop the stack }
else {
if( this is an assignment statement node
and the target variable is on the stack )
report rule violated
node.childrenAccept(this, null) ;
}
}