那么如何评估一个非常简单的只有这个的antlr语法。
Box(1,2,4)
Cylinder(1,2)
并构建java3d形状,(假设我已经为java3d构建了一个画布,并且有用于在java中创建每个元素的代码,
protected static BranchGroup addBox1(Float a, Float b, Float C){
// create branch for display
TransformGroup bodyTransform = new TransformGroup();
BranchGroup bg = new BranchGroup();
bg.setCapability(BranchGroup.ALLOW_DETACH);
bg.setUserData(shapeId);
// set transformation
bodyTransform = setTransformShape(0,0,0,0,0,0,0);
// create box
Box tmpBox = new Box(a,b,c, Primitive.GENERATE_NORMALS |
Primitive.GENERATE_TEXTURE_COORDS,setAppearance(color));
getCoords(tmpBox);
bodyTransform.addChild(tmpBox);
trFormList.add(bodyTransform);
shapeId++;
//add box to branch
bg.addChild(bodyTransform);
return bg;
}
)
感谢
答案 0 :(得分:0)
或许这样的事情?
// ...
parse
: shape+ EOF
;
shape
: BOX '(' a=INT ',' b=INT ',' c=INT ')' {
YourClass.addBox(Float.parseFloat($a.text), Float.parseFloat($b.text), Float.parseFloat($c.text));
}
| CYL '(' a=INT ',' b=INT ')' {
YourClass.addCylinder(Float.parseFloat($a.text), Float.parseFloat($b.text));
}
;
BOX : 'Box';
CYL : 'Cylinder';
INT : '0'..'9'+;
SPACE : (' ' | '\t' | '\r' | '\n'){skip();};
// ...