diff options
Diffstat (limited to 'dimension')
-rw-r--r-- | dimension/common.rules | 40 | ||||
-rw-r--r-- | dimension/grammar.epilogue | 4 | ||||
-rw-r--r-- | dimension/parse.c | 69 | ||||
-rw-r--r-- | dimension/parse.h | 4 |
4 files changed, 72 insertions, 45 deletions
diff --git a/dimension/common.rules b/dimension/common.rules index fea7794..02f2010 100644 --- a/dimension/common.rules +++ b/dimension/common.rules @@ -498,34 +498,20 @@ ARITH_EXPR: FLOAT_LITERAL | "vlength" "(" ARITH_EXPR ")" { $$ = dmnsn_new_astnode1(DMNSN_AST_VLENGTH, @$, $3); } - | "pi" { - $$ = dmnsn_new_astnode(DMNSN_AST_PI, @$); - } - | "true" { - $$ = dmnsn_new_astnode(DMNSN_AST_TRUE, @$); - } - | "on" { - $$ = dmnsn_new_astnode(DMNSN_AST_TRUE, @$); - } - | "yes" { - $$ = dmnsn_new_astnode(DMNSN_AST_TRUE, @$); - } - | "false" { - $$ = dmnsn_new_astnode(DMNSN_AST_FALSE, @$); - } - | "off" { - $$ = dmnsn_new_astnode(DMNSN_AST_FALSE, @$); - } - | "no" { - $$ = dmnsn_new_astnode(DMNSN_AST_FALSE, @$); - } + | "pi" { $$ = dmnsn_new_astnode(DMNSN_AST_PI, @$); } + | "true" { $$ = dmnsn_new_astnode(DMNSN_AST_TRUE, @$); } + | "on" { $$ = dmnsn_new_astnode(DMNSN_AST_TRUE, @$); } + | "yes" { $$ = dmnsn_new_astnode(DMNSN_AST_TRUE, @$); } + | "false" { $$ = dmnsn_new_astnode(DMNSN_AST_FALSE, @$); } + | "off" { $$ = dmnsn_new_astnode(DMNSN_AST_FALSE, @$); } + | "no" { $$ = dmnsn_new_astnode(DMNSN_AST_FALSE, @$); } + | "x" { $$ = dmnsn_new_astnode(DMNSN_AST_X, @$); } + | "u" { $$ = dmnsn_new_astnode(DMNSN_AST_X, @$); } + | "y" { $$ = dmnsn_new_astnode(DMNSN_AST_Y, @$); } + | "v" { $$ = dmnsn_new_astnode(DMNSN_AST_Y, @$); } + | "z" { $$ = dmnsn_new_astnode(DMNSN_AST_Z, @$); } + | "t" { $$ = dmnsn_new_astnode(DMNSN_AST_T, @$); } | 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); } ; MAX_LIST: ARITH_EXPR "," ARITH_EXPR { diff --git a/dimension/grammar.epilogue b/dimension/grammar.epilogue index 08587f9..881ec98 100644 --- a/dimension/grammar.epilogue +++ b/dimension/grammar.epilogue @@ -217,6 +217,10 @@ dmnsn_astnode_string(dmnsn_astnode_type astnode_type) dmnsn_astnode_map(DMNSN_AST_PI, "pi" ); dmnsn_astnode_map(DMNSN_AST_TRUE, "true" ); dmnsn_astnode_map(DMNSN_AST_FALSE, "false"); + dmnsn_astnode_map(DMNSN_AST_X, "x" ); + dmnsn_astnode_map(DMNSN_AST_Y, "y" ); + dmnsn_astnode_map(DMNSN_AST_Z, "z" ); + dmnsn_astnode_map(DMNSN_AST_T, "t" ); dmnsn_astnode_map(DMNSN_AST_NEGATE, "-"); dmnsn_astnode_map(DMNSN_AST_DOT_X, ".x"); diff --git a/dimension/parse.c b/dimension/parse.c index cfef162..0f94f6c 100644 --- a/dimension/parse.c +++ b/dimension/parse.c @@ -396,55 +396,71 @@ dmnsn_new_ast_float(double value) return astnode; } -dmnsn_astnode -dmnsn_new_ast_ivector(long x, long y, long z, long f, long t) +static void +dmnsn_make_ast_ivector(dmnsn_astnode *astnode, + 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)); + astnode->type = DMNSN_AST_VECTOR; + if (!astnode->children) + astnode->children = dmnsn_new_array(sizeof(dmnsn_astnode)); dmnsn_astnode comp; comp = dmnsn_new_ast_integer(x); - dmnsn_array_push(astnode.children, &comp); + dmnsn_array_push(astnode->children, &comp); comp = dmnsn_new_ast_integer(y); - dmnsn_array_push(astnode.children, &comp); + dmnsn_array_push(astnode->children, &comp); comp = dmnsn_new_ast_integer(z); - dmnsn_array_push(astnode.children, &comp); + dmnsn_array_push(astnode->children, &comp); comp = dmnsn_new_ast_integer(f); - dmnsn_array_push(astnode.children, &comp); + dmnsn_array_push(astnode->children, &comp); comp = dmnsn_new_ast_integer(t); - dmnsn_array_push(astnode.children, &comp); - - return astnode; + dmnsn_array_push(astnode->children, &comp); } dmnsn_astnode -dmnsn_new_ast_vector(double x, double y, double z, double f, double t) +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_make_ast_ivector(&astnode, x, y, z, f, t); + return astnode; +} + +static void +dmnsn_make_ast_vector(dmnsn_astnode *astnode, + double x, double y, double z, double f, double t) +{ + astnode->type = DMNSN_AST_VECTOR; + if (!astnode->children) + astnode->children = dmnsn_new_array(sizeof(dmnsn_astnode)); dmnsn_astnode comp; comp = dmnsn_new_ast_float(x); - dmnsn_array_push(astnode.children, &comp); + dmnsn_array_push(astnode->children, &comp); comp = dmnsn_new_ast_float(y); - dmnsn_array_push(astnode.children, &comp); + dmnsn_array_push(astnode->children, &comp); comp = dmnsn_new_ast_float(z); - dmnsn_array_push(astnode.children, &comp); + dmnsn_array_push(astnode->children, &comp); comp = dmnsn_new_ast_float(f); - dmnsn_array_push(astnode.children, &comp); + dmnsn_array_push(astnode->children, &comp); comp = dmnsn_new_ast_float(t); - dmnsn_array_push(astnode.children, &comp); + dmnsn_array_push(astnode->children, &comp); +} +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); + dmnsn_make_ast_vector(&astnode, x, y, z, f, t); return astnode; } @@ -587,6 +603,19 @@ dmnsn_eval_zeroary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable) dmnsn_make_ast_integer(&ret, 0); break; + case DMNSN_AST_X: + dmnsn_make_ast_ivector(&ret, 1, 0, 0, 0, 0); + break; + case DMNSN_AST_Y: + dmnsn_make_ast_ivector(&ret, 0, 1, 0, 0, 0); + break; + case DMNSN_AST_Z: + dmnsn_make_ast_ivector(&ret, 0, 0, 1, 0, 0); + break; + case DMNSN_AST_T: + dmnsn_make_ast_ivector(&ret, 0, 0, 0, 1, 0); + break; + default: dmnsn_diagnostic(astnode.filename, astnode.line, astnode.col, "invalid constant '%s'", @@ -1421,6 +1450,10 @@ dmnsn_eval(dmnsn_astnode astnode, dmnsn_symbol_table *symtable) case DMNSN_AST_PI: case DMNSN_AST_TRUE: case DMNSN_AST_FALSE: + case DMNSN_AST_X: + case DMNSN_AST_Y: + case DMNSN_AST_Z: + case DMNSN_AST_T: return dmnsn_eval_zeroary(astnode, symtable); case DMNSN_AST_DOT_X: diff --git a/dimension/parse.h b/dimension/parse.h index ca1771b..09931d1 100644 --- a/dimension/parse.h +++ b/dimension/parse.h @@ -128,6 +128,10 @@ typedef enum { DMNSN_AST_PI, DMNSN_AST_TRUE, DMNSN_AST_FALSE, + DMNSN_AST_X, + DMNSN_AST_Y, + DMNSN_AST_Z, + DMNSN_AST_T, DMNSN_AST_EQUAL, DMNSN_AST_NOT_EQUAL, |