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