summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--tests/dimension/arithexp.pov2
-rwxr-xr-xtests/dimension/arithexp.sh4
8 files changed, 21 insertions, 4 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,
diff --git a/tests/dimension/arithexp.pov b/tests/dimension/arithexp.pov
index b8d700b..5e27612 100644
--- a/tests/dimension/arithexp.pov
+++ b/tests/dimension/arithexp.pov
@@ -21,5 +21,5 @@
sphere {
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
+ exp(1) - 1*2
}
diff --git a/tests/dimension/arithexp.sh b/tests/dimension/arithexp.sh
index 5fd24f2..6572646 100755
--- a/tests/dimension/arithexp.sh
+++ b/tests/dimension/arithexp.sh
@@ -28,13 +28,13 @@ arithexp_exp="$(echo -n \
(float "1.0") + (integer "2") * (integer "2") - (integer "4") >
-
- < (integer "0") , (integer "0") , (integer "1") > ,
- (float "2.25") - (integer "1") * (integer "2")
+ exp \( (integer "1") \) - (integer "1") * (integer "2")
})' \
| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g')
$(echo -n \
'((sphere
(vector (float 2) (float 2) (float 3) (integer 0) (integer 0))
- (float 0.25)
+ (float 0.718282)
object-modifiers))' \
| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g')"