Compare commits
No commits in common. "3fcffc81add050c4e6c4c5f1bd722b0015c99e31" and "c94d7863a73ad7f4620ac4cf1f249bceb65b5eef" have entirely different histories.
3fcffc81ad
...
c94d7863a7
14
src/ast.c
14
src/ast.c
@ -27,7 +27,6 @@ void ast_destroy(AST* ast) {
|
|||||||
switch (ast->type) {
|
switch (ast->type) {
|
||||||
case AST_TYPE_NUM: ast_num_data_destroy(ast->data); break;
|
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_CALL: ast_call_data_destroy(ast->data); break;
|
||||||
case AST_TYPE_VREF: ast_vref_data_destroy(ast->data); break;
|
|
||||||
default:
|
default:
|
||||||
log_dbgf("Unknown ast type %d (max: %d)", ast->type, AST_TYPE_MAX);
|
log_dbgf("Unknown ast type %d (max: %d)", ast->type, AST_TYPE_MAX);
|
||||||
}
|
}
|
||||||
@ -104,18 +103,9 @@ void ast_call_print(ASTCallData* data, int i) {
|
|||||||
INDENT_END;
|
INDENT_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASTVrefData* ast_vref_data_init(char* to) {
|
ASTVrefData* ast_vref_data_init(char* to) {}
|
||||||
talloc(ASTVrefData, vref);
|
|
||||||
|
|
||||||
vref->to = to;
|
void ast_vref_data_destroy(ASTVrefData* vref) {}
|
||||||
|
|
||||||
return vref;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ast_vref_data_destroy(ASTVrefData* vref) {
|
|
||||||
free(vref->to);
|
|
||||||
free(vref);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ast_vref_print(ASTVrefData* data, int i) {
|
void ast_vref_print(ASTVrefData* data, int i) {
|
||||||
INDENT_BEGIN(i);
|
INDENT_BEGIN(i);
|
||||||
|
@ -13,7 +13,6 @@ ASTNumData exec_exp(AST* ast) {
|
|||||||
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: return *(ASTNumData*)ast->data;
|
case AST_TYPE_NUM: return *(ASTNumData*)ast->data;
|
||||||
case AST_TYPE_VREF: return exec_vref(ast);
|
|
||||||
default: printf("what\n");
|
default: printf("what\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -68,8 +67,4 @@ ASTNumData exec_call(AST* ast) {
|
|||||||
return -1000;
|
return -1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASTNumData exec_vref(AST* ast) {
|
|
||||||
return *ast_num_data_init(42.42);
|
|
||||||
}
|
|
||||||
|
|
||||||
void exec_print(double n) { printf("= %lf\n", n); }
|
void exec_print(double n) { printf("= %lf\n", n); }
|
||||||
|
@ -27,8 +27,6 @@
|
|||||||
%token RGROUP
|
%token RGROUP
|
||||||
%token SEP
|
%token SEP
|
||||||
|
|
||||||
%token EXPSEP
|
|
||||||
|
|
||||||
%token<strval> WORD
|
%token<strval> WORD
|
||||||
%token<fval> NUM
|
%token<fval> NUM
|
||||||
|
|
||||||
@ -52,7 +50,6 @@
|
|||||||
input:
|
input:
|
||||||
%empty
|
%empty
|
||||||
| exp { root = $1; }
|
| exp { root = $1; }
|
||||||
| input EXPSEP exp { root = $3; }
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
@ -87,9 +84,7 @@ exp:
|
|||||||
| LGROUP exp RGROUP { $$ = $2; }
|
| LGROUP exp RGROUP { $$ = $2; }
|
||||||
|
|
||||||
// Variable reference.
|
// Variable reference.
|
||||||
| WORD {
|
//| WORD
|
||||||
$$ = ast_init(AST_TYPE_VREF, ast_vref_data_init($1));
|
|
||||||
}
|
|
||||||
|
|
||||||
| WORD LGROUP arg RGROUP {
|
| WORD LGROUP arg RGROUP {
|
||||||
size_t argc = $3->ln;
|
size_t argc = $3->ln;
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
ASTNumData exec_exp(AST* ast);
|
ASTNumData exec_exp(AST* ast);
|
||||||
ASTNumData exec_call(AST* ast);
|
ASTNumData exec_call(AST* ast);
|
||||||
ASTNumData exec_vref(AST* ast);
|
|
||||||
void exec_print(double n);
|
void exec_print(double n);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -112,7 +112,6 @@ int yylex() {
|
|||||||
case '(': return LGROUP;
|
case '(': return LGROUP;
|
||||||
case ')': return RGROUP;
|
case ')': return RGROUP;
|
||||||
case ',': return SEP;
|
case ',': return SEP;
|
||||||
case ';': return EXPSEP;
|
|
||||||
default: fprintf(stderr, "Unexpected character: %c\n", c);
|
default: fprintf(stderr, "Unexpected character: %c\n", c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,16 +82,3 @@ bin() { ./scl.out $1 | tail -n1; }
|
|||||||
run bin "-(-(1+2)*3)"
|
run bin "-(-(1+2)*3)"
|
||||||
[ "$output" = "= 9.000000" ]
|
[ "$output" = "= 9.000000" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "multiple expressions per line" {
|
|
||||||
run bin "1+1;2"
|
|
||||||
[ "$output" = "= 2.000000" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "variable definition" {
|
|
||||||
run bin "x = 1"
|
|
||||||
[ "$output" = "= 1.000000" ]
|
|
||||||
|
|
||||||
run bin "x = 1; x + 1"
|
|
||||||
[ "$output" = "= 2.000000" ]
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user