summaryrefslogtreecommitdiffstats
path: root/dimension/directives.rules
blob: 392408dc31c91246f13431b9a84dc07c36cf4292 (plain)
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
#line 1 "directives.rules"

/*
 * Start symbol
 */

LANGUAGE_DIRECTIVE: "#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);
                  }

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
      | 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;
           }