10 void psi_error(int, const char *, int, const char *, ...);
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 */
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);
25 psi_error(PSI_WARNING, P->psi.file.fn, P->line, "PSI syntax error: Unexpected end of input");
32 %fallback NAME TEMP FREE SET LET RETURN CALLOC CALLBACK ZVAL LIB STRING.
37 blocks ::= blocks block.
42 block ::= LIB(T) QUOTED_STRING(libname) EOS. {
44 P->error(P, T, PSI_WARNING, "Extra 'lib %s' statement has no effect", libname->text);
46 P->psi.file.ln = strndup(libname->text + 1, libname->size - 2);
52 block ::= decl(decl). {
53 P->decls = add_decl(P->decls, decl);
55 block ::= impl(impl). {
56 P->impls = add_impl(P->impls, impl);
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);
64 P->enums = add_decl_enum(P->enums, def->type->enm);
67 block ::= constant(constant). {
68 P->consts = add_constant(P->consts, constant);
70 block ::= decl_struct(strct). {
71 P->structs = add_decl_struct(P->structs, strct);
73 block ::= decl_union(u). {
74 P->unions = add_decl_union(P->unions, u);
76 block ::= decl_enum(e). {
77 P->enums = add_decl_enum(P->enums, e);
80 optional_name(n) ::= .{
83 optional_name(n) ::= NAME(N). {
87 enum_name(n) ::= ENUM(E) optional_name(N). {
94 PSI_TokenHash(E, digest);
95 n = PSI_TokenTranslit(PSI_TokenAppend(E, 1, digest), " ", "@");
99 %type decl_enum {decl_enum *}
100 %destructor decl_enum {free_decl_enum($$);}
101 decl_enum(e) ::= enum_name(N) LBRACE decl_enum_items(list) RBRACE. {
102 e = init_decl_enum(N->text, list);
106 %type decl_enum_items {decl_enum_items*}
107 %destructor decl_enum_items {free_decl_enum_items($$);}
108 decl_enum_items(l) ::= decl_enum_item(i). {
109 l = init_decl_enum_items(i);
111 decl_enum_items(l) ::= decl_enum_items(l_) COMMA decl_enum_item(i). {
112 l = add_decl_enum_item(l_, i);
115 %type decl_enum_item {decl_enum_item*}
116 %destructor decl_enum_item {free_decl_enum_item($$);}
117 decl_enum_item(i) ::= NAME(N) EQUALS num_exp(num). {
118 i = init_decl_enum_item(N->text, num);
121 decl_enum_item(i) ::= NAME(N). {
122 i = init_decl_enum_item(N->text, NULL);
126 union_name(n) ::= UNION(U) optional_name(N). {
133 PSI_TokenHash(U, digest);
134 n = PSI_TokenTranslit(PSI_TokenAppend(U, 1, digest), " ", "@");
138 struct_name(n) ::= STRUCT(S) optional_name(N). {
145 PSI_TokenHash(S, digest);
146 n = PSI_TokenTranslit(PSI_TokenAppend(S, 1, digest), " ", "@");
150 %type decl_struct_args_block {decl_args*}
151 %destructor decl_struct_args_block {free_decl_args($$);}
152 decl_struct_args_block(args_) ::= LBRACE struct_args(args) RBRACE. {
155 %type decl_struct_args {decl_args*}
156 %destructor decl_struct_args {free_decl_args($$);}
157 decl_struct_args(args_) ::= decl_struct_args_block(args). {
160 decl_struct_args(args_) ::= EOS. {
161 args_ = init_decl_args(NULL);
165 %type decl_struct {decl_struct*}
166 %destructor decl_struct {free_decl_struct($$);}
167 decl_struct(strct) ::= STRUCT NAME(N) align_and_size(as) decl_struct_args(args). {
168 strct = init_decl_struct(N->text, args);
174 %type align_and_size { struct {size_t a; size_t s; } }
175 align_and_size(as) ::= . {
179 align_and_size(as) ::= COLON COLON LPAREN NUMBER(A) COMMA NUMBER(S) RPAREN. {
180 as.a = atol(A->text);
181 as.s = atol(S->text);
186 %type decl_union {decl_union*}
187 %destructor decl_union {free_decl_union($$);}
188 decl_union(u) ::= UNION NAME(N) align_and_size(as) decl_struct_args(args). {
189 u = init_decl_union(N->text, args);
195 %token_class const_type_token BOOL INT FLOAT STRING.
196 %type const_type {const_type*}
197 %destructor const_type {free_const_type($$);}
198 const_type(type_) ::= const_type_token(T). {
199 type_ = init_const_type(T->type, T->text);
202 %type constant {constant*}
203 %destructor constant {free_constant($$);}
204 constant(constant) ::= CONST const_type(type) NSNAME(T) EQUALS impl_def_val(val) EOS. {
205 constant = init_constant(type, T->text, val);
209 %type decl_typedef {decl_arg*}
210 %destructor decl_typedef {
212 if ($$->type->strct) {
213 free_decl_struct($$->type->strct);
216 free_decl_enum($$->type->enm);
218 if ($$->type->func) {
219 free_decl($$->type->func);
222 decl_typedef(def) ::= TYPEDEF(T) decl_typedef_body(def_) EOS. {
226 %type decl_typedef_body_ex {decl_arg*}
227 %destructor decl_typedef_body_ex {
229 if ($$->type->strct) {
230 free_decl_struct($$->type->strct);
233 free_decl_enum($$->type->enm);
236 free_decl_union($$->type->unn);
238 if ($$->type->func) {
239 free_decl($$->type->func);
242 decl_typedef_body_ex(def) ::= struct_name(N) align_and_size(as) decl_struct_args_block(args) decl_var(var). {
243 def = init_decl_arg(init_decl_type(PSI_T_STRUCT, N->text), var);
244 def->type->token = PSI_TokenCopy(N);
245 def->type->strct = init_decl_struct(N->text, args);
246 def->type->strct->token = N;
247 def->type->strct->align = as.a;
248 def->type->strct->size = as.s;
250 decl_typedef_body_ex(def) ::= union_name(N) align_and_size(as) decl_struct_args_block(args) decl_var(var). {
251 def = init_decl_arg(init_decl_type(PSI_T_UNION, N->text), var);
252 def->type->token = PSI_TokenCopy(N);
253 def->type->unn = init_decl_union(N->text, args);
254 def->type->unn->token = N;
255 def->type->unn->align = as.a;
256 def->type->unn->size = as.s;
258 decl_typedef_body_ex(def) ::= decl_enum(e) NAME(ALIAS). {
259 def = init_decl_arg(init_decl_type(PSI_T_ENUM, e->name), init_decl_var(ALIAS->text, 0, 0));
260 def->var->token = ALIAS;
261 def->type->token = PSI_TokenCopy(e->token);
264 %type decl_typedef_body {decl_arg*}
265 %destructor decl_typedef_body {
267 if ($$->type->strct) {
268 free_decl_struct($$->type->strct);
271 free_decl_enum($$->type->enm);
274 free_decl_union($$->type->unn);
276 if ($$->type->func) {
277 free_decl($$->type->func);
280 decl_typedef_body(def) ::= decl_typedef_body_ex(def_). {
283 %type decl_typedef_body_fn_args {decl_args *}
284 %destructor decl_typedef_body_fn_args {free_decl_args($$);}
285 decl_typedef_body_fn_args(args) ::= LPAREN decl_args(args_) RPAREN. {
288 decl_typedef_body(def) ::= decl_func(func_) decl_typedef_body_fn_args(args). {
289 def = init_decl_arg(init_decl_type(PSI_T_FUNCTION, func_->var->name), copy_decl_var(func_->var));
290 def->type->token = PSI_TokenCopy(func_->token);
291 def->type->func = init_decl(init_decl_abi("default"), func_, args);
293 decl_typedef_body(def) ::= decl_arg(arg). {
298 %destructor decl {free_decl($$);}
299 decl(decl) ::= decl_abi(abi) decl_func(func) LPAREN decl_args(args) RPAREN EOS. {
300 decl = init_decl(abi, func, args);
303 %type decl_func {decl_arg*}
304 %destructor decl_func {free_decl_arg($$);}
305 decl_func(func) ::= decl_arg(arg). {
308 /* special case for void functions */
309 decl_func(func) ::= VOID(T) NAME(N). {
310 func = init_decl_arg(
311 init_decl_type(T->type, T->text),
312 init_decl_var(N->text, 0, 0)
314 func->type->token = T;
315 func->var->token = N;
318 decl_typedef_body(def) ::= VOID(T) indirection(i) LPAREN ASTERISK NAME(N) RPAREN decl_typedef_body_fn_args(args). {
319 decl_arg *func_ = init_decl_arg(
320 init_decl_type(T->type, T->text),
321 init_decl_var(N->text, i, 0)
323 func_->type->token = T;
324 func_->var->token = N;
326 def = init_decl_arg(init_decl_type(PSI_T_FUNCTION, func_->var->name), copy_decl_var(func_->var));
327 def->type->token = PSI_TokenCopy(func_->token);
328 def->type->func = init_decl(init_decl_abi("default"), func_, args);
330 decl_typedef_body(def) ::= CONST VOID(T) pointers(i) LPAREN ASTERISK NAME(N) RPAREN decl_typedef_body_fn_args(args). {
331 decl_arg *func_ = init_decl_arg(
332 init_decl_type(T->type, T->text),
333 init_decl_var(N->text, i, 0)
335 func_->type->token = T;
336 func_->var->token = N;
338 def = init_decl_arg(init_decl_type(PSI_T_FUNCTION, func_->var->name), copy_decl_var(func_->var));
339 def->type->token = PSI_TokenCopy(func_->token);
340 def->type->func = init_decl(init_decl_abi("default"), func_, args);
343 %type decl_abi {decl_abi*}
344 %destructor decl_abi {free_decl_abi($$);}
345 decl_abi(abi) ::= NAME(T). {
346 abi = init_decl_abi(T->text);
350 %type decl_var {decl_var*}
351 %destructor decl_var {free_decl_var($$);}
352 decl_var(var) ::= indirection(p) NAME(T). {
353 var = init_decl_var(T->text, p, 0);
356 decl_var(var) ::= indirection(p) NAME(T) LBRACKET NUMBER(D) RBRACKET. {
357 var = init_decl_var(T->text, p+1, atol(D->text));
362 %type decl_vars {decl_vars*}
363 %destructor decl_vars {free_decl_vars($$);}
364 decl_vars(vars) ::= decl_var(var). {
365 vars = init_decl_vars(var);
367 decl_vars(vars) ::= decl_vars(vars_) COMMA decl_var(var). {
368 vars = add_decl_var(vars_, var);
371 %type decl_arg {decl_arg*}
372 %destructor decl_arg {free_decl_arg($$);}
373 decl_arg(arg_) ::= const_decl_type(type) decl_var(var). {
374 arg_ = init_decl_arg(type, var);
376 decl_typedef_body(def) ::= const_decl_type(type_) indirection(i) LPAREN ASTERISK NAME(N) RPAREN decl_typedef_body_fn_args(args). {
377 decl_arg *func_ = init_decl_arg(
379 init_decl_var(N->text, i, 0)
381 func_->var->token = N;
383 def = init_decl_arg(init_decl_type(PSI_T_FUNCTION, func_->var->name), copy_decl_var(func_->var));
384 def->type->token = PSI_TokenCopy(func_->token);
385 def->type->func = init_decl(init_decl_abi("default"), func_, args);
388 /* void pointers need a specific rule */
389 decl_arg(arg_) ::= VOID(T) pointers(p) NAME(N). {
390 arg_ = init_decl_arg(
391 init_decl_type(T->type, T->text),
392 init_decl_var(N->text, p, 0)
394 arg_->type->token = T;
395 arg_->var->token = N;
398 decl_arg(arg_) ::= CONST VOID(T) pointers(p) NAME(N). {
399 arg_ = init_decl_arg(
400 init_decl_type(T->type, T->text),
401 init_decl_var(N->text, p, 0)
403 arg_->type->token = T;
404 arg_->var->token = N;
408 %type decl_args {decl_args*}
409 %destructor decl_args {free_decl_args($$);}
412 decl_args(args) ::= decl_arg(arg). {
413 args = init_decl_args(arg);
415 decl_args(args) ::= decl_args(args_) COMMA decl_arg(arg). {
416 args = add_decl_arg(args_, arg);
418 decl_args(args) ::= decl_args(args_) COMMA ELLIPSIS. {
422 %type struct_args {decl_args*}
423 %destructor struct_args {free_decl_args($$);}
424 struct_args(args) ::= struct_arg(arg). {
425 args = init_decl_args(arg);
427 struct_args(args) ::= struct_args(args_) struct_arg(arg). {
428 args = add_decl_arg(args_, arg);
430 %type struct_arg {decl_arg*}
431 %destructor struct_arg {
433 if ($$->type->strct) {
434 free_decl_struct($$->type->strct);
437 free_decl_enum($$->type->enm);
439 if ($$->type->func) {
440 free_decl($$->type->func);
443 struct_arg(arg_) ::= decl_typedef_body_ex(def) EOS. {
445 if (def->type->strct) {
446 P->structs = add_decl_struct(P->structs, def->type->strct);
448 if (def->type->enm) {
449 P->enums = add_decl_enum(P->enums, def->type->enm);
452 struct_arg(arg) ::= decl_arg(arg_) struct_layout(layout_) EOS. {
453 arg_->layout = layout_;
457 %type struct_layout {decl_struct_layout*}
458 %destructor struct_layout {free_decl_struct_layout($$);}
459 struct_layout(layout) ::= . {
462 struct_layout(layout) ::= COLON COLON LPAREN NUMBER(POS) COMMA NUMBER(SIZ) RPAREN. {
463 layout = init_decl_struct_layout(atol(POS->text), atol(SIZ->text));
468 /* un/signed, urgh */
469 decl_scalar_type(type_) ::= CHAR(C). {
472 decl_scalar_type(type_) ::= SHORT(S) decl_scalar_type_short(s). {
474 type_ = PSI_TokenCat(2, S, s);
481 decl_scalar_type_short(s) ::= . {
485 decl_scalar_type_short(s) ::= INT(I). {
488 decl_scalar_type(type_) ::= INT(I). {
491 decl_scalar_type(type_) ::= LONG(L) decl_scalar_type_long(l). {
493 type_ = PSI_TokenCat(2, L, l);
500 decl_scalar_type_long(l) ::= . {
503 decl_scalar_type_long(l) ::= DOUBLE(D). {
506 decl_scalar_type_long(l) ::= LONG(L) decl_scalar_type_long_long(ll). {
508 l = PSI_TokenCat(2, L, ll);
515 decl_scalar_type_long_long(ll) ::= . {
518 decl_scalar_type_long_long(ll) ::= INT(I). {
521 decl_type(type_) ::= UNSIGNED(U) decl_scalar_type(N). {
522 PSI_Token *T = PSI_TokenCat(2, U, N);
523 type_ = init_decl_type(T->type, T->text);
528 decl_type(type_) ::= SIGNED(S) decl_scalar_type(N). {
529 PSI_Token *T = PSI_TokenCat(2, S, N);
530 type_ = init_decl_type(T->type, T->text);
535 decl_type(type_) ::= UNSIGNED(U). {
536 type_ = init_decl_type(PSI_T_NAME, U->text);
539 decl_type(type_) ::= SIGNED(S). {
540 type_ = init_decl_type(PSI_T_NAME, S->text);
543 decl_type(type_) ::= decl_scalar_type(N). {
544 type_ = init_decl_type(N->type, N->text);
548 decl_type(type_) ::= STRUCT(S) NAME(T). {
549 type_ = init_decl_type(S->type, T->text);
553 decl_type(type_) ::= UNION(U) NAME(T). {
554 type_ = init_decl_type(U->type, T->text);
558 decl_type(type_) ::= ENUM(E) NAME(T). {
559 type_ = init_decl_type(E->type, T->text);
563 %token_class decl_type_token FLOAT DOUBLE INT8 UINT8 INT16 UINT16 INT32 UINT32 INT64 UINT64 NAME.
564 %type decl_type {decl_type*}
565 %destructor decl_type {free_decl_type($$);}
566 decl_type(type_) ::= decl_type_token(T). {
567 type_ = init_decl_type(T->type, T->text);
572 %type const_decl_type {decl_type*}
573 %destructor const_decl_type {free_decl_type($$);}
574 const_decl_type(type) ::= decl_type(type_). {
577 const_decl_type(type) ::= CONST decl_type(type_). {
582 %destructor impl {free_impl($$);}
583 impl(impl) ::= impl_func(func) LBRACE impl_stmts(stmts) RBRACE. {
584 impl = init_impl(func, stmts);
587 %type impl_func {impl_func*}
588 %destructor impl_func {free_impl_func($$);}
589 impl_func(func) ::= FUNCTION reference(r) NSNAME(NAME) impl_args(args) COLON impl_type(type). {
590 func = init_impl_func(NAME->text, args, type, r);
594 %token_class impl_def_val_token NULL NUMBER TRUE FALSE QUOTED_STRING.
595 %type impl_def_val {impl_def_val*}
596 %destructor impl_def_val {free_impl_def_val($$);}
597 impl_def_val(def) ::= impl_def_val_token(T). {
598 def = init_impl_def_val(T->type, T->text);
602 %type impl_var {impl_var*}
603 %destructor impl_var {free_impl_var($$);}
604 impl_var(var) ::= reference(r) DOLLAR_NAME(T). {
605 var = init_impl_var(T->text, r);
609 %type impl_arg {impl_arg*}
610 %destructor impl_arg {free_impl_arg($$);}
611 impl_arg(arg) ::= impl_type(type) impl_var(var). {
612 arg = init_impl_arg(type, var, NULL);
614 impl_arg(arg) ::= impl_type(type) impl_var(var) EQUALS impl_def_val(def). {
615 arg = init_impl_arg(type, var, def);
618 %type impl_args {impl_args*}
619 %destructor impl_args {free_impl_args($$);}
620 impl_args(args) ::= LPAREN RPAREN. {
623 impl_args(args) ::= LPAREN impl_arg_list(args_) RPAREN. {
626 impl_args(args) ::= LPAREN impl_arg_list(args_) COMMA impl_vararg(va) RPAREN. {
628 args->vararg.name = va;
631 %type impl_vararg {impl_arg*}
632 %destructor impl_vararg {free_impl_arg($$);}
633 impl_vararg(va) ::= impl_type(type) reference(r) ELLIPSIS DOLLAR_NAME(T). {
634 va = init_impl_arg(type, init_impl_var(T->text, r), NULL);
638 %type impl_arg_list {impl_args*}
639 %destructor impl_arg_list {free_impl_args($$);}
640 impl_arg_list(args) ::= impl_arg(arg). {
641 args = init_impl_args(arg);
643 impl_arg_list(args) ::= impl_arg_list(args_) COMMA impl_arg(arg). {
644 args = add_impl_arg(args_, arg);
647 %type impl_stmts {impl_stmts*}
648 %destructor impl_stmts {free_impl_stmts($$);}
649 impl_stmts(stmts) ::= impl_stmt(stmt). {
650 stmts = init_impl_stmts(stmt);
652 impl_stmts(stmts) ::= impl_stmts(stmts_) impl_stmt(stmt). {
653 stmts = add_impl_stmt(stmts_, stmt);
656 %type impl_stmt {impl_stmt*}
657 %destructor impl_stmt {free_impl_stmt($$);}
658 impl_stmt(stmt) ::= let_stmt(let). {
659 stmt = init_impl_stmt(PSI_T_LET, let);
661 impl_stmt(stmt) ::= set_stmt(set). {
662 stmt = init_impl_stmt(PSI_T_SET, set);
664 impl_stmt(stmt) ::= return_stmt(ret). {
665 stmt = init_impl_stmt(PSI_T_RETURN, ret);
667 impl_stmt(stmt) ::= free_stmt(free). {
668 stmt = init_impl_stmt(PSI_T_FREE, free);
671 %token_class num_exp_token NUMBER NSNAME.
672 %token_class num_exp_op_token PLUS MINUS ASTERISK SLASH.
673 %type num_exp {num_exp*}
674 %destructor num_exp {free_num_exp($$);}
675 num_exp(exp) ::= num_exp_token(tok). {
676 exp = init_num_exp(tok->type, tok->text);
679 num_exp(exp) ::= decl_var(var). {
680 exp = init_num_exp(PSI_T_NAME, var);
681 exp->token = PSI_TokenCopy(var->token);
683 num_exp(exp) ::= num_exp(exp_) num_exp_op_token(operator_) num_exp(operand_). {
684 exp_->operator = operator_->type;
685 exp_->operand = operand_;
690 %type let_stmt {let_stmt*}
691 %destructor let_stmt {free_let_stmt($$);}
692 let_stmt(let) ::= LET decl_var(var) EOS. {
693 let = init_let_stmt(var, init_let_val(PSI_LET_NULL, NULL));
695 let_stmt(let) ::= LET decl_var(var) EQUALS reference(r) let_val(val) EOS. {
696 val->flags.one.is_reference = r ? 1 : 0;
697 let = init_let_stmt(var, val);
699 let_stmt(let) ::= TEMP decl_var(var) EQUALS decl_var(val) EOS. {
700 let = init_let_stmt(var, init_let_val(PSI_LET_TMP, val));
703 %type let_calloc {let_calloc*}
704 %destructor let_calloc {free_let_calloc($$);}
705 let_calloc(alloc) ::= num_exp(nmemb) COMMA num_exp(size). {
706 alloc = init_let_calloc(nmemb, size);
708 %token_class let_func_token ZVAL OBJVAL ARRVAL PATHVAL STRLEN STRVAL FLOATVAL INTVAL BOOLVAL.
709 %type let_func {let_func*}
710 %destructor let_func {free_let_func($$);}
711 let_func(func) ::= let_func_token(T) LPAREN impl_var(var) RPAREN. {
712 func = init_let_func(T->type, T->text, var);
716 %type callback_arg_list {set_values *}
717 %destructor callback_arg_list {free_set_values($$);}
718 callback_arg_list ::= .
719 callback_arg_list(args) ::= callback_args(args_). {
723 %type callback_args {set_values *}
724 %destructor callback_args {free_set_values($$);}
725 callback_args(args) ::= set_value(val). {
726 args = init_set_values(val);
728 callback_args(args) ::= callback_args(args_) COMMA set_value(val). {
729 args = add_set_value(args_, val);
732 %type let_val {let_val*}
733 %destructor let_val {free_let_val($$);}
734 let_val(val) ::= NULL. {
735 val = init_let_val(PSI_LET_NULL, NULL);
737 let_val(val) ::= num_exp(exp). {
738 val = init_let_val(PSI_LET_NUMEXP, exp);
740 let_val(val) ::= CALLOC LPAREN let_calloc(alloc) RPAREN. {
741 val = init_let_val(PSI_LET_CALLOC, alloc);
743 let_val(val) ::= let_func(func). {
744 val = init_let_val(PSI_LET_FUNC, func);
746 let_val(val) ::= CALLBACK let_func_token(F) LPAREN impl_var(var) LPAREN callback_arg_list(args_) RPAREN RPAREN. {
747 val = init_let_val(PSI_LET_CALLBACK, init_let_callback(
748 init_let_func(F->type, F->text, var), args_));
752 %type set_stmt {set_stmt*}
753 %destructor set_stmt {free_set_stmt($$);}
754 set_stmt(set) ::= SET impl_var(var) EQUALS set_value(val) EOS. {
755 set = init_set_stmt(var, val);
758 %type set_value {set_value*}
759 %destructor set_value {free_set_value($$);}
760 set_value(val) ::= set_func(func) LPAREN decl_var(var) RPAREN. {
761 val = init_set_value(func, init_decl_vars(var));
763 set_value(val) ::= set_func(func) LPAREN decl_var(var) COMMA num_exp(num_) RPAREN. {
764 val = init_set_value(func, init_decl_vars(var));
767 set_value(val) ::= set_func(func_) LPAREN decl_var(var) COMMA ELLIPSIS(T) RPAREN. {
768 free_set_func(func_);
769 val = init_set_value(init_set_func(T->type, T->text), init_decl_vars(var));
770 val->func->token = T;
772 set_value(val) ::= set_func(func_) LPAREN decl_var(var) COMMA set_vals(vals) RPAREN. {
775 val->vars = init_decl_vars(var);
777 set_value(val) ::= set_func(func_) LPAREN decl_var(var) COMMA num_exp(num_) COMMA set_vals(vals) RPAREN. {
781 val->vars = init_decl_vars(var);
783 %type set_vals {set_value*}
784 %destructor set_vals {free_set_value($$);}
785 set_vals(vals) ::= set_value(val). {
786 vals = add_inner_set_value(init_set_value(NULL, NULL), val);
788 set_vals(vals) ::= set_vals(vals_) COMMA set_value(val). {
789 vals = add_inner_set_value(vals_, val);
792 %token_class set_func_token TO_OBJECT TO_ARRAY TO_STRING TO_INT TO_FLOAT TO_BOOL ZVAL VOID.
793 %type set_func {set_func*}
794 %destructor set_func {free_set_func($$);}
795 set_func(func) ::= set_func_token(T). {
796 func = init_set_func(T->type, T->text);
800 %type return_stmt {return_stmt*}
801 %destructor return_stmt {free_return_stmt($$);}
802 return_stmt(ret) ::= RETURN(T) set_value(val) EOS. {
803 ret = init_return_stmt(val);
807 %type free_stmt {free_stmt*}
808 %destructor free_stmt {free_free_stmt($$);}
809 free_stmt(free) ::= FREE free_calls(calls) EOS. {
810 free = init_free_stmt(calls);
813 %type free_calls {free_calls*}
814 %destructor free_calls {free_free_calls($$);}
815 free_calls(calls) ::= free_call(call). {
816 calls = init_free_calls(call);
818 free_calls(calls) ::= free_calls(calls_) COMMA free_call(call). {
819 calls = add_free_call(calls_, call);
822 %type free_call {free_call*}
823 %destructor free_call {free_free_call($$);}
824 free_call(call) ::= NAME(F) LPAREN decl_vars(vars) RPAREN. {
825 call = init_free_call(F->text, vars);
829 %token_class impl_type_token VOID MIXED BOOL INT FLOAT STRING ARRAY OBJECT CALLABLE.
830 %type impl_type {impl_type*}
831 %destructor impl_type {free_impl_type($$);}
832 impl_type(type_) ::= impl_type_token(T). {
833 type_ = init_impl_type(T->type, T->text);
837 %type reference {char}
838 reference(r) ::= . {r = 0;}
839 reference(r) ::= AMPERSAND. {r = 1;}
841 %type indirection {unsigned}
842 indirection(i) ::= . {i = 0;}
843 indirection(i) ::= pointers(p). {i = p;}
845 %type pointers {unsigned}
846 pointers(p) ::= ASTERISK. {p = 1;}
847 pointers(p) ::= pointers(P) ASTERISK. {p = P+1;}