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;
}
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);

View File

@ -17,6 +17,7 @@
double fval;
char* strval;
AST* ast;
ArgArr* argarr;
}
%define parse.error verbose
@ -40,6 +41,8 @@
%precedence NEG
%type<ast> exp;
%type<argarr> arg;
%type<argarr> 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 {

View File

@ -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