summaryrefslogtreecommitdiffstats
path: root/dimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-03-09 00:14:42 -0500
committerTavian Barnes <tavianator@gmail.com>2010-03-09 00:14:42 -0500
commit2afc9be712c69a66833de75683cdbaa3886379f1 (patch)
treead1b8adedbfded210d9389739b0edab05313ba79 /dimension
parent66b9177cce4e186bf3572443af2436d7a9d0f162 (diff)
downloaddimension-2afc9be712c69a66833de75683cdbaa3886379f1.tar.xz
Implement unit vectors.
Diffstat (limited to 'dimension')
-rw-r--r--dimension/common.rules6
-rw-r--r--dimension/parse.c52
-rw-r--r--dimension/parse.h3
3 files changed, 61 insertions, 0 deletions
diff --git a/dimension/common.rules b/dimension/common.rules
index 72480c0..c03eee8 100644
--- a/dimension/common.rules
+++ b/dimension/common.rules
@@ -397,6 +397,12 @@ ARITH_EXPR: FLOAT_LITERAL
}
| "(" ARITH_EXPR ")" { $$ = $2; }
| IDENTIFIER
+ | "x" { $$ = dmnsn_new_ast_ivector(1, 0, 0, 0, 0); }
+ | "u" { $$ = dmnsn_new_ast_ivector(1, 0, 0, 0, 0); }
+ | "y" { $$ = dmnsn_new_ast_ivector(0, 1, 0, 0, 0); }
+ | "v" { $$ = dmnsn_new_ast_ivector(0, 1, 0, 0, 0); }
+ | "z" { $$ = dmnsn_new_ast_ivector(0, 0, 1, 0, 0); }
+ | "t" { $$ = dmnsn_new_ast_ivector(0, 0, 0, 1, 0); }
;
/* Colors */
diff --git a/dimension/parse.c b/dimension/parse.c
index a4a4c43..5756659 100644
--- a/dimension/parse.c
+++ b/dimension/parse.c
@@ -76,6 +76,58 @@ dmnsn_new_ast_float(double value)
}
dmnsn_astnode
+dmnsn_new_ast_ivector(long x, long y, long z, long f, long t)
+{
+ dmnsn_astnode astnode = dmnsn_new_astnode(DMNSN_AST_VECTOR);
+ astnode.children = dmnsn_new_array(sizeof(dmnsn_astnode));
+
+ dmnsn_astnode comp;
+
+ comp = dmnsn_new_ast_integer(x);
+ dmnsn_array_push(astnode.children, &comp);
+
+ comp = dmnsn_new_ast_integer(y);
+ dmnsn_array_push(astnode.children, &comp);
+
+ comp = dmnsn_new_ast_integer(z);
+ dmnsn_array_push(astnode.children, &comp);
+
+ comp = dmnsn_new_ast_integer(f);
+ dmnsn_array_push(astnode.children, &comp);
+
+ comp = dmnsn_new_ast_integer(t);
+ dmnsn_array_push(astnode.children, &comp);
+
+ return astnode;
+}
+
+dmnsn_astnode
+dmnsn_new_ast_vector(double x, double y, double z, double f, double t)
+{
+ dmnsn_astnode astnode = dmnsn_new_astnode(DMNSN_AST_VECTOR);
+ astnode.children = dmnsn_new_array(sizeof(dmnsn_astnode));
+
+ dmnsn_astnode comp;
+
+ comp = dmnsn_new_ast_float(x);
+ dmnsn_array_push(astnode.children, &comp);
+
+ comp = dmnsn_new_ast_float(y);
+ dmnsn_array_push(astnode.children, &comp);
+
+ comp = dmnsn_new_ast_float(z);
+ dmnsn_array_push(astnode.children, &comp);
+
+ comp = dmnsn_new_ast_float(f);
+ dmnsn_array_push(astnode.children, &comp);
+
+ comp = dmnsn_new_ast_float(t);
+ dmnsn_array_push(astnode.children, &comp);
+
+ return astnode;
+}
+
+dmnsn_astnode
dmnsn_new_ast_string(const char *value)
{
dmnsn_astnode astnode = dmnsn_new_astnode(DMNSN_AST_STRING);
diff --git a/dimension/parse.h b/dimension/parse.h
index 8a5bb93..2d946b6 100644
--- a/dimension/parse.h
+++ b/dimension/parse.h
@@ -125,6 +125,9 @@ typedef dmnsn_array dmnsn_astree;
dmnsn_astnode dmnsn_new_ast_array();
dmnsn_astnode dmnsn_new_ast_integer(long value);
dmnsn_astnode dmnsn_new_ast_float(double value);
+dmnsn_astnode dmnsn_new_ast_ivector(long x, long y, long z, long f, long t);
+dmnsn_astnode dmnsn_new_ast_vector(double x, double y, double z,
+ double f, double t);
dmnsn_astnode dmnsn_new_ast_string(const char *value);
void dmnsn_delete_astnode(dmnsn_astnode astnode);