这更多的是一个简单的个人尝试,以了解Rascal内部发生的事情。必须有更好的(如果尚未支持的话)解决方案。 下面的代码:不能遍历AST的节点,同时为每个节点分配一个ID
fileLoad = |home:///PHPAnalysis/systems/ApilTestScripts/simple1.php|;
fileAST=loadPHPFile(fileLoad,true,false);
//assign a simple id to each node
public map[value,int] assignID12(node N)
{
myID=();
visit(N)
{
case node M:
{
name=getName(M);
myID[name] =999;
}
}
return myID;
}
ids=assignID12(fileAST);
给我
|stdin:///|(92,4,<1,92>,<1,96>): Expected str, but got value
loadPHPFile返回类型的节点:列表[语句],其中每个语句是众多类型的语句可能发生在一个程序中的一个(在我的情况下,PHP)。没有进入为什么我会这样做,为什么上面的代码没有工作?尤其令人沮丧的是,在线文档中有一个非常简单的例子。见:http://tutor.rascal-mpl.org/Recipes/Basic/Basic.html#/Recipes/Common/CountConstructors/CountConstructors.html