summaryrefslogtreecommitdiffstats
path: root/dimension
diff options
context:
space:
mode:
Diffstat (limited to 'dimension')
-rw-r--r--dimension/common.rules21
-rw-r--r--dimension/common.terminals14
-rw-r--r--dimension/grammar.epilogue4
-rw-r--r--dimension/lexer.l7
-rw-r--r--dimension/parse.c32
-rw-r--r--dimension/parse.h4
6 files changed, 75 insertions, 7 deletions
diff --git a/dimension/common.rules b/dimension/common.rules
index c8e0767..fea7794 100644
--- a/dimension/common.rules
+++ b/dimension/common.rules
@@ -498,6 +498,27 @@ 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, @$);
+ }
| 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 b72e836..490df65 100644
--- a/dimension/common.terminals
+++ b/dimension/common.terminals
@@ -189,7 +189,7 @@
%token DMNSN_T_FADE_POWER
%token DMNSN_T_FALLOFF "falloff"
%token DMNSN_T_FALLOFF_ANGLE
-%token DMNSN_T_FALSE
+%token DMNSN_T_FALSE "false"
%token DMNSN_T_FILE_EXISTS
%token DMNSN_T_FILTER "filter"
%token DMNSN_T_FINAL_CLOCK
@@ -295,7 +295,7 @@
%token DMNSN_T_MORTAR
%token DMNSN_T_NATURAL_SPLINE
%token DMNSN_T_NEAREST_COUNT
-%token DMNSN_T_NO
+%token DMNSN_T_NO "no"
%token DMNSN_T_NO_BUMP_SCALE
%token DMNSN_T_NO_IMAGE
%token DMNSN_T_NO_REFLECTION
@@ -308,11 +308,11 @@
%token DMNSN_T_NUMBER_OF_WAVES
%token DMNSN_T_OBJECT
%token DMNSN_T_OCTAVES
-%token DMNSN_T_OFF
+%token DMNSN_T_OFF "off"
%token DMNSN_T_OFFSET
%token DMNSN_T_OMEGA
%token DMNSN_T_OMNIMAX
-%token DMNSN_T_ON
+%token DMNSN_T_ON "on"
%token DMNSN_T_ONCE
%token DMNSN_T_ONION
%token DMNSN_T_OPEN
@@ -330,7 +330,7 @@
%token DMNSN_T_PHONG "phong"
%token DMNSN_T_PHONG_SIZE "phong_size"
%token DMNSN_T_PHOTONS
-%token DMNSN_T_PI
+%token DMNSN_T_PI "pi"
%token DMNSN_T_PIGMENT "pigment"
%token DMNSN_T_PIGMENT_MAP
%token DMNSN_T_PIGMENT_PATTERN
@@ -450,7 +450,7 @@
%token DMNSN_T_TRANSMIT "transmit"
%token DMNSN_T_TRIANGLE
%token DMNSN_T_TRIANGLE_WAVE
-%token DMNSN_T_TRUE
+%token DMNSN_T_TRUE "true"
%token DMNSN_T_TTF
%token DMNSN_T_TURB_DEPTH
%token DMNSN_T_TURBULENCE
@@ -488,7 +488,7 @@
%token DMNSN_T_WRINKLES
%token DMNSN_T_X "x"
%token DMNSN_T_Y "y"
-%token DMNSN_T_YES
+%token DMNSN_T_YES "yes"
%token DMNSN_T_Z "z"
/* Directives (#declare etc.) */
diff --git a/dimension/grammar.epilogue b/dimension/grammar.epilogue
index 23e8504..08587f9 100644
--- a/dimension/grammar.epilogue
+++ b/dimension/grammar.epilogue
@@ -214,6 +214,10 @@ dmnsn_astnode_string(dmnsn_astnode_type astnode_type)
dmnsn_astnode_map(DMNSN_AST_VDOT, "vdot" );
dmnsn_astnode_map(DMNSN_AST_VLENGTH, "vlength");
+ 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_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 a2cf342..ab9bcdd 100644
--- a/dimension/lexer.l
+++ b/dimension/lexer.l
@@ -199,6 +199,7 @@ unsigned long wchar;
"div" RETURN_TOKEN(DMNSN_T_DIV);
"exp" RETURN_TOKEN(DMNSN_T_EXP);
"falloff" RETURN_TOKEN(DMNSN_T_FALLOFF);
+"false" RETURN_TOKEN(DMNSN_T_FALSE);
"filter" RETURN_TOKEN(DMNSN_T_FILTER);
"finish" RETURN_TOKEN(DMNSN_T_FINISH);
"floor" RETURN_TOKEN(DMNSN_T_FLOOR);
@@ -218,9 +219,13 @@ unsigned long wchar;
"max_trace_level" RETURN_TOKEN(DMNSN_T_MAX_TRACE_LEVEL);
"min" RETURN_TOKEN(DMNSN_T_MIN);
"mod" RETURN_TOKEN(DMNSN_T_MOD);
+"no" RETURN_TOKEN(DMNSN_T_NO);
+"off" RETURN_TOKEN(DMNSN_T_OFF);
+"on" RETURN_TOKEN(DMNSN_T_ON);
"perspective" RETURN_TOKEN(DMNSN_T_PERSPECTIVE);
"phong" RETURN_TOKEN(DMNSN_T_PHONG);
"phong_size" RETURN_TOKEN(DMNSN_T_PHONG_SIZE);
+"pi" RETURN_TOKEN(DMNSN_T_PI);
"pigment" RETURN_TOKEN(DMNSN_T_PIGMENT);
"pow" RETURN_TOKEN(DMNSN_T_POW);
"radians" RETURN_TOKEN(DMNSN_T_RADIANS);
@@ -244,6 +249,7 @@ unsigned long wchar;
"tanh" RETURN_TOKEN(DMNSN_T_TANH);
"texture" RETURN_TOKEN(DMNSN_T_TEXTURE);
"transmit" RETURN_TOKEN(DMNSN_T_TRANSMIT);
+"true" RETURN_TOKEN(DMNSN_T_TRUE);
"u" RETURN_TOKEN(DMNSN_T_U);
"up" RETURN_TOKEN(DMNSN_T_UP);
"v" RETURN_TOKEN(DMNSN_T_V);
@@ -252,6 +258,7 @@ unsigned long wchar;
"vlength" RETURN_TOKEN(DMNSN_T_VLENGTH);
"x" RETURN_TOKEN(DMNSN_T_X);
"y" RETURN_TOKEN(DMNSN_T_Y);
+"yes" RETURN_TOKEN(DMNSN_T_YES);
"z" RETURN_TOKEN(DMNSN_T_Z);
(?# Directives)
diff --git a/dimension/parse.c b/dimension/parse.c
index 6de30c9..cfef162 100644
--- a/dimension/parse.c
+++ b/dimension/parse.c
@@ -572,6 +572,33 @@ dmnsn_make_ast_maybe_integer(dmnsn_astnode *ret, double n)
}
static dmnsn_astnode
+dmnsn_eval_zeroary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
+{
+ dmnsn_astnode ret = dmnsn_copy_astnode(astnode);
+
+ switch(astnode.type) {
+ case DMNSN_AST_PI:
+ dmnsn_make_ast_float(&ret, 4*atan(1.0));
+ break;
+ case DMNSN_AST_TRUE:
+ dmnsn_make_ast_integer(&ret, 1);
+ break;
+ case DMNSN_AST_FALSE:
+ dmnsn_make_ast_integer(&ret, 0);
+ break;
+
+ default:
+ dmnsn_diagnostic(astnode.filename, astnode.line, astnode.col,
+ "invalid constant '%s'",
+ dmnsn_astnode_string(astnode.type));
+ ret.type = DMNSN_AST_NONE;
+ break;
+ }
+
+ return ret;
+}
+
+static dmnsn_astnode
dmnsn_eval_unary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
{
unsigned int i;
@@ -1391,6 +1418,11 @@ dmnsn_eval(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
}
}
+ case DMNSN_AST_PI:
+ case DMNSN_AST_TRUE:
+ case DMNSN_AST_FALSE:
+ return dmnsn_eval_zeroary(astnode, symtable);
+
case DMNSN_AST_DOT_X:
case DMNSN_AST_DOT_Y:
case DMNSN_AST_DOT_Z:
diff --git a/dimension/parse.h b/dimension/parse.h
index 2b5ecb7..ca1771b 100644
--- a/dimension/parse.h
+++ b/dimension/parse.h
@@ -125,6 +125,10 @@ typedef enum {
DMNSN_AST_VDOT,
DMNSN_AST_VLENGTH,
+ DMNSN_AST_PI,
+ DMNSN_AST_TRUE,
+ DMNSN_AST_FALSE,
+
DMNSN_AST_EQUAL,
DMNSN_AST_NOT_EQUAL,
DMNSN_AST_LESS,