diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-12-29 00:07:16 +0200 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-12-29 00:07:16 +0200 |
| commit | 90b0d817fedfa5715b195e16da67fa6bdd67638e (patch) | |
| tree | de5c01884a434ffcc940be2e96474f188c95362c /src/parser.y | |
| parent | 0e0c41af58a0f4ec5a39ce77822de71e5523fcba (diff) | |
| download | fwd-90b0d817fedfa5715b195e16da67fa6bdd67638e.tar.gz fwd-90b0d817fedfa5715b195e16da67fa6bdd67638e.zip | |
work towards a simple integer vector implementationgnc
+ Hopefully shows that useful programs can be implemented with
the rules present
+ Still missing at least external functions with non-void returns
Diffstat (limited to 'src/parser.y')
| -rw-r--r-- | src/parser.y | 48 |
1 files changed, 31 insertions, 17 deletions
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 <node> exprs statements closures trailing_closure %nterm <node> opt_exprs opt_statements opt_trailing_closure %nterm <node> rev_exprs rev_closures rev_statements -%nterm <node> let if nil unop binop construct import +%nterm <node> let put if nil unop binop construct import %nterm <node> opt_vars vars rev_vars var %nterm <node> opt_params params rev_params param @@ -113,12 +113,12 @@ %nterm <node> opt_elements elements rev_elements element %nterm <node> instance template supertemplate %nterm <node> opt_constructions constructions construction -%nterm <node> id impl forget assign +%nterm <node> opt_deconstructions deconstructions deconstruction +%nterm <node> id impl forget +%nterm <node> explode %nterm <type> 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 |
