diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-12-29 00:07:16 +0200 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2026-01-06 17:19:52 +0200 |
| commit | c7b41b47d038fd4973da05224b7aa29efaae1784 (patch) | |
| tree | ad439ff996aa5121bced46bdb7e42eb419702be0 /src/parser.y | |
| parent | d501b2c9ebab6f5b90c808ea0e5fde912818707d (diff) | |
| download | fwd-c7b41b47d038fd4973da05224b7aa29efaae1784.tar.gz fwd-c7b41b47d038fd4973da05224b7aa29efaae1784.zip | |
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
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 |
