aboutsummaryrefslogtreecommitdiff
path: root/src/parser.y
diff options
context:
space:
mode:
authorFlavian Kaufmann <flavian@flaviankaufmann.ch>2025-05-23 11:25:29 +0200
committerFlavian Kaufmann <flavian@flaviankaufmann.ch>2025-05-23 11:25:29 +0200
commitde59dbd1773dff06051b7b604977bcb2803ada4f (patch)
tree60be4de19aa7be4d4d99136c2bfbb824edfa2d90 /src/parser.y
parent987a7c553701251d48b11a2243892ecd74ce6c4d (diff)
downloadimp-de59dbd1773dff06051b7b604977bcb2803ada4f.tar.gz
imp-de59dbd1773dff06051b7b604977bcb2803ada4f.zip
[cleanup] ast
Diffstat (limited to 'src/parser.y')
-rw-r--r--src/parser.y68
1 files changed, 34 insertions, 34 deletions
diff --git a/src/parser.y b/src/parser.y
index 164b3cc..5952aa9 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -6,7 +6,7 @@ extern char *yytext;
extern int yylineno;
extern int yylex();
-ASTNode *ast_root;
+IMP_ASTNode *ast_root;
void yyerror(const char *s) {
fprintf(stderr, "Parse error at token \"%s\", line %d: %s\n", yytext, yylineno, s);
@@ -15,10 +15,10 @@ void yyerror(const char *s) {
%union {
- int num;
- char *id;
- struct ASTNode *node;
- struct ASTNodeList *node_list;
+ int num;
+ char *id;
+ struct IMP_ASTNode *node;
+ struct IMP_ASTNodeList *node_list;
}
%start prog
@@ -47,23 +47,23 @@ prog : stm
;
stm : T_SKIP
- { $$ = ast_skip(); }
+ { $$ = imp_ast_skip(); }
| var T_ASSIGN aexp
- { $$ = ast_assign($1, $3); }
+ { $$ = imp_ast_assign($1, $3); }
| T_LPAREN stm T_SEM stm T_RPAREN
- { $$ = ast_seq($2, $4); }
+ { $$ = imp_ast_seq($2, $4); }
| stm T_SEM stm
- { $$ = ast_seq($1, $3); }
+ { $$ = imp_ast_seq($1, $3); }
| stm T_SEM
{ $$ = $1; }
| T_IF bexp T_THEN stm T_ELSE stm T_END
- { $$ = ast_if($2, $4, $6); }
+ { $$ = imp_ast_if($2, $4, $6); }
| T_IF bexp T_THEN stm T_END
- { $$ = ast_if($2, $4, ast_skip()); }
+ { $$ = imp_ast_if($2, $4, imp_ast_skip()); }
| T_WHILE bexp T_DO stm T_END
- { $$ = ast_while($2, $4); }
+ { $$ = imp_ast_while($2, $4); }
| T_VAR var T_ASSIGN aexp T_IN stm T_END
- { $$ = ast_let($2, $4, $6); }
+ { $$ = imp_ast_let($2, $4, $6); }
| procd
{ $$ = $1; }
| procc
@@ -71,62 +71,62 @@ stm : T_SKIP
;
var : T_ID
- { $$ = ast_var($1); }
+ { $$ = imp_ast_var($1); }
;
aexp : aexp T_PLUS aexp
- { $$ = ast_aop(AOP_ADD, $1, $3); }
+ { $$ = imp_ast_aop(IMP_AST_AOP_ADD, $1, $3); }
| aexp T_MINUS aexp
- { $$ = ast_aop(AOP_SUB, $1, $3); }
+ { $$ = imp_ast_aop(IMP_AST_AOP_SUB, $1, $3); }
| aexp T_STAR aexp
- { $$ = ast_aop(AOP_MUL, $1, $3); }
+ { $$ = imp_ast_aop(IMP_AST_AOP_MUL, $1, $3); }
| T_MINUS aexp %prec T_UMINUS
- { $$ = ast_aop(AOP_SUB, ast_int(0), $2); }
+ { $$ = imp_ast_aop(IMP_AST_AOP_SUB, imp_ast_int(0), $2); }
| T_LPAREN aexp T_RPAREN
{ $$ = $2; }
| var
{ $$ = $1; }
| T_NUM
- { $$ = ast_int($1); }
+ { $$ = imp_ast_int($1); }
;
bexp : bexp T_OR bexp
- { $$ = ast_bop(BOP_OR, $1, $3); }
+ { $$ = imp_ast_bop(IMP_AST_BOP_OR, $1, $3); }
| bexp T_AND bexp
- { $$ = ast_bop(BOP_AND, $1, $3); }
+ { $$ = imp_ast_bop(IMP_AST_BOP_AND, $1, $3); }
| T_NOT bexp
- { $$ = ast_not($2); }
+ { $$ = imp_ast_not($2); }
| aexp T_EQ aexp
- { $$ = ast_rop(ROP_EQ, $1, $3); }
+ { $$ = imp_ast_rop(IMP_AST_ROP_EQ, $1, $3); }
| aexp T_NE aexp
- { $$ = ast_rop(ROP_NE, $1, $3); }
+ { $$ = imp_ast_rop(IMP_AST_ROP_NE, $1, $3); }
| aexp T_LE aexp
- { $$ = ast_rop(ROP_LE, $1, $3); }
+ { $$ = imp_ast_rop(IMP_AST_ROP_LE, $1, $3); }
| aexp T_LT aexp
- { $$ = ast_rop(ROP_LT, $1, $3); }
+ { $$ = imp_ast_rop(IMP_AST_ROP_LT, $1, $3); }
| aexp T_GE aexp
- { $$ = ast_rop(ROP_GE, $1, $3); }
+ { $$ = imp_ast_rop(IMP_AST_ROP_GE, $1, $3); }
| aexp T_GT aexp
- { $$ = ast_rop(ROP_GT, $1, $3); }
+ { $$ = imp_ast_rop(IMP_AST_ROP_GT, $1, $3); }
| T_LPAREN bexp T_RPAREN
{ $$ = $2; }
| T_TRUE
- { $$ = ast_rop(ROP_EQ, ast_int(1), ast_int(1)); }
+ { $$ = imp_ast_rop(IMP_AST_ROP_EQ, imp_ast_int(1), imp_ast_int(1)); }
| T_FALSE
- { $$ = ast_rop(ROP_EQ, ast_int(0), ast_int(1)); }
+ { $$ = imp_ast_rop(IMP_AST_ROP_EQ, imp_ast_int(0), imp_ast_int(1)); }
;
args : var
- { $$ = ast_node_list($1, NULL); }
+ { $$ = imp_ast_list($1, NULL); }
| args T_COM var
- { $$ = ast_node_list($3, $1); }
+ { $$ = imp_ast_list($3, $1); }
;
procd : T_PROC T_ID T_LPAREN args T_SEM args T_RPAREN T_BEGIN stm T_END
- { $$ = ast_procdecl($2, $4, $6, $9); }
+ { $$ = imp_ast_procdecl($2, $4, $6, $9); }
;
procc : T_ID T_LPAREN args T_SEM args T_RPAREN
- { $$ = ast_proccall($1, $3, $5); }
+ { $$ = imp_ast_proccall($1, $3, $5); }
;
%%