Added initial support for variables.
They are now parsed correctly, though they cannot be defined manually and all have a value of 42.42.
This commit is contained in:
parent
3ab2696705
commit
8b01407374
14
src/ast.c
14
src/ast.c
@ -27,6 +27,7 @@ void ast_destroy(AST* ast) {
|
||||
switch (ast->type) {
|
||||
case AST_TYPE_NUM: ast_num_data_destroy(ast->data); break;
|
||||
case AST_TYPE_CALL: ast_call_data_destroy(ast->data); break;
|
||||
case AST_TYPE_VREF: ast_vref_data_destroy(ast->data); break;
|
||||
default:
|
||||
log_dbgf("Unknown ast type %d (max: %d)", ast->type, AST_TYPE_MAX);
|
||||
}
|
||||
@ -103,9 +104,18 @@ void ast_call_print(ASTCallData* data, int i) {
|
||||
INDENT_END;
|
||||
}
|
||||
|
||||
ASTVrefData* ast_vref_data_init(char* to) {}
|
||||
ASTVrefData* ast_vref_data_init(char* to) {
|
||||
talloc(ASTVrefData, vref);
|
||||
|
||||
void ast_vref_data_destroy(ASTVrefData* vref) {}
|
||||
vref->to = to;
|
||||
|
||||
return vref;
|
||||
}
|
||||
|
||||
void ast_vref_data_destroy(ASTVrefData* vref) {
|
||||
free(vref->to);
|
||||
free(vref);
|
||||
}
|
||||
|
||||
void ast_vref_print(ASTVrefData* data, int i) {
|
||||
INDENT_BEGIN(i);
|
||||
|
@ -13,6 +13,7 @@ ASTNumData exec_exp(AST* ast) {
|
||||
switch (ast->type) {
|
||||
case AST_TYPE_CALL: return exec_call(ast);
|
||||
case AST_TYPE_NUM: return *(ASTNumData*)ast->data;
|
||||
case AST_TYPE_VREF: return exec_vref(ast);
|
||||
default: printf("what\n");
|
||||
exit(1);
|
||||
}
|
||||
@ -67,4 +68,8 @@ ASTNumData exec_call(AST* ast) {
|
||||
return -1000;
|
||||
}
|
||||
|
||||
ASTNumData exec_vref(AST* ast) {
|
||||
return *ast_num_data_init(42.42);
|
||||
}
|
||||
|
||||
void exec_print(double n) { printf("= %lf\n", n); }
|
||||
|
@ -84,7 +84,9 @@ exp:
|
||||
| LGROUP exp RGROUP { $$ = $2; }
|
||||
|
||||
// Variable reference.
|
||||
//| WORD
|
||||
| WORD {
|
||||
$$ = ast_init(AST_TYPE_VREF, ast_vref_data_init($1));
|
||||
}
|
||||
|
||||
| WORD LGROUP arg RGROUP {
|
||||
size_t argc = $3->ln;
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
ASTNumData exec_exp(AST* ast);
|
||||
ASTNumData exec_call(AST* ast);
|
||||
ASTNumData exec_vref(AST* ast);
|
||||
void exec_print(double n);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user