X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Fparser_proc.y;h=59477baf28ef2ac830a96c61b32d0ec36b900377;hp=3dc06e28bff2a0e7a631465283d8081e664377c7;hb=212ce3b6a4e70e1fce26d022822228700f3e80b2;hpb=be3ceffdd27422aae6ba44d31d868fb12d08957a diff --git a/src/parser_proc.y b/src/parser_proc.y index 3dc06e2..59477ba 100644 --- a/src/parser_proc.y +++ b/src/parser_proc.y @@ -11,6 +11,7 @@ %token_prefix PSI_T_ %token_type {PSI_Token *} %token_destructor {free($$);} +%default_destructor {(void)P;} %extra_argument {PSI_Parser *P} /* TOKEN is defined inside syntax_error */ %syntax_error { @@ -41,13 +42,61 @@ block ::= impl(impl). { } 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_ = init_const_type(T->type, T->text); + free(T); +} +const_type(type_) ::= INT(T). { + type_ = init_const_type(T->type, T->text); + free(T); +} +const_type(type_) ::= FLOAT(T). { + type_ = init_const_type(T->type, T->text); + free(T); +} +const_type(type_) ::= STRING(T). { + type_ = init_const_type(T->type, T->text); + free(T); +} +%type constant {constant*} +constant(constant) ::= CONST const_type(type) NSNAME(T) EQUALS impl_def_val(val) EOS. { + constant = init_constant(type, T->text, val); + free(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. { @@ -57,17 +106,28 @@ decl(decl) ::= decl_abi(abi) decl_arg(func) LPAREN decl_args(args) RPAREN EOS. { %type decl_abi {decl_abi*} decl_abi(abi) ::= NAME(T). { abi = init_decl_abi(T->text); + free(T); } %type decl_var {decl_var*} decl_var(var) ::= NAME(T). { - var = init_decl_var(T->text, 0); + var = init_decl_var(T->text, 0, 0); free(T); } decl_var(var) ::= pointers(p) NAME(T). { - var = init_decl_var(T->text, p); + var = init_decl_var(T->text, p, 0); free(T); } +decl_var(var) ::= NAME(T) LBRACKET NUMBER(D) RBRACKET. { + var = init_decl_var(T->text, 1, atol(D->text)); + free(T); + free(D); +} +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); +} %type decl_vars {decl_vars*} decl_vars(vars) ::= decl_var(var). { @@ -90,6 +150,13 @@ decl_args(args) ::= decl_arg(arg). { 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). { @@ -120,6 +187,10 @@ decl_type(type_) ::= DOUBLE(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); @@ -158,6 +229,7 @@ decl_type(type_) ::= NAME(T). { } %type impl {impl*} +%destructor impl {free_impl($$);} impl(impl) ::= impl_func(func) LBRACE impl_stmts(stmts) RBRACE. { impl = init_impl(func, stmts); } @@ -175,18 +247,23 @@ impl_func(func) ::= FUNCTION REFERENCE NSNAME(NAME) impl_args(args) COLON impl_t %type impl_def_val {impl_def_val*} impl_def_val(def) ::= NULL(T). { def = init_impl_def_val(T); + free(T); } impl_def_val(def) ::= NUMBER(T). { def = init_impl_def_val(T); + free(T); } impl_def_val(def) ::= TRUE(T). { def = init_impl_def_val(T); + free(T); } impl_def_val(def) ::= FALSE(T). { def = init_impl_def_val(T); + free(T); } impl_def_val(def) ::= QUOTED_STRING(T). { def = init_impl_def_val(T); + free(T); } %type impl_var {impl_var*} @@ -223,6 +300,7 @@ impl_arg_list(args) ::= impl_arg_list(args_) COMMA impl_arg(arg). { } %type impl_stmts {impl_stmts*} +%destructor impl_stmts {free_impl_stmts($$);} impl_stmts(stmts) ::= impl_stmt(stmt). { stmts = init_impl_stmts(stmt); } @@ -231,6 +309,7 @@ impl_stmts(stmts) ::= impl_stmts(stmts_) impl_stmt(stmt). { } %type impl_stmt {impl_stmt*} +%destructor impl_stmt {free_impl_stmt($$);} impl_stmt(stmt) ::= let_stmt(let). { stmt = init_impl_stmt(PSI_T_LET, let); } @@ -245,11 +324,24 @@ impl_stmt(stmt) ::= free_stmt(free). { } %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); } @@ -265,23 +357,23 @@ let_value(val) ::= NULL. { %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); } @@ -296,6 +388,10 @@ set_value(val) ::= set_func(func) LPAREN decl_vars(vars) RPAREN. { } %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);