summaryrefslogtreecommitdiffstats
path: root/dimension/directives.rules
blob: b995c78ff09e7630c3d7e0ecaf601e24313d076f (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
83
84
85
86
87
88
89
90
91
92
#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
;