From 1e11b5921d0338aa335c59ef53c091daf924e707 Mon Sep 17 00:00:00 2001 From: Jacob Date: Sat, 18 Jan 2025 09:42:28 -0500 Subject: [PATCH] It all works! (except for mem leaks) --- src/ast.c | 6 ++++++ src/dstr.c | 2 +- src/grammar.y | 29 ++++++++++++++++++++++------- src/include/ast.h | 4 ++-- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/ast.c b/src/ast.c index 9956721..ceec0a2 100644 --- a/src/ast.c +++ b/src/ast.c @@ -103,6 +103,12 @@ void ast_call_print(ASTCallData* data, int i) { INDENT_END; } +ASTVrefData* ast_vref_data_init(char* to) { + +} + +void ast_vref_data_destroy(ASTVrefData* vref) {} + void ast_vref_print(ASTVrefData* data, int i) { INDENT_BEGIN(i); diff --git a/src/dstr.c b/src/dstr.c index a65cb95..f78919c 100644 --- a/src/dstr.c +++ b/src/dstr.c @@ -12,7 +12,7 @@ Dstr* dstr_init(void) { dstr->buf = malloc(DSTR_INITSZ); *dstr->buf = '\0'; dstr->ln = 0; - + return dstr; } diff --git a/src/grammar.y b/src/grammar.y index cc46167..84694bc 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -17,6 +17,7 @@ double fval; char* strval; AST* ast; + ArgArr* argarr; } %define parse.error verbose @@ -40,6 +41,8 @@ %precedence NEG %type exp; +%type arg; +%type argstart; %% @@ -48,6 +51,23 @@ input: | exp { root = $1; } ; + +argstart: + exp { + ArgArr* argarr = argarr_init(); + argarr_add(argarr, $1); + $$ = argarr; + } + ; + +arg: + argstart { $$ = $1; } + | arg SEP exp { + argarr_add($1, $3); + $$ = $1; + } + ; + exp: NUM { $$ = ast_init(AST_TYPE_NUM, ast_num_data_init($1)); } @@ -63,13 +83,8 @@ exp: // Variable reference. //| WORD - // Function call. - // name(thing, thing) - | WORD LGROUP exp SEP exp RGROUP { - AST** argv = calloc(2, sizeof(AST*)); - argv[0] = $3; - argv[1] = $5; - $$ = ast_init(AST_TYPE_CALL, ast_call_data_init($1, 2, argv)); + | WORD LGROUP arg RGROUP { + $$ = ast_init(AST_TYPE_CALL, ast_call_data_init($1, $3->ln, $3->buf)); } | exp PLUS exp { diff --git a/src/include/ast.h b/src/include/ast.h index 3c5dd93..7ecbf97 100644 --- a/src/include/ast.h +++ b/src/include/ast.h @@ -40,8 +40,8 @@ typedef struct { char* to; // What the reference's to. } ASTVrefData; -ASTCallData* ast_vref_data_init(char* to); -void ast_vref_data_destroy(ASTCallData* call); +ASTVrefData* ast_vref_data_init(char* to); +void ast_vref_data_destroy(ASTVrefData* call); void ast_vref_print(ASTVrefData*, int i); #endif