This commit is contained in:
Jacob Signorovitch 2024-11-16 10:00:40 -05:00
parent 139d6fcb22
commit 363188d7d6
3 changed files with 16 additions and 14 deletions

View File

@ -10,7 +10,7 @@ static char* asttype_names[] = {
}; };
#endif #endif
ASTTypeNum* ast_type_num_init(AST* val) { ASTTypeNum* ast_type_num_init(int val) {
talloc(ASTTypeNum, num); talloc(ASTTypeNum, num);
num->val = val; num->val = val;

View File

@ -1,8 +1,8 @@
%{ %{
#include "../../src/include/ast.h" #include "../../src/include/ast.h"
#include "../../src/include/lexer.h" #include "../../src/include/lexer.h"
int yylex (void); int yylex(void);
void yyerror (char const *); void yyerror(char const*);
%} %}
%code requires { %code requires {
@ -15,16 +15,18 @@ void yyerror (char const *);
AST* ast; AST* ast;
} }
%token <intval> NUM %token<intval> NUM
%token <strval> CALL %token<strval> CALL
%token PLUS %token PLUS
%type <ast> exp %type<ast> exp
%% %%
exp: exp:
NUM { $$ = ast_type_num_init($1); } 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);} | NUM PLUS NUM {
; AST* argv[2] = {ast_type_num_init($1), ast_type_num_init($1)};
$$ = ast_type_call_init("+", 2, argv);
};
%% %%

View File

@ -18,10 +18,10 @@ AST* ast_init(ASTType type, void* data);
void ast_destroy(AST* ast); void ast_destroy(AST* ast);
typedef struct { typedef struct {
AST* val; int val;
} ASTTypeNum; } ASTTypeNum;
ASTTypeNum* ast_type_num_init(AST* val); ASTTypeNum* ast_type_num_init(int val);
void ast_type_num_destroy(ASTTypeNum* num); void ast_type_num_destroy(ASTTypeNum* num);
typedef struct { typedef struct {