Usando o padrao Visitor de forma decente. Verificacao semantica meio pronta.
[toypasc.git] / ast.h
blob3b70ce7d669702e622f862f8fd3684004208fc5c
1 #ifndef AST_H
2 #define AST_H
4 #include "base.h"
5 #include "parser.h"
6 #include "symbol_table.h"
8 struct AstNode {
9 char *name;
10 int kind;
11 Type type;
12 Value value;
13 Symbol *symbol;
14 int linenum;
15 bool has_problem;
16 struct AstNode* parent;
17 struct AstNode* children;
18 struct AstNode* sibling;
21 typedef struct {
22 void (*visit_program)(struct AstNode *);
23 void (*visit_programdecl)(struct AstNode *);
24 void (*visit_vardecl_list)(struct AstNode *);
25 void (*visit_vardecl)(struct AstNode *);
26 void (*visit_identifier_list)(struct AstNode *);
27 void (*visit_identifier)(struct AstNode *);
28 void (*visit_procfunc_list)(struct AstNode *);
29 void (*visit_procedure)(struct AstNode *);
30 void (*visit_function)(struct AstNode *);
31 void (*visit_param_list)(struct AstNode *);
32 void (*visit_parameter)(struct AstNode *);
33 void (*visit_statement_list)(struct AstNode *);
34 void (*visit_print_stmt)(struct AstNode *);
35 void (*visit_assignment_stmt)(struct AstNode *);
36 void (*visit_if_stmt)(struct AstNode *);
37 void (*visit_while_stmt)(struct AstNode *);
38 void (*visit_for_stmt)(struct AstNode *);
39 void (*visit_rel_expr)(struct AstNode *);
40 void (*visit_add_expr)(struct AstNode *);
41 void (*visit_mul_expr)(struct AstNode *);
42 void (*visit_notfactor)(struct AstNode *);
43 void (*visit_call)(struct AstNode *);
44 void (*visit_callparam_list)(struct AstNode *);
45 void (*visit_literal)(struct AstNode *);
46 void (*close_group)();
47 } Visitor;
49 struct AstNode *ast_node_new(const char* name, int kind, int type,
50 int linenum, Symbol *symbol);
51 void ast_node_destroy(struct AstNode *self);
53 void ast_node_add_child(struct AstNode *self, struct AstNode *child);
54 void ast_node_add_sibling(struct AstNode *self, struct AstNode *sibling);
55 void ast_node_accept(struct AstNode *self, Visitor *visitor);
57 #endif // AST_H