}
block ::= decl_typedef(def). {
P->defs = add_decl_typedef(P->defs, def);
+ if (def->type->strct) {
+ P->structs = add_decl_struct(P->structs, def->type->strct);
+ }
}
block ::= constant(constant). {
P->consts = add_constant(P->consts, constant);
}
+block ::= decl_struct(strct). {
+ P->structs = add_decl_struct(P->structs, strct);
+}
+
+%type decl_struct {decl_struct*}
+decl_struct(strct) ::= STRUCT NAME(N) LBRACE struct_args(args) RBRACE. {
+ strct = init_decl_struct(N->text, args);
+}
%type const_type {const_type*}
const_type(type_) ::= BOOL(T). {
}
%type decl_typedef {decl_typedef*}
-decl_typedef(def) ::= TYPEDEF NAME(ALIAS) decl_type(type) EOS. {
+decl_typedef(def) ::= TYPEDEF decl_type(type) NAME(ALIAS) EOS. {
def = init_decl_typedef(ALIAS->text, type);
free(ALIAS);
}
+decl_typedef(def) ::= TYPEDEF STRUCT(S) NAME(N) NAME(ALIAS) EOS. {
+ def = init_decl_typedef(ALIAS->text, init_decl_type(S->type, N->text));
+ free(ALIAS);
+ free(S);
+ free(N);
+}
+decl_typedef(def) ::= TYPEDEF decl_struct(s) NAME(ALIAS) EOS. {
+ def = init_decl_typedef(ALIAS->text, init_decl_type(PSI_T_STRUCT, s->name));
+ def->type->strct = s;
+ free(ALIAS);
+}
%type decl {decl*}
decl(decl) ::= decl_abi(abi) decl_arg(func) LPAREN decl_args(args) RPAREN EOS. {
free(T);
free(D);
}
-decl_var(var) ::= pointers(p) NAME(T) LBRACKET DIGITS(D) RBRACKET. {
+decl_var(var) ::= pointers(p) NAME(T) LBRACKET NUMBER(D) RBRACKET. {
var = init_decl_var(T->text, p+1, atol(D->text));
free(T);
free(D);
decl_args(args) ::= decl_args(args_) COMMA decl_arg(arg). {
args = add_decl_arg(args_, arg);
}
+%type struct_args {decl_args*}
+struct_args(args) ::= decl_arg(arg) EOS. {
+ args = init_decl_args(arg);
+}
+struct_args(args) ::= struct_args(args_) decl_arg(arg) EOS. {
+ args = add_decl_arg(args_, arg);
+}
%type decl_type {decl_type*}
decl_type(type_) ::= VOID(T). {
type_ = init_decl_type(T->type, T->text);
free(T);
}
+decl_type(type_) ::= SIZE_T(T). {
+ type_ = init_decl_type(T->type, T->text);
+ free(T);
+}
decl_type(type_) ::= SINT8(T). {
type_ = init_decl_type(T->type, T->text);
free(T);
}
%type let_stmt {let_stmt*}
+let_stmt(let) ::= LET decl_var(var) EOS. {
+ let = init_let_stmt(var, NULL);
+}
let_stmt(let) ::= LET decl_var(var) EQUALS let_value(val) EOS. {
let = init_let_stmt(var, val);
}
%type let_value {let_value*}
+let_value(val) ::= CALLOC(F) LPAREN NUMBER(N) COMMA decl_type(t) RPAREN. {
+ val = init_let_value(
+ init_let_func(F->type, F->text,
+ atol(N->text) * psi_t_size(real_decl_type(t)->type)
+ ), NULL, 0
+ );
+ free_decl_type(t);
+ free(F);
+ free(N);
+}
let_value(val) ::= let_func(func) LPAREN impl_var(var) RPAREN. {
val = init_let_value(func, var, 0);
}
%type let_func {let_func*}
let_func(func) ::= STRLEN(T). {
- func = init_let_func(T->type, T->text);
+ func = init_let_func(T->type, T->text, 0);
free(T);
}
let_func(func) ::= STRVAL(T). {
- func = init_let_func(T->type, T->text);
+ func = init_let_func(T->type, T->text, 0);
free(T);
}
let_func(func) ::= INTVAL(T). {
- func = init_let_func(T->type, T->text);
+ func = init_let_func(T->type, T->text, 0);
free(T);
}
let_func(func) ::= FLOATVAL(T). {
- func = init_let_func(T->type, T->text);
+ func = init_let_func(T->type, T->text, 0);
free(T);
}
let_func(func) ::= BOOLVAL(T). {
- func = init_let_func(T->type, T->text);
+ func = init_let_func(T->type, T->text, 0);
+ free(T);
+}
+let_func(func) ::= ARRVAL(T). {
+ func = init_let_func(T->type, T->text, 0);
free(T);
}
}
%type set_func {set_func*}
+set_func(func) ::= TO_ARRAY(T). {
+ func = init_set_func(T->type, T->text);
+ free(T);
+}
set_func(func) ::= TO_STRING(T). {
func = init_set_func(T->type, T->text);
free(T);