Fixed float addition.
One can now add floats, will also print the AST.
This commit is contained in:
parent
8763fa35dd
commit
905acacd07
@ -8,13 +8,11 @@
|
||||
extern AST* root;
|
||||
|
||||
ASTNumData exec_expr(AST* ast) {
|
||||
ast_print(ast);
|
||||
// ast_print(ast);
|
||||
log_dbg("Started execution.");
|
||||
switch (ast->type) {
|
||||
case AST_TYPE_CALL: return exec_call(ast);
|
||||
case AST_TYPE_NUM:
|
||||
exec_print(*(ASTNumData*)ast->data);
|
||||
return *(ASTNumData*)ast->data;
|
||||
case AST_TYPE_NUM: return *(ASTNumData*)ast->data;
|
||||
default: printf("what\n");
|
||||
}
|
||||
}
|
||||
|
@ -37,10 +37,9 @@ input:
|
||||
exp:
|
||||
NUM { $$ = ast_init(AST_TYPE_NUM, ast_num_data_init($1)); }
|
||||
| NUM PLUS NUM {
|
||||
AST* argv[2] = {
|
||||
ast_init(AST_TYPE_NUM, ast_num_data_init($1)),
|
||||
ast_init(AST_TYPE_NUM, ast_num_data_init($3))
|
||||
};
|
||||
AST** argv = calloc(2, sizeof(AST*));
|
||||
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init($1));
|
||||
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init($3));
|
||||
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("+", 2, argv));
|
||||
}
|
||||
|
||||
|
@ -40,12 +40,11 @@ int main(int argc, char** argv) {
|
||||
log_dbgf("cline: %s", ln->buf);
|
||||
|
||||
if (ln->ln > 0) {
|
||||
// I hope to god it's null-terminated.
|
||||
inp = ln->buf;
|
||||
if (yyparse() == 0) printf("Parsed successfully!\n");
|
||||
else printf("Parse error.\n");
|
||||
|
||||
// exec_expr(root);
|
||||
exec_print(exec_expr(root));
|
||||
ast_print(root);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user