filled out tree-building code for all parser nodes

git-svn-id: svn://anubis/fart/trunk@113 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2009-02-17 00:58:08 +00:00
parent 5d7a230ee3
commit 3aed1c21ca
2 changed files with 86 additions and 22 deletions

View File

@ -53,6 +53,17 @@ class NumberNode : public Node
double m_number; double m_number;
}; };
class VectorNode : public Node
{
public:
VectorNode(refptr<Vector> vector) { m_vector = vector; }
refptr<Vector> getVector() { return m_vector; }
protected:
refptr<Vector> m_vector;
};
class AmbientNode : public Node class AmbientNode : public Node
{ {
}; };
@ -75,6 +86,10 @@ class HeightNode : public IntegerNode
HeightNode(int i) : IntegerNode(i) {} HeightNode(int i) : IntegerNode(i) {}
}; };
class IntersectNode : public Node
{
};
class ItemsNode : public Node class ItemsNode : public Node
{ {
}; };
@ -97,6 +112,10 @@ class MultisampleNode : public IntegerNode
MultisampleNode(int i) : IntegerNode(i) {} MultisampleNode(int i) : IntegerNode(i) {}
}; };
class OptionsNode : public Node
{
};
class PlaneNode : public Node class PlaneNode : public Node
{ {
}; };
@ -133,6 +152,10 @@ class ReflectanceNode : public NumberNode
ReflectanceNode(double d) : NumberNode(d) {} ReflectanceNode(double d) : NumberNode(d) {}
}; };
class SceneNode : public Node
{
};
class ShapeNode : public Node class ShapeNode : public Node
{ {
}; };
@ -143,6 +166,12 @@ class ShininessNode : public NumberNode
ShininessNode(double d) : NumberNode(d) {} ShininessNode(double d) : NumberNode(d) {}
}; };
class SizeNode : public VectorNode
{
public:
SizeNode(refptr<Vector> vector) : VectorNode(vector) {}
};
class SpecularNode : public Node class SpecularNode : public Node
{ {
}; };
@ -151,18 +180,16 @@ class SphereNode : public Node
{ {
}; };
class UpNode : public Node class SubtractNode : public Node
{ {
}; };
class VectorNode : public Node class UnionNode : public Node
{ {
public: };
VectorNode(refptr<Vector> vector) { m_vector = vector; }
refptr<Vector> getVector() { return m_vector; }
protected: class UpNode : public Node
refptr<Vector> m_vector; {
}; };
class VFOVNode : public Node class VFOVNode : public Node

View File

@ -90,23 +90,31 @@ static Scene * g_scene;
%% %%
scene: SCENE LCURLY scene_items RCURLY { scene: SCENE LCURLY scene_items RCURLY {
$$ = new SceneNode();
$$->addChildren($3);
} }
; ;
boolean_items: shape shape boolean_items_more { box: BOX LCURLY box_items RCURLY {
} $$ = new BoxNode();
; $$->addChildren($3);
}
boolean_items_more: /* empty */
| material boolean_items_more
;
box: BOX LPAREN vector RPAREN LCURLY box_items RCURLY
; ;
box_items: shape_items { $$ = $1; } box_items: /* empty */
| box_item box_items {
$$ = new ItemsNode();
$$->addChild($1);
$$->addChildren($2);
}
; ;
box_item: SIZE vector {
$$ = new SizeNode($2->getVector());
}
| shape_item { $$ = $1; }
;
camera: CAMERA LCURLY camera_items RCURLY { camera: CAMERA LCURLY camera_items RCURLY {
Vector default_position(0, -1, 0); Vector default_position(0, -1, 0);
Vector default_look_at(0, 0, 0); Vector default_look_at(0, 0, 0);
@ -115,7 +123,11 @@ camera: CAMERA LCURLY camera_items RCURLY {
; ;
camera_items: /* empty */ camera_items: /* empty */
| camera_item camera_items | camera_item camera_items {
$$ = new ItemsNode();
$$->addChild($1);
$$->addChildren($2);
}
; ;
camera_item: POSITION vector { camera_item: POSITION vector {
@ -136,15 +148,25 @@ camera_item: POSITION vector {
} }
; ;
intersect: INTERSECT LCURLY boolean_items RCURLY intersect: INTERSECT LCURLY shape shape shape_items RCURLY {
$$ = new IntersectNode();
$$->addChild($3);
$$->addChild($4);
$$->addChildren($5);
}
; ;
light: LIGHT LCURLY light_items RCURLY { light: LIGHT LCURLY light_items RCURLY {
$$ = new LightNode();
$$->addChildren($3);
} }
; ;
light_items: /* empty */ light_items: /* empty */
| light_item light_items { | light_item light_items {
$$ = new ItemsNode();
$$->addChild($1);
$$->addChildren($2);
} }
; ;
@ -163,6 +185,8 @@ light_item: POSITION vector {
; ;
material: MATERIAL LCURLY material_items RCURLY { material: MATERIAL LCURLY material_items RCURLY {
$$ = new MaterialNode();
$$->addChildren($3);
} }
; ;
@ -202,7 +226,10 @@ number: DEC_NUMBER {
} }
; ;
options: OPTIONS LCURLY options_items RCURLY { $$ = $3; } options: OPTIONS LCURLY options_items RCURLY {
$$ = new OptionsNode();
$$->addChildren($3);
}
; ;
options_items: /* empty */ options_items: /* empty */
@ -300,10 +327,20 @@ sphere_item: radius { $$ = $1; }
| shape_item { $$ = $1; } | shape_item { $$ = $1; }
; ;
subtract: SUBTRACT LCURLY boolean_items RCURLY subtract: SUBTRACT LCURLY shape shape shape_items RCURLY {
$$ = new SubtractNode();
$$->addChild($3);
$$->addChild($4);
$$->addChildren($5);
}
; ;
union: UNION LCURLY boolean_items RCURLY union: UNION LCURLY shape shape shape_items RCURLY {
$$ = new UnionNode();
$$->addChild($3);
$$->addChild($4);
$$->addChildren($5);
}
; ;
vector: LESS number COMMA number COMMA number GREATER { vector: LESS number COMMA number COMMA number GREATER {