The.
This commit is contained in:
parent
139d6fcb22
commit
363188d7d6
@ -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;
|
||||
|
@ -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 <intval> NUM
|
||||
%token <strval> CALL
|
||||
%token<intval> NUM
|
||||
%token<strval> CALL
|
||||
%token PLUS
|
||||
%type <ast> exp
|
||||
%type<ast> 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);}
|
||||
;
|
||||
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);
|
||||
};
|
||||
|
||||
%%
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user