diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-11-25 01:42:37 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-11-25 01:42:37 -0500 |
commit | 9af188db64514fd5dd6db0a0bf82920b9b661758 (patch) | |
tree | d45a6070193f589c656f00cc150a1f53e95bb503 /dimension/grammar.y | |
parent | 819af91b95033ed34d07c0a973ad722bcaf20735 (diff) | |
download | dimension-9af188db64514fd5dd6db0a0bf82920b9b661758.tar.xz |
Implement object modifiers and rotation.
Diffstat (limited to 'dimension/grammar.y')
-rw-r--r-- | dimension/grammar.y | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/dimension/grammar.y b/dimension/grammar.y index 6bf6569..91d3852 100644 --- a/dimension/grammar.y +++ b/dimension/grammar.y @@ -188,6 +188,8 @@ yyerror(YYLTYPE *locp, dmnsn_array *astree, dmnsn_token_iterator *iterator, %error-verbose %token-table +%expect 2 + %parse-param {dmnsn_array *astree} %parse-param {dmnsn_token_iterator *iterator} %lex-param {dmnsn_token_iterator *iterator} @@ -550,7 +552,7 @@ yyerror(YYLTYPE *locp, dmnsn_array *astree, dmnsn_token_iterator *iterator, %token DMNSN_T_RGBT %token DMNSN_T_RIGHT %token DMNSN_T_RIPPLES -%token DMNSN_T_ROTATE +%token DMNSN_T_ROTATE "rotate" %token DMNSN_T_ROUGHNESS %token DMNSN_T_SAMPLES %token DMNSN_T_SAVE_FILE @@ -699,12 +701,19 @@ yyerror(YYLTYPE *locp, dmnsn_array *astree, dmnsn_token_iterator *iterator, /* Top-level items */ %type <astnode> SCENE_ITEM +/* Transformations */ +%type <astnode> TRANSFORMATION + /* Objects */ %type <astnode> OBJECT %type <astnode> FINITE_SOLID_OBJECT %type <astnode> BOX %type <astnode> SPHERE +/* Object modifiers */ +%type <astnode> OBJECT_MODIFIERS +%type <astnode> OBJECT_MODIFIER + /* Floats */ %type <astnode> FLOAT %type <astnode> FLOAT_EXPR @@ -719,6 +728,8 @@ yyerror(YYLTYPE *locp, dmnsn_array *astree, dmnsn_token_iterator *iterator, %% +/* Start symbol */ + SCENE: /* empty */ { } | SCENE SCENE_ITEM { dmnsn_array_push(astree, &$2); @@ -728,6 +739,14 @@ SCENE: /* empty */ { } SCENE_ITEM: OBJECT ; +/* Transformations */ + +TRANSFORMATION: "rotate" VECTOR { + $$ = dmnsn_new_astnode1(DMNSN_AST_ROTATION, @$, $2); + } + +/* Objects */ + OBJECT: FINITE_SOLID_OBJECT ; @@ -737,20 +756,37 @@ FINITE_SOLID_OBJECT: BOX BOX: "box" "{" VECTOR "," VECTOR + OBJECT_MODIFIERS "}" { - $$ = dmnsn_new_astnode2(DMNSN_AST_BOX, @$, $3, $5); + $$ = dmnsn_new_astnode3(DMNSN_AST_BOX, @$, $3, $5, $6); } ; SPHERE: "sphere" "{" VECTOR "," FLOAT + OBJECT_MODIFIERS "}" { - $$ = dmnsn_new_astnode2(DMNSN_AST_SPHERE, @$, $3, $5); + $$ = dmnsn_new_astnode3(DMNSN_AST_SPHERE, @$, $3, $5, $6); } ; +/* Object modifiers */ + +OBJECT_MODIFIERS: /* empty */ { + $$ = dmnsn_new_astnode(DMNSN_AST_OBJECT_MODIFIERS, + @$); + } + | OBJECT_MODIFIERS OBJECT_MODIFIER { + $$ = $1; + dmnsn_array_push($$.children, &$2); + } + +OBJECT_MODIFIER: TRANSFORMATION + +/* Floats */ + FLOAT: FLOAT_EXPR { $$ = dmnsn_eval_scalar($1); dmnsn_delete_astnode($1); @@ -856,6 +892,8 @@ FLOAT_LITERAL: "integer" { } ; +/* Vectors */ + VECTOR: VECTOR_EXPR { $$ = dmnsn_eval_vector($1); dmnsn_delete_astnode($1); @@ -1334,6 +1372,8 @@ dmnsn_astnode_string(dmnsn_astnode_type astnode_type) dmnsn_astnode_map(DMNSN_AST_BOX, "box"); dmnsn_astnode_map(DMNSN_AST_VECTOR, "vector"); dmnsn_astnode_map(DMNSN_AST_SPHERE, "sphere"); + dmnsn_astnode_map(DMNSN_AST_OBJECT_MODIFIERS, "object-modifiers"); + dmnsn_astnode_map(DMNSN_AST_ROTATION, "rotate"); default: fprintf(stderr, "Warning: unrecognised astnode type %d.\n", |