parser wip pt2
[henge/webcc.git] / src / apc / parser.y
1 /* Asset Package Compiler */
2 %{
3 #include <stdio.h>
4 #include <string.h>
5 #include <dirent.h>
6 #include "sprite.h"
7 #include "symbol.h"
8 #include <png.h>
9 #include "ir.h"
10
11 extern int lexer_init();
12 extern int lexer();
13 #define yylex lexer
14
15
16 void yyerror();
17 %}
18 %define parse.error verbose
19 %define lr.type ielr
20 %define api.value.type union
21 %token <char*> WORD
22 //operators
23 %token CLOPEN // /
24 %token CLCLOSE // \
25 %token RLS //!
26 %token RLE //#
27 %token RT //*
28 %token HB
29 //nonterminal types
30 %type <int> element
31 %type <int> vdat
32 %type <str> elem_label
33 //terminals
34 %token <int> NUM
35 %token <int> fd
36 %token <str> STR
37 %token <int> VAR
38 %token <int> SS
39 //precedence
40 %right LOW HIGH
41
42 /* Syntax Directed Translation Scheme of the APC grammar */
43
44
45 /* Rules */
46 %%
47 output:
48 class_list {condense();} //Seperate file?
49 ;
50
51 class_list:
52 class_list class {cbi++;};
53 | class
54 ;
55
56 class_label:
57 STR
58 ;
59
60 class:
61 class_label CLOPEN class_closure CLCLOSE {CB[cbi].label = $1;};
62 ;
63
64 class_closure:
65 subclass_list
66 | subclass_list set_list
67 | set_list
68 ;
69
70 subclass_list:
71 subclass_list class {CB[cbi].subclass_index++;};
72 | class
73 ;
74
75 set_list:
76 set_list set {CB[cbi].set_index++;};
77 | set
78 ;
79
80
81 //set needs a label, vdat_id.
82 set:
83 set_map_data element_list {insert_set();};
84 | element_list
85 ;
86
87
88 //TODO: Figure out what to do with hitbox and root.
89 set_map_data:
90 ref_list {};
91 | ref_list hitbox
92 | ref_list hitbox root
93 | hitbox root
94 | hitbox
95 | root
96 ;
97
98 ref_list:
99 RLS quads RLE
100 ;
101
102 quads:
103 quads quad {OB[obi].ref_index++;OB[obi].num_ref++;};
104 | quad
105 ;
106
107 quad:
108 NUM NUM NUM NUM {insert_ref($1, $2, $3, $4);};
109 ;
110
111 hitbox:
112 HB NUM
113 ;
114
115 root:
116 RT NUM NUM NUM
117 ;
118
119 //parent_id is the set_index of the subclass_index.
120 element_list:
121 element_list element {CB[cbi].set_stack[stack_index].num_ele++;};
122 | element
123 ;
124
125 element:
126 set_label elem_label vdat {insert_ele($2,$3); vbi++;};
127 ;
128
129 set_label:
130 STR
131 ;
132
133 elem_label:
134 STR
135 ;
136
137 vdat:
138 vdat model {VB[vbi].num_models++;};
139 | model
140 ;
141
142 model:
143 model fdat
144 | fdat
145 ;
146
147 fdat:
148 label SS FNAME {insert_fdat($1, $2, $3);};
149 ;
150
151 label:
152 STR
153 ;
154
155 ref:
156 NUM
157 ;
158
159 FNAME:
160 STR
161 ;
162
163 %%
164 int
165 main (argc, argv)
166 {
167 lexer_init();
168 yyparse();
169 return 0;
170 }
171
172 void
173 yyerror (char const *s)
174 { fprintf(stderr, "%s\n", s);
175 }