It all works! (except for mem leaks)

This commit is contained in:
Jacob Signorovitch 2025-01-18 09:42:28 -05:00
parent 7343c3b9d9
commit 1e11b5921d
4 changed files with 31 additions and 10 deletions

View File

@ -103,6 +103,12 @@ void ast_call_print(ASTCallData* data, int i) {
INDENT_END; INDENT_END;
} }
ASTVrefData* ast_vref_data_init(char* to) {
}
void ast_vref_data_destroy(ASTVrefData* vref) {}
void ast_vref_print(ASTVrefData* data, int i) { void ast_vref_print(ASTVrefData* data, int i) {
INDENT_BEGIN(i); INDENT_BEGIN(i);

View File

@ -17,6 +17,7 @@
double fval; double fval;
char* strval; char* strval;
AST* ast; AST* ast;
ArgArr* argarr;
} }
%define parse.error verbose %define parse.error verbose
@ -40,6 +41,8 @@
%precedence NEG %precedence NEG
%type<ast> exp; %type<ast> exp;
%type<argarr> arg;
%type<argarr> argstart;
%% %%
@ -48,6 +51,23 @@ input:
| exp { root = $1; } | 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: exp:
NUM { $$ = ast_init(AST_TYPE_NUM, ast_num_data_init($1)); } NUM { $$ = ast_init(AST_TYPE_NUM, ast_num_data_init($1)); }
@ -63,13 +83,8 @@ exp:
// Variable reference. // Variable reference.
//| WORD //| WORD
// Function call. | WORD LGROUP arg RGROUP {
// name(thing, thing) $$ = ast_init(AST_TYPE_CALL, ast_call_data_init($1, $3->ln, $3->buf));
| 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));
} }
| exp PLUS exp { | exp PLUS exp {

View File

@ -40,8 +40,8 @@ typedef struct {
char* to; // What the reference's to. char* to; // What the reference's to.
} ASTVrefData; } ASTVrefData;
ASTCallData* ast_vref_data_init(char* to); ASTVrefData* ast_vref_data_init(char* to);
void ast_vref_data_destroy(ASTCallData* call); void ast_vref_data_destroy(ASTVrefData* call);
void ast_vref_print(ASTVrefData*, int i); void ast_vref_print(ASTVrefData*, int i);
#endif #endif