From 363188d7d6b0d5083541b6972714167786da7605 Mon Sep 17 00:00:00 2001 From: Jacob Signorovitch Date: Sat, 16 Nov 2024 10:00:40 -0500 Subject: [PATCH] The. --- src/ast.c | 2 +- src/grammar.y | 24 +++++++++++++----------- src/include/ast.h | 4 ++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/ast.c b/src/ast.c index 9f79725..f03ece0 100644 --- a/src/ast.c +++ b/src/ast.c @@ -10,7 +10,7 @@ static char* asttype_names[] = { }; #endif -ASTTypeNum* ast_type_num_init(AST* val) { +ASTTypeNum* ast_type_num_init(int val) { talloc(ASTTypeNum, num); num->val = val; diff --git a/src/grammar.y b/src/grammar.y index 8a191ff..8826a3d 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -1,8 +1,8 @@ %{ -#include "../../src/include/ast.h" -#include "../../src/include/lexer.h" -int yylex (void); -void yyerror (char const *); + #include "../../src/include/ast.h" + #include "../../src/include/lexer.h" + int yylex(void); + void yyerror(char const*); %} %code requires { @@ -15,16 +15,18 @@ void yyerror (char const *); AST* ast; } -%token NUM -%token CALL +%token NUM +%token CALL %token PLUS -%type exp +%type exp %% -exp: - NUM { $$ = ast_type_num_init($1); } - | NUM PLUS NUM { AST* argv[2] = {ast_type_num_init($1), ast_type_num_init($1)}; $$ = ast_type_call_init("+", 2, argv);} - ; +exp: + NUM { $$ = ast_type_num_init($1); } + | NUM PLUS NUM { + AST* argv[2] = {ast_type_num_init($1), ast_type_num_init($1)}; + $$ = ast_type_call_init("+", 2, argv); + }; %% diff --git a/src/include/ast.h b/src/include/ast.h index 538be3c..f1051c9 100644 --- a/src/include/ast.h +++ b/src/include/ast.h @@ -18,10 +18,10 @@ AST* ast_init(ASTType type, void* data); void ast_destroy(AST* ast); typedef struct { - AST* val; + int val; } ASTTypeNum; -ASTTypeNum* ast_type_num_init(AST* val); +ASTTypeNum* ast_type_num_init(int val); void ast_type_num_destroy(ASTTypeNum* num); typedef struct {