From 3aed1c21ca6ae07f763a911b291ae52191a927b3 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 17 Feb 2009 00:58:08 +0000 Subject: [PATCH] filled out tree-building code for all parser nodes git-svn-id: svn://anubis/fart/trunk@113 7f9b0f55-74a9-4bce-be96-3c2cd072584d --- parser/nodes.h | 41 ++++++++++++++++++++++++----- parser/parser.yy | 67 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 86 insertions(+), 22 deletions(-) diff --git a/parser/nodes.h b/parser/nodes.h index e0dc89b..f93ba5f 100644 --- a/parser/nodes.h +++ b/parser/nodes.h @@ -53,6 +53,17 @@ class NumberNode : public Node double m_number; }; +class VectorNode : public Node +{ + public: + VectorNode(refptr vector) { m_vector = vector; } + refptr getVector() { return m_vector; } + + protected: + refptr m_vector; +}; + + class AmbientNode : public Node { }; @@ -75,6 +86,10 @@ class HeightNode : public IntegerNode HeightNode(int i) : IntegerNode(i) {} }; +class IntersectNode : public Node +{ +}; + class ItemsNode : public Node { }; @@ -97,6 +112,10 @@ class MultisampleNode : public IntegerNode MultisampleNode(int i) : IntegerNode(i) {} }; +class OptionsNode : public Node +{ +}; + class PlaneNode : public Node { }; @@ -133,6 +152,10 @@ class ReflectanceNode : public NumberNode ReflectanceNode(double d) : NumberNode(d) {} }; +class SceneNode : public Node +{ +}; + class ShapeNode : public Node { }; @@ -143,6 +166,12 @@ class ShininessNode : public NumberNode ShininessNode(double d) : NumberNode(d) {} }; +class SizeNode : public VectorNode +{ + public: + SizeNode(refptr vector) : VectorNode(vector) {} +}; + 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) { m_vector = vector; } - refptr getVector() { return m_vector; } +}; - protected: - refptr m_vector; +class UpNode : public Node +{ }; class VFOVNode : public Node diff --git a/parser/parser.yy b/parser/parser.yy index ba8dda6..83f3206 100644 --- a/parser/parser.yy +++ b/parser/parser.yy @@ -90,23 +90,31 @@ static Scene * g_scene; %% scene: SCENE LCURLY scene_items RCURLY { + $$ = new SceneNode(); + $$->addChildren($3); } ; -boolean_items: shape shape boolean_items_more { - } - ; - -boolean_items_more: /* empty */ - | material boolean_items_more - ; - -box: BOX LPAREN vector RPAREN LCURLY box_items RCURLY +box: BOX LCURLY box_items RCURLY { + $$ = new BoxNode(); + $$->addChildren($3); + } ; -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 { Vector default_position(0, -1, 0); Vector default_look_at(0, 0, 0); @@ -115,7 +123,11 @@ camera: CAMERA LCURLY camera_items RCURLY { ; camera_items: /* empty */ - | camera_item camera_items + | camera_item camera_items { + $$ = new ItemsNode(); + $$->addChild($1); + $$->addChildren($2); + } ; 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 { + $$ = new LightNode(); + $$->addChildren($3); } ; light_items: /* empty */ | light_item light_items { + $$ = new ItemsNode(); + $$->addChild($1); + $$->addChildren($2); } ; @@ -163,6 +185,8 @@ light_item: POSITION vector { ; 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 */ @@ -300,10 +327,20 @@ sphere_item: radius { $$ = $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 {