6 #include "symbol_table.h"
16 struct AstNode
* parent
;
17 struct AstNode
* children
;
18 struct AstNode
* sibling
;
21 typedef struct _Visitor
{
22 void (*visit_program
) (struct _Visitor
*, struct AstNode
*);
23 void (*visit_programdecl
) (struct _Visitor
*, struct AstNode
*);
24 void (*visit_vardecl_list
) (struct _Visitor
*, struct AstNode
*);
25 void (*visit_vardecl
) (struct _Visitor
*, struct AstNode
*);
26 void (*visit_identifier_list
) (struct _Visitor
*, struct AstNode
*);
27 void (*visit_identifier
) (struct _Visitor
*, struct AstNode
*);
28 void (*visit_procfunc_list
) (struct _Visitor
*, struct AstNode
*);
29 void (*visit_procedure
) (struct _Visitor
*, struct AstNode
*);
30 void (*visit_function
) (struct _Visitor
*, struct AstNode
*);
31 void (*visit_param_list
) (struct _Visitor
*, struct AstNode
*);
32 void (*visit_parameter
) (struct _Visitor
*, struct AstNode
*);
33 void (*visit_statement_list
) (struct _Visitor
*, struct AstNode
*);
34 void (*visit_printint_stmt
) (struct _Visitor
*, struct AstNode
*);
35 void (*visit_printchar_stmt
) (struct _Visitor
*, struct AstNode
*);
36 void (*visit_printbool_stmt
) (struct _Visitor
*, struct AstNode
*);
37 void (*visit_printline_stmt
) (struct _Visitor
*, struct AstNode
*);
38 void (*visit_assignment_stmt
) (struct _Visitor
*, struct AstNode
*);
39 void (*visit_if_stmt
) (struct _Visitor
*, struct AstNode
*);
40 void (*visit_while_stmt
) (struct _Visitor
*, struct AstNode
*);
41 void (*visit_for_stmt
) (struct _Visitor
*, struct AstNode
*);
42 void (*visit_rel_expr
) (struct _Visitor
*, struct AstNode
*);
43 void (*visit_add_expr
) (struct _Visitor
*, struct AstNode
*);
44 void (*visit_mul_expr
) (struct _Visitor
*, struct AstNode
*);
45 void (*visit_notfactor
) (struct _Visitor
*, struct AstNode
*);
46 void (*visit_call
) (struct _Visitor
*, struct AstNode
*);
47 void (*visit_callparam_list
) (struct _Visitor
*, struct AstNode
*);
48 void (*visit_callparam
) (struct _Visitor
*, struct AstNode
*);
49 void (*visit_literal
) (struct _Visitor
*, struct AstNode
*);
50 void (*visit_add_op
) (struct _Visitor
*, struct AstNode
*);
51 void (*visit_mul_op
) (struct _Visitor
*, struct AstNode
*);
52 void (*visit_rel_op
) (struct _Visitor
*, struct AstNode
*);
53 void (*visit_not_op
) (struct _Visitor
*, struct AstNode
*);
56 typedef void (*VisitFunc
)(struct _Visitor
*, struct AstNode
*);
58 struct AstNode
*ast_node_new(const char *name
, int kind
, int type
,
59 int linenum
, Symbol
*symbol
);
60 void ast_node_destroy(struct AstNode
*);
62 Value
ast_node_get_value(struct AstNode
*);
63 int ast_node_get_value_as_int(struct AstNode
*);
64 int ast_node_get_child_counter(struct AstNode
*);
65 bool ast_node_check_errors(struct AstNode
*);
66 void ast_node_add_child(struct AstNode
*, struct AstNode
*);
67 void ast_node_add_sibling(struct AstNode
*, struct AstNode
*);
68 void ast_node_accept(struct AstNode
*, Visitor
*);
69 void ast_node_accept_children(struct AstNode
*, Visitor
*);