commit 06ea4b80b2ded074148bf4dad8c03b2a680d89ed
parent 05071072441230e13cdb46e48a02a02642e961e6
Author: thing1 <thing1@seacrossedlovers.xyz>
Date: Wed, 22 Oct 2025 13:47:17 +0100
started work on making graphs
Diffstat:
4 files changed, 37 insertions(+), 14 deletions(-)
diff --git a/ast.h b/ast.h
@@ -37,7 +37,7 @@ struct ast_exprs {
struct ast_dec {
- char *name;
+ char *name, *type;
struct ast_expr *value;
};
diff --git a/fela.y b/fela.y
@@ -8,6 +8,7 @@
#define YYDEBUG 1
extern char *yytext;
+extern int yyleng;
extern int yylex();
int yyerror(const char *);
struct ast_decs *body;
@@ -34,6 +35,7 @@ struct ast_decs *body;
%type <exprs> exprs
%type <dec> dec
%type <decs> decs
+%type <s> name
%left '+' '-'
@@ -58,19 +60,22 @@ decs : decs dec ';' {
;
-dec : NAME NAME {
+dec : name name {
$$ = alloczt(struct ast_dec);
- $$->name = strslice($2, yylen);
+ $$->name = $2;
+ $$->type = $1;
}
- | NAME NAME '=' expr {
+ | name name '=' expr {
$$ = alloczt(struct ast_dec);
- $$->name = strslice($2, yylen);
+ $$->name = $2;
$$->value = $4;
+ $$->type = $1;
}
- | NAME NAME '=' func {
+ | name name '=' func {
$$ = alloczt(struct ast_dec);
- $$->name = strslice($2, yylen);
+ $$->name = $2;
$$->value = $4;
+ $$->type = $1;
}
;
@@ -99,11 +104,11 @@ func : FUNC '(' ')' '{' exprs '}' {
}
;
-expr : NAME '=' expr {
+expr : name '=' expr {
$$ = alloczt(struct ast_expr);
$$->op = ADD;
$$->children = allocztn(struct ast_expr, 2);
- $$->fn = strslice($1, yylen);
+ $$->fn = $1;
$$->children[0] = *$3;
}
| expr '+' expr {
@@ -146,17 +151,21 @@ expr : NAME '=' expr {
$$->op = VALUE;
$$->value = $1;
}
- | NAME {
+ | name {
$$ = alloczt(struct ast_expr);
$$->op = VAR;
- $$->fn = strslice($1, yylen);
+ $$->fn = $1;
}
- | NAME '(' ')' {
+ | name '(' ')' {
$$ = alloczt(struct ast_expr);
$$->op = FUNC;
- $$->fn = strslice($1, yylen);
+ $$->fn = $1;
}
;
+
+name : NAME {
+ $$ = strslice($1, yyleng);
+ }
%%
int
@@ -168,4 +177,5 @@ yyerror(const char *msg) {
int
main() {
yyparse();
+ printf("%s\n", body->dec->type);
}
diff --git a/gv.c b/gv.c
@@ -0,0 +1,13 @@
+#include <stdio.h>
+
+#include "ast.h"
+
+void
+gv(struct ast_decs *body, int node, int parent) {
+ if (parent != -1)
+ printf("%d -> %d [style=solid]\n", parent, node);
+ printf("%d ", node);
+ printf("[label=\"dec\"\n\l type: %s, name: %s\l", body->dec->type,
+ body->dec->name);
+ // if statment to deside if its a function or an expression
+}
diff --git a/test.fe b/test.fe
@@ -1,4 +1,4 @@
-byte num = func() {
+byte num=func() {
int a = 0;
rand();
};