summaryrefslogtreecommitdiffstats
path: root/dimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-03-19 12:48:38 -0400
committerTavian Barnes <tavianator@gmail.com>2010-03-19 12:48:38 -0400
commitc01e193e19d45e2c5b1e86928cedc11cdbdda476 (patch)
tree5233fa6d70c2a79022e19b1fffa13b2c5ce5c678 /dimension
parent8977b20f170a23bb917a0f09b4c558ad8bbdb0ab (diff)
downloaddimension-c01e193e19d45e2c5b1e86928cedc11cdbdda476.tar.xz
Support exp().
Diffstat (limited to 'dimension')
-rw-r--r--dimension/common.rules3
-rw-r--r--dimension/common.terminals2
-rw-r--r--dimension/grammar.epilogue2
-rw-r--r--dimension/lexer.l1
-rw-r--r--dimension/parse.c9
-rw-r--r--dimension/parse.h2
6 files changed, 18 insertions, 1 deletions
diff --git a/dimension/common.rules b/dimension/common.rules
index c03eee8..bb03577 100644
--- a/dimension/common.rules
+++ b/dimension/common.rules
@@ -396,6 +396,9 @@ ARITH_EXPR: FLOAT_LITERAL
$$ = dmnsn_new_astnode1(DMNSN_AST_DOT_TRANSMIT, @$, $1);
}
| "(" ARITH_EXPR ")" { $$ = $2; }
+ | "exp" "(" ARITH_EXPR ")" {
+ $$ = dmnsn_new_astnode1(DMNSN_AST_EXP, @$, $3);
+ }
| IDENTIFIER
| "x" { $$ = dmnsn_new_ast_ivector(1, 0, 0, 0, 0); }
| "u" { $$ = dmnsn_new_ast_ivector(1, 0, 0, 0, 0); }
diff --git a/dimension/common.terminals b/dimension/common.terminals
index 20b6459..02338c9 100644
--- a/dimension/common.terminals
+++ b/dimension/common.terminals
@@ -176,7 +176,7 @@
%token DMNSN_T_EMISSION
%token DMNSN_T_ERROR_BOUND
%token DMNSN_T_EVALUATE
-%token DMNSN_T_EXP
+%token DMNSN_T_EXP "exp"
%token DMNSN_T_EXPAND_THRESHOLDS
%token DMNSN_T_EXPONENT
%token DMNSN_T_EXTERIOR
diff --git a/dimension/grammar.epilogue b/dimension/grammar.epilogue
index d666b0a..84141fb 100644
--- a/dimension/grammar.epilogue
+++ b/dimension/grammar.epilogue
@@ -178,6 +178,8 @@ dmnsn_astnode_string(dmnsn_astnode_type astnode_type)
dmnsn_astnode_map(DMNSN_AST_AND, "&" );
dmnsn_astnode_map(DMNSN_AST_OR, "|" );
+ dmnsn_astnode_map(DMNSN_AST_EXP, "exp");
+
dmnsn_astnode_map(DMNSN_AST_NEGATE, "-");
dmnsn_astnode_map(DMNSN_AST_DOT_X, ".x");
dmnsn_astnode_map(DMNSN_AST_DOT_Y, ".y");
diff --git a/dimension/lexer.l b/dimension/lexer.l
index 5a603ea..4f12f31 100644
--- a/dimension/lexer.l
+++ b/dimension/lexer.l
@@ -183,6 +183,7 @@ unsigned long wchar;
"colour" RETURN_TOKEN(DMNSN_T_COLOR);
"direction" RETURN_TOKEN(DMNSN_T_DIRECTION);
"diffuse" RETURN_TOKEN(DMNSN_T_DIFFUSE);
+"exp" RETURN_TOKEN(DMNSN_T_EXP);
"falloff" RETURN_TOKEN(DMNSN_T_FALLOFF);
"filter" RETURN_TOKEN(DMNSN_T_FILTER);
"finish" RETURN_TOKEN(DMNSN_T_FINISH);
diff --git a/dimension/parse.c b/dimension/parse.c
index da35c0d..7edf22a 100644
--- a/dimension/parse.c
+++ b/dimension/parse.c
@@ -633,6 +633,10 @@ dmnsn_eval_unary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
dmnsn_make_ast_integer(&ret, -n);
break;
+ case DMNSN_AST_EXP:
+ dmnsn_make_ast_float(&ret, exp(n));
+ break;
+
default:
dmnsn_diagnostic(astnode.filename, astnode.line, astnode.col,
"Invalid unary operator '%s' on %s",
@@ -658,6 +662,10 @@ dmnsn_eval_unary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
dmnsn_make_ast_float(&ret, -n);
break;
+ case DMNSN_AST_EXP:
+ dmnsn_make_ast_float(&ret, exp(n));
+ break;
+
default:
dmnsn_diagnostic(astnode.filename, astnode.line, astnode.col,
"Invalid unary operator '%s' on %s",
@@ -1061,6 +1069,7 @@ dmnsn_eval(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
case DMNSN_AST_DOT_T:
case DMNSN_AST_DOT_TRANSMIT:
case DMNSN_AST_NEGATE:
+ case DMNSN_AST_EXP:
return dmnsn_eval_unary(astnode, symtable);
case DMNSN_AST_ADD:
diff --git a/dimension/parse.h b/dimension/parse.h
index 6da36d7..8a572f2 100644
--- a/dimension/parse.h
+++ b/dimension/parse.h
@@ -90,6 +90,8 @@ typedef enum {
DMNSN_AST_DOT_T,
DMNSN_AST_DOT_TRANSMIT,
+ DMNSN_AST_EXP,
+
DMNSN_AST_EQUAL,
DMNSN_AST_NOT_EQUAL,
DMNSN_AST_LESS,