aboutsummaryrefslogtreecommitdiff
path: root/src/parser.y
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2023-03-25 21:14:13 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2023-03-25 21:14:35 +0200
commit542be69b2a89eb35f87e208018a7c0cc4c2aac04 (patch)
tree4dd510c5020c963e1be460be65c8c53104dcf49d /src/parser.y
parenteaf2d360120a4cab12c27ed51961cd5d224042ff (diff)
downloadek-542be69b2a89eb35f87e208018a7c0cc4c2aac04.tar.gz
ek-542be69b2a89eb35f87e208018a7c0cc4c2aac04.zip
add union to parser
Diffstat (limited to 'src/parser.y')
-rw-r--r--src/parser.y27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/parser.y b/src/parser.y
index cddfb2a..0132283 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -135,10 +135,10 @@
%nterm <node> func_sign variadic_sign type var_decl var
%nterm <node> var_init proc lambda template_elem template_list type_list
%nterm <node> type_alias type_template enum_val enum_list enum top unit id
-%nterm <node> embed param_decl union union_list union_elem struct struct_list
+%nterm <node> embed param_decl union struct struct_list struct_elem
%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
+%nterm <node> generic generic_list union_struct
%destructor {} FLOAT INT STRING ID
%destructor { destroy_ast_tree($$); } <*>
@@ -493,27 +493,22 @@ proc: id variadic_sign body {
}
;
-lambda: "[" macro_list "]" func_sign body { $$ = gen_lambda($2, $4, $5);
- }
+lambda: "[" macro_list "]" func_sign body { $$ = gen_lambda($2, $4, $5); }
;
-union_elem: union { $$ = $1; }
- | var_decl { $$ = $1; }
+struct_elem: var_decl { $$ = $1; }
;
-union_list: union_elem ";" union_list { $$ = $1; $1->next = $3; }
- | union_elem ";" { $$ = $1; }
+struct_list: struct_elem ";" struct_list { $$ = $1; $1->next = $3; }
+ | struct_elem ";" { $$ = $1; }
;
-union: "union" id "{" union_list "}" {
- $$ = gen_type(AST_TYPE_UNION, $2, $4, NULL);
+union: "union" id "{" struct_list "}" {
+ $$ = gen_union($2, NULL, $4);
+ }
+ | "union" id "(" generic_list ")" "{" struct_list "}" {
+ $$ = gen_union($2, $4, $7);
}
- | "union" "{" union_list "}" {
- $$ = gen_type(AST_TYPE_UNION, NULL, $3, NULL); }
- ;
-
-/* alias I guess, might try and name things better */
-struct_list: union_list { $$ = $1; }
;
generic: id type { $$ = gen_alias($1, $2); }