1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
#line 2 "directives.rules"
/*
* Start symbol
*/
LANGUAGE_DIRECTIVE: "#include" STRING {
dmnsn_declare_symbol(symtable, "__include__", $2);
dmnsn_delete_astnode($2);
}
| "#declare" "identifier" "=" RVALUE {
dmnsn_declare_symbol(symtable, $2, $4);
free($2);
dmnsn_delete_astnode($4);
}
| "#local" "identifier" "=" RVALUE {
dmnsn_local_symbol(symtable, $2, $4);
free($2);
dmnsn_delete_astnode($4);
}
| "#undef" "identifier" {
dmnsn_undef_symbol(symtable, $2);
free($2);
}
| "#if" "(" CONDITIONAL ")" {
dmnsn_astnode cond = dmnsn_eval($3, symtable);
dmnsn_delete_astnode($3);
if (cond.type == DMNSN_AST_NONE) {
dmnsn_delete_astnode(cond);
YYERROR;
}
dmnsn_local_symbol(symtable, "__cond__", cond);
dmnsn_delete_astnode(cond);
}
| "#ifdef" "(" "identifier" ")" {
dmnsn_astnode *node = dmnsn_find_symbol(symtable, $3);
dmnsn_local_symbol(symtable, "__cond__",
dmnsn_new_ast_integer(node ? 1 : 0));
free($3);
}
| "#ifndef" "(" "identifier" ")" {
dmnsn_astnode *node = dmnsn_find_symbol(symtable, $3);
dmnsn_local_symbol(symtable, "__cond__",
dmnsn_new_ast_integer(node ? 0 : 1));
free($3);
}
| "#version" FLOAT ";" {
dmnsn_diagnostic(@$.first_filename, @$.first_line,
@$.first_column,
"WARNING: POV-Ray #version"
" backwards-compatibility not supported");
dmnsn_delete_astnode($2);
}
| "#debug" STRING {
fprintf(stderr, "%s\n", (const char *)$2.ptr);
dmnsn_delete_astnode($2);
}
| "#warning" STRING {
dmnsn_diagnostic(@$.first_filename, @$.first_line,
@$.first_column,
"WARNING: %s", (const char *)$2.ptr);
dmnsn_delete_astnode($2);
}
| "#error" STRING {
dmnsn_diagnostic(@$.first_filename, @$.first_line,
@$.first_column,
"%s", (const char *)$2.ptr);
dmnsn_delete_astnode($2);
YYERROR;
}
RVALUE: ARITH_EXPR ";" %dprec 2 {
$$ = dmnsn_eval($1, symtable);
dmnsn_delete_astnode($1);
if ($$.type == DMNSN_AST_NONE) {
dmnsn_delete_astnode($$);
YYERROR;
}
}
| COLOR ";" %dprec 1
| OBJECT
| TEXTURE
| PIGMENT
| FINISH
| INTERIOR
| CAMERA
| TRANSFORMATION
CONDITIONAL: ARITH_EXPR {
/* Force the expression to be evaluated logically */
dmnsn_astnode zero = dmnsn_new_ast_integer(0);
$$ = dmnsn_new_astnode2(DMNSN_AST_OR, @$, zero, $1);
}
| ARITH_EXPR "=" ARITH_EXPR {
$$ = dmnsn_new_astnode2(DMNSN_AST_EQUAL, @$, $1, $3);
}
| ARITH_EXPR "!=" ARITH_EXPR {
$$ = dmnsn_new_astnode2(DMNSN_AST_NOT_EQUAL, @$, $1, $3);
}
| ARITH_EXPR "<" ARITH_EXPR {
$$ = dmnsn_new_astnode2(DMNSN_AST_LESS, @$, $1, $3);
}
| ARITH_EXPR "<=" ARITH_EXPR {
$$ = dmnsn_new_astnode2(DMNSN_AST_LESS_EQUAL, @$, $1, $3);
}
| ARITH_EXPR ">" ARITH_EXPR {
$$ = dmnsn_new_astnode2(DMNSN_AST_GREATER, @$, $1, $3);
}
| ARITH_EXPR ">=" ARITH_EXPR {
$$ = dmnsn_new_astnode2(DMNSN_AST_GREATER_EQUAL, @$, $1, $3);
}
| CONDITIONAL "&" CONDITIONAL {
$$ = dmnsn_new_astnode2(DMNSN_AST_AND, @$, $1, $3);
}
| CONDITIONAL "|" CONDITIONAL {
$$ = dmnsn_new_astnode2(DMNSN_AST_OR, @$, $1, $3);
}
| "(" CONDITIONAL ")" {
$$ = $2;
}
|