From 90b0d817fedfa5715b195e16da67fa6bdd67638e Mon Sep 17 00:00:00 2001 From: Kimplul Date: Mon, 29 Dec 2025 00:07:16 +0200 Subject: work towards a simple integer vector implementation + Hopefully shows that useful programs can be implemented with the rules present + Still missing at least external functions with non-void returns --- src/parser.y | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) (limited to 'src/parser.y') diff --git a/src/parser.y b/src/parser.y index 023c10a..9607e71 100644 --- a/src/parser.y +++ b/src/parser.y @@ -101,7 +101,7 @@ %nterm exprs statements closures trailing_closure %nterm opt_exprs opt_statements opt_trailing_closure %nterm rev_exprs rev_closures rev_statements -%nterm let if nil unop binop construct import +%nterm let put if nil unop binop construct import %nterm opt_vars vars rev_vars var %nterm opt_params params rev_params param @@ -113,12 +113,12 @@ %nterm opt_elements elements rev_elements element %nterm instance template supertemplate %nterm opt_constructions constructions construction -%nterm id impl forget assign +%nterm opt_deconstructions deconstructions deconstruction +%nterm id impl forget +%nterm explode %nterm type rev_types types opt_types - - %{ /** Modifies the signature of yylex to fit our parser better. */ @@ -262,10 +262,6 @@ unop type : ID { $$ = tgen_id($1, src_loc(@$)); } | "(" opt_types ")" { $$ = tgen_closure($2, src_loc(@$)); } - | "[" "]" type { - /* TODO static sizes? */ - $$ = tgen_arr($3, NULL, src_loc(@$)); - } | "&&" type { if ($2->k == TYPE_CLOSURE) { $$ = $2; $$->k = TYPE_PURE_CLOSURE; @@ -315,8 +311,21 @@ opt_constructions : constructions | { $$ = NULL; } +deconstruction + : ID "=>" var { + $$ = gen_deconstruction($1, $3, src_loc(@$)); + } + +deconstructions + : deconstructions "," deconstruction { $$ = $3; $$->n = $1; } + | deconstruction + +opt_deconstructions + : deconstructions + | { $$ = NULL; } + construct - : "(" opt_constructions ")" ID { + : "[" opt_constructions "]" ID { $$ = gen_construct($4, $2, src_loc(@$)); } @@ -325,8 +334,6 @@ id expr : "sizeof" "(" type ")" { $$ = gen_sizeof($3, src_loc(@$)); } - | expr "." ID { $$ = gen_dot($3, $1, src_loc(@$)); } - | expr "[" expr "]" { $$ = gen_arr($1, $3, src_loc(@$)); } | STRING { $$ = gen_const_str(strip($1), src_loc(@$)); } | FLOAT { $$ = gen_const_float($1, src_loc(@$)); } | BOOL { $$ = gen_const_bool($1, src_loc(@$)); } @@ -403,8 +410,18 @@ call $$ = gen_call($[expr], $[opt_exprs], src_loc(@$)); } +put + : put "*" { $$ = gen_put($1, src_loc(@$)); } + | id "*" { $$ = gen_put($1, src_loc(@$)); } + let : expr "=>" var ";" { $$ = gen_let($3, $1, src_loc(@$)); } + | expr "=>" put ";" { $$ = gen_write($3, $1, src_loc(@$)); } + +explode + : expr "=>" "[" opt_deconstructions "]" { + $$ = gen_explode($4, $1, src_loc(@$)); + } if : "if" expr body { $$ = gen_if($2, $3, NULL, src_loc(@$)); } @@ -413,6 +430,8 @@ if nil : "nil" expr body "=>" var ";" { + /** @todo should nil check define new scope for created + * variable? */ $$ = gen_nil_check($2, $3, $5, src_loc(@$)); } @@ -421,16 +440,11 @@ forget $$ = gen_forget($2, src_loc(@$)); } -assign - : expr "=" expr ";" { - $$ = gen_assign($1, $3, src_loc(@$)); - } - statement : call | forget - | assign | body + | explode | let | nil | if -- cgit v1.2.3