full struct typedefs
[m6w6/ext-psi] / src / parser_proc.y
1 %include {
2 #include <stddef.h>
3 #include <assert.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <stdarg.h>
7
8 #include "parser.h"
9
10 void psi_error(int, const char *, int, const char *, ...);
11 }
12
13 %name PSI_ParserProc
14 %token_prefix PSI_T_
15 %token_type {PSI_Token *}
16 %token_destructor {free($$);}
17 %default_destructor {(void)P;}
18 %extra_argument {PSI_Parser *P}
19 /* TOKEN is defined inside syntax_error */
20 %syntax_error {
21 ++P->errors;
22 if (TOKEN && TOKEN->type != PSI_T_EOF) {
23 psi_error(PSI_WARNING, TOKEN->file, TOKEN->line, "PSI syntax error: Unexpected token '%s'", TOKEN->text);
24 } else {
25 psi_error(PSI_WARNING, P->psi.file.fn, P->line, "PSI syntax error: Unexpected end of input");
26 }
27 }
28
29 %nonassoc NAME.
30 %left PLUS MINUS.
31 %left SLASH ASTERISK.
32 %fallback NAME TEMP FREE SET LET RETURN LIB STRING.
33
34 file ::= blocks.
35
36 blocks ::= block.
37 blocks ::= blocks block.
38
39 block ::= EOF.
40 block ::= EOS.
41
42 block ::= LIB(T) QUOTED_STRING(libname) EOS. {
43 if (P->psi.file.ln) {
44 P->error(T, PSI_WARNING, "Extra 'lib %s' statement has no effect", libname->text);
45 } else {
46 P->psi.file.ln = strndup(libname->text + 1, libname->size - 2);
47 }
48 free(libname);
49 free(T);
50 }
51
52 block ::= decl(decl). {
53 P->decls = add_decl(P->decls, decl);
54 }
55 block ::= impl(impl). {
56 P->impls = add_impl(P->impls, impl);
57 }
58 block ::= decl_typedef(def). {
59 P->defs = add_decl_typedef(P->defs, def);
60 if (def->type->strct) {
61 P->structs = add_decl_struct(P->structs, def->type->strct);
62 }
63 }
64 block ::= constant(constant). {
65 P->consts = add_constant(P->consts, constant);
66 }
67 block ::= decl_struct(strct). {
68 P->structs = add_decl_struct(P->structs, strct);
69 }
70 block ::= decl_enum(e). {
71 P->enums = add_decl_enum(P->enums, e);
72 }
73
74 enum_name(n) ::= ENUM NAME(N). {
75 n = N;
76 }
77
78 %type decl_enum {decl_enum *}
79 %destructor decl_enum {free_decl_enum($$);}
80 decl_enum(e) ::= enum_name(N) LBRACE decl_enum_items(list) RBRACE. {
81 e = init_decl_enum(N->text, list);
82 e->token = N;
83 }
84
85 %type decl_enum_items {decl_enum_items*}
86 %destructor decl_enum_items {free_decl_enum_items($$);}
87 decl_enum_items(l) ::= decl_enum_item(i). {
88 l = init_decl_enum_items(i);
89 }
90 decl_enum_items(l) ::= decl_enum_items(l_) COMMA decl_enum_item(i). {
91 l = add_decl_enum_item(l_, i);
92 }
93
94 %type decl_enum_item {decl_enum_item*}
95 %destructor decl_enum_item {free_decl_enum_item($$);}
96 decl_enum_item(i) ::= NAME(N) EQUALS num_exp(num). {
97 i = init_decl_enum_item(N->text, num);
98 i->token = N;
99 }
100 decl_enum_item(i) ::= NAME(N). {
101 i = init_decl_enum_item(N->text, NULL);
102 i->token = N;
103 }
104
105 struct_name(n) ::= STRUCT NAME(N). {
106 n = N;
107 }
108
109 %type decl_struct_args_block {decl_args*}
110 %destructor decl_struct_args_block {free_decl_args($$);}
111 decl_struct_args_block(args_) ::= LBRACE struct_args(args) RBRACE. {
112 args_ = args;
113 }
114 %type decl_struct_args {decl_args*}
115 %destructor decl_struct_args {free_decl_args($$);}
116 decl_struct_args(args_) ::= decl_struct_args_block(args). {
117 args_ = args;
118 }
119 decl_struct_args(args_) ::= EOS. {
120 args_ = init_decl_args(NULL);
121 }
122
123
124 %type decl_struct {decl_struct*}
125 %destructor decl_struct {free_decl_struct($$);}
126 decl_struct(strct) ::= struct_name(N) struct_size(size_) decl_struct_args(args). {
127 strct = init_decl_struct(N->text, args);
128 strct->size = size_;
129 strct->token = N;
130 }
131
132 %type struct_size {size_t}
133 struct_size(size) ::= . {
134 size = 0;
135 }
136 struct_size(size) ::= COLON COLON LPAREN NUMBER(SIZ) RPAREN. {
137 size = atol(SIZ->text);
138 free(SIZ);
139 }
140
141 %token_class const_type_token BOOL INT FLOAT STRING.
142 %type const_type {const_type*}
143 %destructor const_type {free_const_type($$);}
144 const_type(type_) ::= const_type_token(T). {
145 type_ = init_const_type(T->type, T->text);
146 free(T);
147 }
148 %type constant {constant*}
149 %destructor constant {free_constant($$);}
150 constant(constant) ::= CONST const_type(type) NSNAME(T) EQUALS impl_def_val(val) EOS. {
151 constant = init_constant(type, T->text, val);
152 free(T);
153 }
154
155 %type decl_typedef {decl_typedef*}
156 %destructor decl_typedef {free_decl_typedef($$);}
157 decl_typedef(def) ::= TYPEDEF decl_typedef_body(def_) EOS. {
158 def = def_;
159 }
160 %type decl_typedef_body {decl_typedef*}
161 %destructor decl_typedef_body {free_decl_typedef($$);}
162 decl_typedef_body(def) ::= struct_name(N) struct_size(size_) decl_struct_args_block(args) NAME(ALIAS). {
163 def = init_decl_typedef(ALIAS->text, init_decl_type(PSI_T_STRUCT, N->text));
164 def->token = ALIAS;
165 def->type->strct = init_decl_struct(N->text, args);
166 def->type->strct->token = N;
167 def->type->strct->size = size_;
168 }
169 decl_typedef_body(def) ::= decl_type(type) NAME(ALIAS). {
170 def = init_decl_typedef(ALIAS->text, type);
171 def->token = ALIAS;
172 }
173 /* support opaque types */
174 decl_typedef_body(def) ::= VOID(V) indirection(i) NAME(ALIAS). {
175 def = init_decl_typedef(ALIAS->text, init_decl_type(i?PSI_T_POINTER:V->type, V->text));
176 def->token = ALIAS;
177 def->type->token = V;
178 }
179
180 %type decl {decl*}
181 %destructor decl {free_decl($$);}
182 decl(decl) ::= decl_abi(abi) decl_func(func) LPAREN decl_args(args) RPAREN EOS. {
183 decl = init_decl(abi, func, args);
184 }
185
186 %type decl_func {decl_arg*}
187 %destructor decl_func {free_decl_arg($$);}
188 decl_func(func) ::= decl_arg(arg). {
189 func = arg;
190 }
191 /* special case for void functions */
192 decl_func(func) ::= VOID(T) NAME(N). {
193 func = init_decl_arg(
194 init_decl_type(T->type, T->text),
195 init_decl_var(N->text, 0, 0)
196 );
197 func->type->token = T;
198 //free(T);
199 free(N);
200 }
201
202 %type decl_abi {decl_abi*}
203 %destructor decl_abi {free_decl_abi($$);}
204 decl_abi(abi) ::= NAME(T). {
205 abi = init_decl_abi(T->text);
206 abi->token = T;
207 }
208
209 %type decl_var {decl_var*}
210 %destructor decl_var {free_decl_var($$);}
211 decl_var(var) ::= indirection(p) NAME(T). {
212 var = init_decl_var(T->text, p, 0);
213 var->token = T;
214 }
215 decl_var(var) ::= indirection(p) NAME(T) LBRACKET NUMBER(D) RBRACKET. {
216 var = init_decl_var(T->text, p+1, atol(D->text));
217 var->token = T;
218 free(D);
219 }
220
221 %type decl_vars {decl_vars*}
222 %destructor decl_vars {free_decl_vars($$);}
223 decl_vars(vars) ::= decl_var(var). {
224 vars = init_decl_vars(var);
225 }
226 decl_vars(vars) ::= decl_vars(vars_) COMMA decl_var(var). {
227 vars = add_decl_var(vars_, var);
228 }
229
230 %type decl_arg {decl_arg*}
231 %destructor decl_arg {free_decl_arg($$);}
232 decl_arg(arg_) ::= const_decl_type(type) decl_var(var). {
233 arg_ = init_decl_arg(type, var);
234 }
235 /* void pointers need a specific rule */
236 decl_arg(arg_) ::= VOID(T) pointers(p) NAME(N). {
237 arg_ = init_decl_arg(
238 init_decl_type(T->type, T->text),
239 init_decl_var(N->text, p, 0)
240 );
241 arg_->type->token = T;
242 arg_->var->token = N;
243 arg_->token = N;
244 }
245 decl_arg(arg_) ::= CONST VOID(T) pointers(p) NAME(N). {
246 arg_ = init_decl_arg(
247 init_decl_type(T->type, T->text),
248 init_decl_var(N->text, p, 0)
249 );
250 arg_->type->token = T;
251 arg_->var->token = N;
252 arg_->token = N;
253 }
254
255 %type decl_args {decl_args*}
256 %destructor decl_args {free_decl_args($$);}
257 decl_args ::= .
258 decl_args ::= VOID.
259 decl_args(args) ::= decl_arg(arg). {
260 args = init_decl_args(arg);
261 }
262 decl_args(args) ::= decl_args(args_) COMMA decl_arg(arg). {
263 args = add_decl_arg(args_, arg);
264 }
265 decl_args(args) ::= decl_args(args_) COMMA ELLIPSIS. {
266 args = args_;
267 args->varargs = 1;
268 }
269 %type struct_args {decl_args*}
270 %destructor struct_args {free_decl_args($$);}
271 struct_args(args) ::= struct_arg(arg). {
272 args = init_decl_args(arg);
273 }
274 struct_args(args) ::= struct_args(args_) struct_arg(arg). {
275 args = add_decl_arg(args_, arg);
276 }
277 %type struct_arg {decl_arg*}
278 %destructor struct_arg {free_decl_arg($$);}
279 struct_arg(arg) ::= decl_arg(arg_) struct_layout(layout_) EOS. {
280 arg_->layout = layout_;
281 arg = arg_;
282 }
283
284 %type struct_layout {decl_struct_layout*}
285 %destructor struct_layout {free_decl_struct_layout($$);}
286 struct_layout(layout) ::= . {
287 layout = NULL;
288 }
289 struct_layout(layout) ::= COLON COLON LPAREN NUMBER(POS) COMMA NUMBER(SIZ) RPAREN. {
290 layout = init_decl_struct_layout(atol(POS->text), atol(SIZ->text));
291 free(POS);
292 free(SIZ);
293 }
294
295 /* un/signed, urgh */
296 decl_scalar_type(type_) ::= CHAR(C). {
297 type_ = C;
298 }
299 decl_scalar_type(type_) ::= SHORT(S) decl_scalar_type_short(s). {
300 if (s) {
301 type_ = PSI_TokenCat(2, S, s);
302 free(S);
303 free(s);
304 } else {
305 type_ = S;
306 }
307 }
308 decl_scalar_type_short(s) ::= . {
309 s = NULL;
310 }
311
312 decl_scalar_type_short(s) ::= INT(I). {
313 s = I;
314 }
315 decl_scalar_type(type_) ::= INT(I). {
316 type_ = I;
317 }
318 decl_scalar_type(type_) ::= LONG(L) decl_scalar_type_long(l). {
319 if (l) {
320 type_ = PSI_TokenCat(2, L, l);
321 free(L);
322 free(l);
323 } else {
324 type_ = L;
325 }
326 }
327 decl_scalar_type_long(l) ::= . {
328 l = NULL;
329 }
330 decl_scalar_type_long(l) ::= DOUBLE(D). {
331 l = D;
332 }
333 decl_scalar_type_long(l) ::= LONG(L) decl_scalar_type_long_long(ll). {
334 if (ll) {
335 l = PSI_TokenCat(2, L, ll);
336 free(L);
337 free(ll);
338 } else {
339 l = L;
340 }
341 }
342 decl_scalar_type_long_long(ll) ::= . {
343 ll = NULL;
344 }
345 decl_scalar_type_long_long(ll) ::= INT(I). {
346 ll = I;
347 }
348 decl_type(type_) ::= UNSIGNED(U) decl_scalar_type(N). {
349 PSI_Token *T = PSI_TokenCat(2, U, N);
350 type_ = init_decl_type(T->type, T->text);
351 type_->token = T;
352 free(U);
353 free(N);
354 }
355 decl_type(type_) ::= SIGNED(S) decl_scalar_type(N). {
356 PSI_Token *T = PSI_TokenCat(2, S, N);
357 type_ = init_decl_type(T->type, T->text);
358 type_->token = T;
359 free(S);
360 free(N);
361 }
362 decl_type(type_) ::= UNSIGNED(U). {
363 type_ = init_decl_type(PSI_T_NAME, U->text);
364 type_->token = U;
365 }
366 decl_type(type_) ::= SIGNED(S). {
367 type_ = init_decl_type(PSI_T_NAME, S->text);
368 type_->token = S;
369 }
370 decl_type(type_) ::= decl_scalar_type(N). {
371 type_ = init_decl_type(N->type, N->text);
372 type_->token = N;
373 }
374 /* structs ! */
375 decl_type(type_) ::= STRUCT(S) NAME(T). {
376 type_ = init_decl_type(S->type, T->text);
377 type_->token = T;
378 free(S);
379 }
380 decl_type(type_) ::= ENUM(E) NAME(T). {
381 type_ = init_decl_type(E->type, T->text);
382 type_->token = T;
383 free(E);
384 }
385 %token_class decl_type_token FLOAT DOUBLE INT8 UINT8 INT16 UINT16 INT32 UINT32 INT64 UINT64 NAME.
386 %type decl_type {decl_type*}
387 %destructor decl_type {free_decl_type($$);}
388 decl_type(type_) ::= decl_type_token(T). {
389 type_ = init_decl_type(T->type, T->text);
390 type_->token = T;
391 }
392
393
394 %type const_decl_type {decl_type*}
395 %destructor const_decl_type {free_decl_type($$);}
396 const_decl_type(type) ::= decl_type(type_). {
397 type = type_;
398 }
399 const_decl_type(type) ::= CONST decl_type(type_). {
400 type = type_;
401 }
402
403 %type impl {impl*}
404 %destructor impl {free_impl($$);}
405 impl(impl) ::= impl_func(func) LBRACE impl_stmts(stmts) RBRACE. {
406 impl = init_impl(func, stmts);
407 }
408
409 %type impl_func {impl_func*}
410 %destructor impl_func {free_impl_func($$);}
411 impl_func(func) ::= FUNCTION reference(r) NSNAME(NAME) impl_args(args) COLON impl_type(type). {
412 func = init_impl_func(NAME->text, args, type, r);
413 func->token = NAME;
414 }
415
416 %token_class impl_def_val_token NULL NUMBER TRUE FALSE QUOTED_STRING.
417 %type impl_def_val {impl_def_val*}
418 %destructor impl_def_val {free_impl_def_val($$);}
419 impl_def_val(def) ::= impl_def_val_token(T). {
420 def = init_impl_def_val(T->type, T->text);
421 free(T);
422 }
423
424 %type impl_var {impl_var*}
425 %destructor impl_var {free_impl_var($$);}
426 impl_var(var) ::= reference(r) DOLLAR NAME(T). {
427 var = init_impl_var(T->text, r);
428 var->token = T;
429 }
430
431 %type impl_arg {impl_arg*}
432 %destructor impl_arg {free_impl_arg($$);}
433 impl_arg(arg) ::= impl_type(type) impl_var(var). {
434 arg = init_impl_arg(type, var, NULL);
435 }
436 impl_arg(arg) ::= impl_type(type) impl_var(var) EQUALS impl_def_val(def). {
437 arg = init_impl_arg(type, var, def);
438 }
439
440 %type impl_args {impl_args*}
441 %destructor impl_args {free_impl_args($$);}
442 impl_args(args) ::= LPAREN RPAREN. {
443 args = NULL;
444 }
445 impl_args(args) ::= LPAREN impl_arg_list(args_) RPAREN. {
446 args = args_;
447 }
448 impl_args(args) ::= LPAREN impl_arg_list(args_) COMMA impl_vararg(va) RPAREN. {
449 args = args_;
450 args->vararg.name = va;
451 }
452
453 %type impl_vararg {impl_arg*}
454 %destructor impl_vararg {free_impl_arg($$);}
455 impl_vararg(va) ::= impl_type(type) reference(r) ELLIPSIS DOLLAR NAME(T). {
456 va = init_impl_arg(type, init_impl_var(T->text, r), NULL);
457 free(T);
458 }
459
460 %type impl_arg_list {impl_args*}
461 %destructor impl_arg_list {free_impl_args($$);}
462 impl_arg_list(args) ::= impl_arg(arg). {
463 args = init_impl_args(arg);
464 }
465 impl_arg_list(args) ::= impl_arg_list(args_) COMMA impl_arg(arg). {
466 args = add_impl_arg(args_, arg);
467 }
468
469 %type impl_stmts {impl_stmts*}
470 %destructor impl_stmts {free_impl_stmts($$);}
471 impl_stmts(stmts) ::= impl_stmt(stmt). {
472 stmts = init_impl_stmts(stmt);
473 }
474 impl_stmts(stmts) ::= impl_stmts(stmts_) impl_stmt(stmt). {
475 stmts = add_impl_stmt(stmts_, stmt);
476 }
477
478 %type impl_stmt {impl_stmt*}
479 %destructor impl_stmt {free_impl_stmt($$);}
480 impl_stmt(stmt) ::= let_stmt(let). {
481 stmt = init_impl_stmt(PSI_T_LET, let);
482 }
483 impl_stmt(stmt) ::= set_stmt(set). {
484 stmt = init_impl_stmt(PSI_T_SET, set);
485 }
486 impl_stmt(stmt) ::= return_stmt(ret). {
487 stmt = init_impl_stmt(PSI_T_RETURN, ret);
488 }
489 impl_stmt(stmt) ::= free_stmt(free). {
490 stmt = init_impl_stmt(PSI_T_FREE, free);
491 }
492
493 %token_class num_exp_token NUMBER NSNAME.
494 %token_class num_exp_op_token PLUS MINUS ASTERISK SLASH.
495 %type num_exp {num_exp*}
496 %destructor num_exp {free_num_exp($$);}
497 num_exp(exp) ::= num_exp_token(tok). {
498 exp = init_num_exp(tok->type, tok->text);
499 exp->token = tok;
500 }
501 num_exp(exp) ::= decl_var(var). {
502 exp = init_num_exp(PSI_T_NAME, var);
503 exp->token = PSI_TokenCopy(var->token);
504 }
505 num_exp(exp) ::= num_exp(exp_) num_exp_op_token(operator_) num_exp(operand_). {
506 exp_->operator = operator_->type;
507 exp_->operand = operand_;
508 exp = exp_;
509 free(operator_);
510 }
511
512 %type let_stmt {let_stmt*}
513 %destructor let_stmt {free_let_stmt($$);}
514 let_stmt(let) ::= LET decl_var(var) EOS. {
515 let = init_let_stmt(var, init_let_val(PSI_LET_NULL, NULL));
516 }
517 let_stmt(let) ::= LET decl_var(var) EQUALS reference(r) let_val(val) EOS. {
518 val->flags.one.is_reference = r ? 1 : 0;
519 let = init_let_stmt(var, val);
520 }
521 let_stmt(let) ::= TEMP decl_var(var) EQUALS decl_var(val) EOS. {
522 let = init_let_stmt(var, init_let_val(PSI_LET_TMP, val));
523 }
524
525 %type let_val {let_val*}
526 %destructor let_val {free_let_val($$);}
527 let_val(val) ::= NULL. {
528 val = init_let_val(PSI_LET_NULL, NULL);
529 }
530 let_val(val) ::= num_exp(exp). {
531 val = init_let_val(PSI_LET_NUMEXP, exp);
532 }
533 let_val(val) ::= CALLOC LPAREN let_calloc(alloc) RPAREN. {
534 val = init_let_val(PSI_LET_CALLOC, alloc);
535 }
536 let_val(val) ::= let_func(func). {
537 val = init_let_val(PSI_LET_FUNC, func);
538 }
539
540 %type let_calloc {let_calloc*}
541 %destructor let_calloc {free_let_calloc($$);}
542 let_calloc(alloc) ::= num_exp(nmemb) COMMA num_exp(size). {
543 alloc = init_let_calloc(nmemb, size);
544 }
545 %token_class let_func_token OBJVAL ARRVAL PATHVAL STRLEN STRVAL FLOATVAL INTVAL BOOLVAL.
546 %type let_func {let_func*}
547 %destructor let_func {free_let_func($$);}
548 let_func(func) ::= let_func_token(T) LPAREN impl_var(var) RPAREN. {
549 func = init_let_func(T->type, T->text, var);
550 free(T);
551 }
552
553
554 %type set_stmt {set_stmt*}
555 %destructor set_stmt {free_set_stmt($$);}
556 set_stmt(set) ::= SET impl_var(var) EQUALS set_value(val) EOS. {
557 set = init_set_stmt(var, val);
558 }
559
560 %type set_value {set_value*}
561 %destructor set_value {free_set_value($$);}
562 set_value(val) ::= set_func(func) LPAREN decl_var(var) RPAREN. {
563 val = init_set_value(func, init_decl_vars(var));
564 }
565 set_value(val) ::= set_func(func) LPAREN decl_var(var) COMMA num_exp(num_) RPAREN. {
566 val = init_set_value(func, init_decl_vars(var));
567 val->num = num_;
568 }
569 set_value(val) ::= set_func(func_) LPAREN decl_var(var) COMMA ELLIPSIS(T) RPAREN. {
570 free_set_func(func_);
571 val = init_set_value(init_set_func(T->type, T->text), init_decl_vars(var));
572 val->func->token = T;
573 }
574 set_value(val) ::= set_func(func_) LPAREN decl_var(var) COMMA set_vals(vals) RPAREN. {
575 val = vals;
576 val->func = func_;
577 val->vars = init_decl_vars(var);
578 }
579 set_value(val) ::= set_func(func_) LPAREN decl_var(var) COMMA num_exp(num_) COMMA set_vals(vals) RPAREN. {
580 val = vals;
581 val->func = func_;
582 val->num = num_;
583 val->vars = init_decl_vars(var);
584 }
585 %type set_vals {set_value*}
586 %destructor set_vals {free_set_value($$);}
587 set_vals(vals) ::= set_value(val). {
588 vals = add_inner_set_value(init_set_value(NULL, NULL), val);
589 }
590 set_vals(vals) ::= set_vals(vals_) COMMA set_value(val). {
591 vals = add_inner_set_value(vals_, val);
592 }
593
594 %token_class set_func_token TO_OBJECT TO_ARRAY TO_STRING TO_INT TO_FLOAT TO_BOOL VOID.
595 %type set_func {set_func*}
596 %destructor set_func {free_set_func($$);}
597 set_func(func) ::= set_func_token(T). {
598 func = init_set_func(T->type, T->text);
599 func->token = T;
600 }
601
602 %type return_stmt {return_stmt*}
603 %destructor return_stmt {free_return_stmt($$);}
604 return_stmt(ret) ::= RETURN(T) set_value(val) EOS. {
605 ret = init_return_stmt(val);
606 ret->token = T;
607 }
608
609 %type free_stmt {free_stmt*}
610 %destructor free_stmt {free_free_stmt($$);}
611 free_stmt(free) ::= FREE free_calls(calls) EOS. {
612 free = init_free_stmt(calls);
613 }
614
615 %type free_calls {free_calls*}
616 %destructor free_calls {free_free_calls($$);}
617 free_calls(calls) ::= free_call(call). {
618 calls = init_free_calls(call);
619 }
620 free_calls(calls) ::= free_calls(calls_) COMMA free_call(call). {
621 calls = add_free_call(calls_, call);
622 }
623
624 %type free_call {free_call*}
625 %destructor free_call {free_free_call($$);}
626 free_call(call) ::= NAME(F) LPAREN decl_vars(vars) RPAREN. {
627 call = init_free_call(F->text, vars);
628 call->token = F;
629 }
630
631 %token_class impl_type_token VOID MIXED BOOL INT FLOAT STRING ARRAY OBJECT.
632 %type impl_type {impl_type*}
633 %destructor impl_type {free_impl_type($$);}
634 impl_type(type_) ::= impl_type_token(T). {
635 type_ = init_impl_type(T->type, T->text);
636 free(T);
637 }
638
639 %type reference {char}
640 reference(r) ::= . {r = 0;}
641 reference(r) ::= AMPERSAND. {r = 1;}
642
643 %type indirection {unsigned}
644 indirection(i) ::= . {i = 0;}
645 indirection(i) ::= pointers(p). {i = p;}
646
647 %type pointers {unsigned}
648 pointers(p) ::= ASTERISK. {p = 1;}
649 pointers(p) ::= pointers(P) ASTERISK. {p = P+1;}