fela

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 14e0fde8f106434ed6189ab3a60231bce1b46b5c
parent f52ea1d2c118fdfd0306d38f610bb79cb9d4f66b
Author: thing1 <thing1@seacrossedlovers.xyz>
Date:   Mon, 27 Oct 2025 10:42:43 +0000

fixed the tree being backwards!

Diffstat:
Mfela.y | 26+++++++++++++++++++-------
Mgv.c | 2+-
Mtest.fe | 15+++++++++++++--
3 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/fela.y b/fela.y @@ -51,10 +51,15 @@ body : decs { body = $1; } ; decs : decs dec ';' { - $$ = alloczt(struct ast_decs); - $$->decs = $1; - $$->dec = $2; - + struct ast_decs *decs = $1, *prev = NULL; + $$ = decs; + while (decs) { + prev = decs; + decs = decs->decs; + } + decs = alloczt(struct ast_decs); + prev->decs = decs; + decs->dec = $2; } | dec ';' { $$ = alloczt(struct ast_decs); @@ -84,9 +89,16 @@ dec : type name { ; exprs : exprs expr ';' { - $$ = alloczt(struct ast_exprs); - $$->exprs = $1; - $$->expr = $2; + struct ast_exprs *exprs = $1, *prev = NULL; + $$ = exprs; + while (exprs) { + prev = exprs; + exprs = exprs->exprs; + } + exprs = alloczt(struct ast_exprs); + prev->exprs = exprs; + exprs->expr = $2; + } | expr ';' { $$ = alloczt(struct ast_exprs); diff --git a/gv.c b/gv.c @@ -6,7 +6,7 @@ void gv_expr(struct ast_expr *expr, int node, int parent) { switch (expr->op) { case VALUE: - printf("%d [label=\"Lit\\l\\n%d\\l\"]\n", node, expr->value); + printf("%d [label=\"Lit\\l\\n%ld\\l\"]\n", node, expr->value); break; } printf("%d -> %d [style=solid]\n", parent, node); diff --git a/test.fe b/test.fe @@ -1,3 +1,14 @@ -byte foo = 20; -int bar = 10; +int baz = func() { + bar(); +}; +int bar = func() { + return; +}; + +byte foo = func() { + byte a = 10; + + bar(); + baz(); +};