Fixed float addition.

One can now add floats, will also print the AST.
This commit is contained in:
Jacob Signorovitch 2024-12-21 10:12:30 -05:00
parent 8763fa35dd
commit 905acacd07
3 changed files with 7 additions and 11 deletions

View File

@ -8,13 +8,11 @@
extern AST* root; extern AST* root;
ASTNumData exec_expr(AST* ast) { ASTNumData exec_expr(AST* ast) {
ast_print(ast); // ast_print(ast);
log_dbg("Started execution."); log_dbg("Started execution.");
switch (ast->type) { switch (ast->type) {
case AST_TYPE_CALL: return exec_call(ast); case AST_TYPE_CALL: return exec_call(ast);
case AST_TYPE_NUM: case AST_TYPE_NUM: return *(ASTNumData*)ast->data;
exec_print(*(ASTNumData*)ast->data);
return *(ASTNumData*)ast->data;
default: printf("what\n"); default: printf("what\n");
} }
} }

View File

@ -37,10 +37,9 @@ input:
exp: exp:
NUM { $$ = ast_init(AST_TYPE_NUM, ast_num_data_init($1)); } NUM { $$ = ast_init(AST_TYPE_NUM, ast_num_data_init($1)); }
| NUM PLUS NUM { | NUM PLUS NUM {
AST* argv[2] = { AST** argv = calloc(2, sizeof(AST*));
ast_init(AST_TYPE_NUM, ast_num_data_init($1)), argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init($1));
ast_init(AST_TYPE_NUM, ast_num_data_init($3)) argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init($3));
};
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("+", 2, argv)); $$ = ast_init(AST_TYPE_CALL, ast_call_data_init("+", 2, argv));
} }

View File

@ -40,12 +40,11 @@ int main(int argc, char** argv) {
log_dbgf("cline: %s", ln->buf); log_dbgf("cline: %s", ln->buf);
if (ln->ln > 0) { if (ln->ln > 0) {
// I hope to god it's null-terminated.
inp = ln->buf; inp = ln->buf;
if (yyparse() == 0) printf("Parsed successfully!\n"); if (yyparse() == 0) printf("Parsed successfully!\n");
else printf("Parse error.\n"); else printf("Parse error.\n");
// exec_expr(root); exec_print(exec_expr(root));
ast_print(root); ast_print(root);
} }