From a893d72c2caf3b8dc457115f6409b6bf66a5adbc Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 25 Feb 2010 02:10:26 -0500 Subject: Parse interiors. --- dimension/common.nonterminals | 4 ++++ dimension/common.rules | 19 +++++++++++++++++++ dimension/common.terminals | 4 ++-- dimension/directives.rules | 1 + dimension/grammar.epilogue | 3 +++ dimension/lexer.l | 2 ++ dimension/parse.h | 3 +++ dimension/realize.c | 44 ++++++++++++++++++++++++++++++++++++++----- tests/dimension/demo.pov | 4 ++++ tests/dimension/demo.sh | 4 +++- 10 files changed, 80 insertions(+), 8 deletions(-) diff --git a/dimension/common.nonterminals b/dimension/common.nonterminals index 7513f9c..c3b2b3f 100644 --- a/dimension/common.nonterminals +++ b/dimension/common.nonterminals @@ -59,6 +59,10 @@ %type REFLECTION %type REFLECTION_ITEMS +/* Interiors */ +%type INTERIOR +%type INTERIOR_ITEMS + /* Floats */ %type FLOAT %type FLOAT_LITERAL diff --git a/dimension/common.rules b/dimension/common.rules index f0e8eae..7b4c609 100644 --- a/dimension/common.rules +++ b/dimension/common.rules @@ -153,6 +153,7 @@ OBJECT_MODIFIER: TRANSFORMATION | PIGMENT { $$ = dmnsn_new_astnode1(DMNSN_AST_TEXTURE, @$, $1); } + | INTERIOR ; /* Textures */ @@ -259,6 +260,24 @@ REFLECTION_ITEMS: /* empty */ { } ; +/* Interiores */ +INTERIOR: "interior" "{" + INTERIOR_ITEMS + "}" + { $$ = $3; } +; + +INTERIOR_ITEMS: /* empty */ { + $$ = dmnsn_new_astnode(DMNSN_AST_INTERIOR, @$); + } + | INTERIOR_ITEMS "ior" FLOAT { + dmnsn_astnode diffuse = dmnsn_new_astnode1(DMNSN_AST_IOR, + @2, $3); + $$ = $1; + dmnsn_array_push($$.children, &diffuse); + } +; + /* Floats */ FLOAT: ARITH_EXPR { diff --git a/dimension/common.terminals b/dimension/common.terminals index c50c7a9..fbe1eb2 100644 --- a/dimension/common.terminals +++ b/dimension/common.terminals @@ -233,14 +233,14 @@ %token DMNSN_T_INSIDE %token DMNSN_T_INSIDE_VECTOR %token DMNSN_T_INT -%token DMNSN_T_INTERIOR +%token DMNSN_T_INTERIOR "interior" %token DMNSN_T_INTERIOR_TEXTURE %token DMNSN_T_INTERNAL %token DMNSN_T_INTERPOLATE %token DMNSN_T_INTERSECTION %token DMNSN_T_INTERVALS %token DMNSN_T_INVERSE -%token DMNSN_T_IOR +%token DMNSN_T_IOR "ior" %token DMNSN_T_IRID %token DMNSN_T_IRID_WAVELENGTH %token DMNSN_T_ISOSURFACE diff --git a/dimension/directives.rules b/dimension/directives.rules index 6f8a812..f3f3e7a 100644 --- a/dimension/directives.rules +++ b/dimension/directives.rules @@ -85,6 +85,7 @@ RVALUE: ARITH_EXPR ";" %dprec 2 { | TEXTURE | PIGMENT | FINISH + | INTERIOR | CAMERA | TRANSFORMATION diff --git a/dimension/grammar.epilogue b/dimension/grammar.epilogue index 6ea4e28..877b876 100644 --- a/dimension/grammar.epilogue +++ b/dimension/grammar.epilogue @@ -152,6 +152,9 @@ dmnsn_astnode_string(dmnsn_astnode_type astnode_type) dmnsn_astnode_map(DMNSN_AST_REFLECTION_ITEMS, "reflection-items"); dmnsn_astnode_map(DMNSN_AST_FALLOFF, "falloff"); + dmnsn_astnode_map(DMNSN_AST_INTERIOR, "interior"); + dmnsn_astnode_map(DMNSN_AST_IOR, "ior"); + dmnsn_astnode_map(DMNSN_AST_FLOAT, "float"); dmnsn_astnode_map(DMNSN_AST_INTEGER, "integer"); diff --git a/dimension/lexer.l b/dimension/lexer.l index 77320c5..6531e0c 100644 --- a/dimension/lexer.l +++ b/dimension/lexer.l @@ -179,6 +179,8 @@ unsigned long wchar; "gray" RETURN_TOKEN(DMNSN_T_GRAY); "grey" RETURN_TOKEN(DMNSN_T_GRAY); "green" RETURN_TOKEN(DMNSN_T_GREEN); +"interior" RETURN_TOKEN(DMNSN_T_INTERIOR); +"ior" RETURN_TOKEN(DMNSN_T_IOR); "location" RETURN_TOKEN(DMNSN_T_LOCATION); "look_at" RETURN_TOKEN(DMNSN_T_LOOK_AT); "light_source" RETURN_TOKEN(DMNSN_T_LIGHT_SOURCE); diff --git a/dimension/parse.h b/dimension/parse.h index 9db4981..9511eab 100644 --- a/dimension/parse.h +++ b/dimension/parse.h @@ -66,6 +66,9 @@ typedef enum { DMNSN_AST_REFLECTION_ITEMS, DMNSN_AST_FALLOFF, + DMNSN_AST_INTERIOR, + DMNSN_AST_IOR, + DMNSN_AST_FLOAT, DMNSN_AST_INTEGER, diff --git a/dimension/realize.c b/dimension/realize.c index 810d86e..b20ec9f 100644 --- a/dimension/realize.c +++ b/dimension/realize.c @@ -504,18 +504,18 @@ dmnsn_realize_texture(dmnsn_astnode astnode) unsigned int i; for (i = 0; i < dmnsn_array_size(astnode.children); ++i) { - dmnsn_astnode modifier; - dmnsn_array_get(astnode.children, i, &modifier); + dmnsn_astnode item; + dmnsn_array_get(astnode.children, i, &item); - switch (modifier.type) { + switch (item.type) { case DMNSN_AST_PIGMENT: dmnsn_delete_pigment(texture->pigment); - texture->pigment = dmnsn_realize_pigment(modifier); + texture->pigment = dmnsn_realize_pigment(item); break; case DMNSN_AST_FINISH: dmnsn_delete_finish(texture->finish); - texture->finish = dmnsn_realize_finish(modifier); + texture->finish = dmnsn_realize_finish(item); break; default: @@ -526,6 +526,35 @@ dmnsn_realize_texture(dmnsn_astnode astnode) return texture; } +static dmnsn_interior * +dmnsn_realize_interior(dmnsn_astnode astnode) +{ + dmnsn_assert(astnode.type == DMNSN_AST_INTERIOR, "Expected a texture."); + + dmnsn_interior *interior = dmnsn_new_interior(); + if (!interior) { + dmnsn_error(DMNSN_SEVERITY_HIGH, "Couldn't allocate interior."); + } + + unsigned int i; + for (i = 0; i < dmnsn_array_size(astnode.children); ++i) { + dmnsn_astnode item, child; + dmnsn_array_get(astnode.children, i, &item); + + switch (item.type) { + case DMNSN_AST_IOR: + dmnsn_array_get(item.children, 0, &child); + interior->ior = dmnsn_realize_float(child); + break; + + default: + dmnsn_assert(false, "Invalid interior item."); + } + } + + return interior; +} + static void dmnsn_realize_object_modifiers(dmnsn_astnode astnode, dmnsn_object *object) { @@ -562,6 +591,11 @@ dmnsn_realize_object_modifiers(dmnsn_astnode astnode, dmnsn_object *object) object->texture = dmnsn_realize_texture(modifier); break; + case DMNSN_AST_INTERIOR: + dmnsn_delete_interior(object->interior); + object->interior = dmnsn_realize_interior(modifier); + break; + default: dmnsn_assert(false, "Invalid object modifier."); } diff --git a/tests/dimension/demo.pov b/tests/dimension/demo.pov index 757857f..d517621 100644 --- a/tests/dimension/demo.pov +++ b/tests/dimension/demo.pov @@ -63,4 +63,8 @@ sphere { phong_size 40.0 } } + + interior { + ior 1.3 + } } diff --git a/tests/dimension/demo.sh b/tests/dimension/demo.sh index a00d0c0..3411ef2 100755 --- a/tests/dimension/demo.sh +++ b/tests/dimension/demo.sh @@ -59,7 +59,9 @@ demo_exp=$(echo -n \ (color (integer 0) (integer 1) (integer 0) (integer 0) (integer 0))) (finish (phong (float 0.2)) - (phong_size (float 40)))))))' \ + (phong_size (float 40)))) + (interior + (ior (float 1.3))))))' \ | tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g') if [ "$demo" != "$demo_exp" ]; then -- cgit v1.2.3