1 /* Asset Package Compiler */
7 typedef struct class_state_t yycstate;
8 struct frame_spec_t { apc_facing d; int w, h; };
11 yycstate* yycstate_new(void);
12 void yycstate_delete(yycstate*);
21 struct class_state_t {
23 ir_class class_stack[];
26 extern long sys_pagesize;
28 static void yyerror(yycstate*, char const*);
29 static inline ir_class yyclass_push(yycstate*, ir_class);
30 static inline ir_class yyclass_pop(yycstate*);
31 /* Stack-based class handler */
32 #define yyclass(CS) (*(CS->csp))
33 #define yyclassld(CS) (ir_classld_from_class(yyclass(CS)))
34 #define DEFAULT_VARIANT (uint8_t*)"default"
36 %define parse.error verbose
37 %define parse.lac full
40 %define api.push-pull push
41 %parse-param {yycstate* cs}
51 struct frame_spec_t frame_spec;
69 %type<ld> set_ld set_link
70 %type<frame_spec> frame_spec
72 /* Syntax Directed Translation Scheme of the APC grammar */
75 | class_list statement_list
76 | statement_list class_list
86 NAME CLOPEN { yyclass_push(cs,ir_class_addchild(yyclass(cs), $1)); }
88 CLCLOSE { yyclass_pop(cs); }
92 statement_list statement
97 set_spec data_spec REF PATH { ir_data_assign_path($2,$4); ir_set_assign_data($1,$2); ir_set_assign_ref($1,$3); }
98 | set_spec data_spec PATH { ir_data_assign_path($2,$3); ir_set_assign_data($1,$2); }
99 | set_spec REF PATH { ir_set_assign_ref($1,$2); }
103 SS NAME frame_spec { $$ = ir_framesheet($2,$3.d,$3.w,$3.h); }
104 | SS frame_spec { $$ = ir_framesheet(DEFAULT_VARIANT,$2.d,$2.w,$2.h); }
105 | MAP NAME frame_spec { $$ = ir_mapsheet($2,$3.d,$3.w,$3.h); }
106 | MAP frame_spec { $$ = ir_mapsheet(DEFAULT_VARIANT,$2.d,$2.w,$2.h); }
107 | AUDIO NAME { $$ = ir_audio($2); }
108 | LINK set_ld { $$ = ir_link(OLINK, $2, NULL); }
109 | LINK set_ld MAP { $$ = ir_link(MLINK, $2,NULL); }
110 | LINK set_ld MAP NAME { $$ = ir_link(MLINK, $2,$4); }
111 | LINK set_ld SS { $$ = ir_link(VLINK, $2,NULL); }
112 | LINK set_ld SS NAME { $$ = ir_link(VLINK, $2,$4); }
113 | LINK set_ld AUDIO { $$ = ir_link(ALINK, $2,NULL); }
114 | LINK set_ld AUDIO NAME { $$ = ir_link(ALINK, $2,$4); }
118 set_spec NAME { $$ = ir_set_addchild($1,$2); }
119 | NAME { $$ = ir_class_addset(yyclass(cs),$1); }
123 set_link NAME { $$ = ir_setld_addchild($1,$2); }
124 | NAME { $$ = ir_setld_from_classld(yyclassld(cs),$1); }
128 set_link { $$ = $1; }
129 | REF { $$ = ir_setld_from_ref($1); }
133 NUM NUM { $$ = (struct frame_spec_t) {SFACE,$1,$2}; }
134 | FACING { $$ = (struct frame_spec_t) {$1,0,0}; }
135 | FACING NUM NUM { $$ = (struct frame_spec_t) {$1,$2,$3}; }
136 | %empty { $$ = (struct frame_spec_t) {SFACE,0,0}; }
147 fprintf(stderr, "[class->");
148 for (iter = cs->class_stack; iter <= cs->csp; iter++)
149 fprintf(stderr, "%s/", ir_class_name(*iter));
150 if (strstr(s,"unexpected CLCLOSE") != NULL)
152 fprintf(stderr, "]\n\t");
153 fprintf(stderr, "%s\n", s);
156 yycstate* yycstate_new
158 { yycstate* class_state;
159 class_state = (yycstate*) malloc((size_t) sys_pagesize);
160 if(class_state == NULL)
161 { yyerror(class_state, "Memory allocation error.");
164 class_state->csp = class_state->class_stack;
165 *(class_state->csp) = ir_class_root();
172 { return *cs->csp--; }
175 ir_class yyclass_push
179 { return *++(cs->csp) = class; }
182 ( yycstate* class_state )
183 { free(class_state); }