diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-11-25 20:27:05 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-11-25 20:27:05 -0500 |
commit | 02c0213ab823a0c838d295017298cf8cd3493342 (patch) | |
tree | 50acf3e6283d070139a34a78741ee8f87ce774a3 | |
parent | 1c899d86c393faf021298d08471f0dd48d5306d7 (diff) | |
download | dimension-02c0213ab823a0c838d295017298cf8cd3493342.tar.xz |
Add vector promotion.
-rw-r--r-- | dimension/grammar.y | 15 | ||||
-rw-r--r-- | tests/dimension/arithexp.pov | 4 | ||||
-rwxr-xr-x | tests/dimension/arithexp.sh | 3 |
3 files changed, 13 insertions, 9 deletions
diff --git a/dimension/grammar.y b/dimension/grammar.y index 5f82028..ddc7418 100644 --- a/dimension/grammar.y +++ b/dimension/grammar.y @@ -225,10 +225,6 @@ yyerror(YYLTYPE *locp, dmnsn_array *astree, dmnsn_token_iterator *iterator, %token DMNSN_T_NOT_EQUAL "!=" /* Operators */ -%left "&" -%left "|" -%left "==" "!=" -%left "<" "<=" ">" ">=" %left "+" "-" %left "*" "/" %left "." @@ -971,6 +967,10 @@ VECTOR: VECTOR_EXPR { $$ = dmnsn_eval_vector($1); dmnsn_delete_astnode($1); } + | FLOAT_EXPR { + $$ = dmnsn_eval_vector($1); + dmnsn_delete_astnode($1); + } ; VECTOR_EXPR: VECTOR_LITERAL @@ -980,10 +980,13 @@ VECTOR_EXPR: VECTOR_LITERAL | VECTOR_EXPR "-" VECTOR_EXPR { $$ = dmnsn_new_astnode2(DMNSN_AST_SUB, @$, $1, $3); } - | VECTOR_EXPR "*" VECTOR_EXPR { + | VECTOR_EXPR "*" FLOAT_EXPR { + $$ = dmnsn_new_astnode2(DMNSN_AST_MUL, @$, $1, $3); + } + | FLOAT_EXPR "*" VECTOR_EXPR { $$ = dmnsn_new_astnode2(DMNSN_AST_MUL, @$, $1, $3); } - | VECTOR_EXPR "/" VECTOR_EXPR { + | VECTOR_EXPR "/" FLOAT_EXPR { $$ = dmnsn_new_astnode2(DMNSN_AST_DIV, @$, $1, $3); } | "+" VECTOR_EXPR %prec DMNSN_T_NEGATE { $$ = $2; } diff --git a/tests/dimension/arithexp.pov b/tests/dimension/arithexp.pov index dd055a4..2cdedb6 100644 --- a/tests/dimension/arithexp.pov +++ b/tests/dimension/arithexp.pov @@ -17,9 +17,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * *************************************************************************/ -// Render demo scene +// Test arithmetic expression handling sphere { - <<2.0 - 1.0, 3.0, 4.0>.x, (1.0 + 2)*2 - 5, 1.0 + 2*2 - 4> - -<0, 0, 1>, + 2*<<2.0 - 1.0, 3.0, 4.0>.x, (1.0 + 2)*2 - 5, 1.0 + 2*2 - 4> - -<0, 0, 1>, 2.25 - 1*2 } diff --git a/tests/dimension/arithexp.sh b/tests/dimension/arithexp.sh index 4b2fbba..66ecd8e 100755 --- a/tests/dimension/arithexp.sh +++ b/tests/dimension/arithexp.sh @@ -22,6 +22,7 @@ arithexp=$(${top_builddir}/dimension/dimension --tokenize --parse ${srcdir}/arithexp.pov) arithexp_exp="$(echo -n \ '(sphere { + (integer "2") * < < (float "2.0") - (float "1.0") , (float "3.0") , (float "4.0") > . x , \( (float "1.0") + (integer "2") \) * (integer "2") - (integer "5") , (float "1.0") + (integer "2") * (integer "2") - (integer "4") > @@ -32,7 +33,7 @@ arithexp_exp="$(echo -n \ | tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g') $(echo -n \ '((sphere - (vector (float 1) (float 1) (float 2) (integer 0) (integer 0)) + (vector (float 2) (float 2) (float 3) (integer 0) (integer 0)) (float 0.25) object-modifiers))' \ | tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g')" |