diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-03-25 20:34:24 +0200 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-03-25 20:34:24 +0200 |
| commit | eaf2d360120a4cab12c27ed51961cd5d224042ff (patch) | |
| tree | 888b4715a1edf7ec74fed1bd26c31213c548650d /src/parser.y | |
| parent | 3bd9103ce0b18f6900ba544a8b2786145868524f (diff) | |
| download | ek-eaf2d360120a4cab12c27ed51961cd5d224042ff.tar.gz ek-eaf2d360120a4cab12c27ed51961cd5d224042ff.zip | |
initial constant struct stuff
Diffstat (limited to 'src/parser.y')
| -rw-r--r-- | src/parser.y | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/parser.y b/src/parser.y index 1b477d6..cddfb2a 100644 --- a/src/parser.y +++ b/src/parser.y @@ -138,6 +138,7 @@ %nterm <node> embed param_decl union union_list union_elem struct struct_list %nterm <node> top_if const_if const_for defer goto assign %nterm <node> struct_construct struct_inits struct_init cond +%nterm <node> generic generic_list %destructor {} FLOAT INT STRING ID %destructor { destroy_ast_tree($$); } <*> @@ -341,7 +342,10 @@ expr_list: expr "," expr_list { $$ = $1; $1->next = $3; } ; struct_init: init_expr { $$ = $1; } - | "." id "=" init_expr { $$ = gen_var($2, NULL, $4); } + | "." id "=" init_expr { + $$ = gen_var($2, NULL, $4); + ast_set_flags($$, AST_FLAG_MEMBER); + } ; struct_inits: struct_init "," struct_inits { $$ = $1; $1->next = $3; } @@ -512,10 +516,15 @@ union: "union" id "{" union_list "}" { struct_list: union_list { $$ = $1; } ; +generic: id type { $$ = gen_alias($1, $2); } +generic_list: generic "," generic_list { $$ = $1; $$->next = $3; } + | generic { $$ = $1; } + ; + struct: "struct" id "{" struct_list "}" { $$ = gen_struct($2, NULL, $4); } - | "struct" id "(" arg_list ")" "{" struct_list "}" { + | "struct" id "(" generic_list ")" "{" struct_list "}" { $$ = gen_struct($2, $4, $7); } ; |
