added material definitions to parser

git-svn-id: svn://anubis/fart/trunk@177 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2009-03-03 02:30:43 +00:00
parent 56a5fa6166
commit fce4d82a73
3 changed files with 48 additions and 0 deletions

View File

@ -5,6 +5,7 @@
#include "util/refptr.h" #include "util/refptr.h"
#include "util/Vector.h" #include "util/Vector.h"
#include <vector> #include <vector>
#include <string>
class Node class Node
{ {
@ -21,6 +22,7 @@ class Node
return refptr<Vector>(NULL); return refptr<Vector>(NULL);
} }
virtual bool isShape() { return false; } virtual bool isShape() { return false; }
virtual std::string getString() { return ""; }
protected: protected:
std::vector< refptr<Node> > m_children; std::vector< refptr<Node> > m_children;
@ -99,6 +101,18 @@ class HeightNode : public IntegerNode
HeightNode(int i) : IntegerNode(i) {} HeightNode(int i) : IntegerNode(i) {}
}; };
class IdentifierNode : public Node
{
public:
IdentifierNode(const std::string & str) { m_string = str; }
std::string getString()
{
return m_string;
}
protected:
std::string m_string;
};
class IntersectNode : public Node class IntersectNode : public Node
{ {
public: public:
@ -123,6 +137,18 @@ class MaterialNode : public Node
{ {
}; };
class MaterialDefinitionNode : public IdentifierNode
{
public:
MaterialDefinitionNode(const std::string & str) : IdentifierNode(str) {}
};
class MaterialRefNode : public IdentifierNode
{
public:
MaterialRefNode(const std::string & str) : IdentifierNode(str) {}
};
class MultisampleNode : public IntegerNode class MultisampleNode : public IntegerNode
{ {
public: public:

View File

@ -44,6 +44,7 @@ box return BOX;
camera return CAMERA; camera return CAMERA;
color return COLOR; color return COLOR;
cyl return CYL; cyl return CYL;
define return DEFINE;
diffuse return DIFFUSE; diffuse return DIFFUSE;
height return HEIGHT; height return HEIGHT;
intersect return INTERSECT; intersect return INTERSECT;
@ -70,6 +71,11 @@ up return UP;
vfov return VFOV; vfov return VFOV;
width return WIDTH; width return WIDTH;
[a-zA-Z_][a-zA-Z_0-9]* {
*yylval = new IdentifierNode(yytext);
return IDENTIFIER;
}
\n yylloc->first_line++; yylloc->last_line++; \n yylloc->first_line++; yylloc->last_line++;
[ \t\v] /* ignore whitespace */ [ \t\v] /* ignore whitespace */

View File

@ -63,6 +63,7 @@ static refptr<Node> parsed_scene_node;
%token CAMERA; %token CAMERA;
%token COLOR; %token COLOR;
%token CYL; %token CYL;
%token DEFINE;
%token DIFFUSE; %token DIFFUSE;
%token HEIGHT; %token HEIGHT;
%token INTERSECT; %token INTERSECT;
@ -89,6 +90,8 @@ static refptr<Node> parsed_scene_node;
%token VFOV; %token VFOV;
%token WIDTH; %token WIDTH;
%token IDENTIFIER;
%% %%
scene: SCENE LCURLY scene_items RCURLY { scene: SCENE LCURLY scene_items RCURLY {
@ -236,6 +239,17 @@ material_item: COLOR vector {
} }
; ;
material_definition: MATERIAL IDENTIFIER LCURLY material_items RCURLY {
$$ = new MaterialDefinitionNode($2->getString());
$$->addChildren($3);
}
;
material_ref: MATERIAL IDENTIFIER {
$$ = new MaterialRefNode($2->getString());
}
;
number: DEC_NUMBER { $$ = $1; } number: DEC_NUMBER { $$ = $1; }
| REAL_NUMBER { $$ = $1; } | REAL_NUMBER { $$ = $1; }
; ;
@ -303,6 +317,7 @@ scene_item: camera { $$ = $1; }
| options { $$ = $1; } | options { $$ = $1; }
| light { $$ = $1; } | light { $$ = $1; }
| transform_block { $$ = $1; } | transform_block { $$ = $1; }
| material_definition { $$ = $1; }
; ;
shape: plane { $$ = $1; } shape: plane { $$ = $1; }
@ -323,6 +338,7 @@ shape_items: /* empty */
; ;
shape_item: material { $$ = $1; } shape_item: material { $$ = $1; }
| material_ref { $$ = $1; }
| transform { $$ = $1; } | transform { $$ = $1; }
; ;