Nothing works.
This commit is contained in:
parent
6fff5e5cc8
commit
ec268f6047
12
src/ast.c
12
src/ast.c
@ -1,8 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "include/ast.h"
|
||||
#include "include/util.h"
|
||||
#include "include/dstr.h"
|
||||
#include "include/util.h"
|
||||
|
||||
extern AST* root;
|
||||
|
||||
@ -30,9 +30,7 @@ void ast_destroy(AST* ast) {
|
||||
}
|
||||
}
|
||||
|
||||
void ast_print(AST* ast) {
|
||||
ast_print_i(ast, 0);
|
||||
}
|
||||
void ast_print(AST* ast) { ast_print_i(ast, 0); }
|
||||
|
||||
void ast_print_i(AST* ast, int i) {
|
||||
INDENT_BEGIN(i);
|
||||
@ -41,8 +39,10 @@ void ast_print_i(AST* ast, int i) {
|
||||
INDENT_FIELD("type", "%s", asttype_names[ast->type]);
|
||||
INDENT_FIELD_EXT_NONL_START("data");
|
||||
switch (ast->type) {
|
||||
case AST_TYPE_NUM: ast_num_print(ast->data, i + 1); break;
|
||||
case AST_TYPE_CALL: ast_call_print(ast->data, i + 1); break;
|
||||
case AST_TYPE_NUM:
|
||||
printf("%s %lf\n", INDENT_spacing->buf, *(ASTNumData*)ast->data);
|
||||
break;
|
||||
case AST_TYPE_CALL: ast_call_print(ast->data, i + 2); break;
|
||||
default: exit(1);
|
||||
}
|
||||
INDENT_FIELD_NONL_END;
|
||||
|
@ -36,13 +36,20 @@ input:
|
||||
|
||||
exp:
|
||||
NUM { $$ = ast_init(AST_TYPE_NUM, ast_num_data_init($1)); }
|
||||
| NUM PLUS exp {
|
||||
| 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_init(AST_TYPE_CALL, ast_call_data_init("+", 2, argv));
|
||||
}
|
||||
/*| NUM PLUS exp {
|
||||
AST* argv[2] = {
|
||||
ast_init(AST_TYPE_NUM, ast_num_data_init($1)),
|
||||
$3
|
||||
};
|
||||
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("+", 2, argv));
|
||||
}/*
|
||||
}
|
||||
| exp PLUS exp {
|
||||
AST* argv[2] = { $1, $3 };
|
||||
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("+", 2, argv));
|
||||
|
@ -50,7 +50,7 @@
|
||||
|
||||
// Print & indent the title of a section.
|
||||
#define INDENT_TITLE(THING, WHERE) \
|
||||
printf("%s" COL_BCYA THING " @ %p\n" COL_RESET, INDENT_spacing->buf, WHERE);
|
||||
printf("%s" COL_BCYA THING COL_RESET " @" COL_MAG " %p\n" COL_RESET, INDENT_spacing->buf, WHERE);
|
||||
|
||||
// Print & indent a thing.
|
||||
#define INDENT_FIELD(FIELD, VAL, ...) \
|
||||
|
Loading…
x
Reference in New Issue
Block a user