4 #include "simpleprinter_visitor.h"
9 Visitor
*sp_visitor
= (Visitor
*) malloc (sizeof(Visitor
));
11 sp_visitor
->visit_program
= &simpleprinter_visit
;
12 sp_visitor
->visit_programdecl
= &simpleprinter_visit
;
13 sp_visitor
->visit_vardecl_list
= &simpleprinter_visit
;
14 sp_visitor
->visit_vardecl
= &simpleprinter_visit
;
15 sp_visitor
->visit_identifier_list
= &simpleprinter_visit
;
16 sp_visitor
->visit_procfunc_list
= &simpleprinter_visit
;
17 sp_visitor
->visit_procedure
= &simpleprinter_visit
;
18 sp_visitor
->visit_function
= &simpleprinter_visit
;
19 sp_visitor
->visit_param_list
= &simpleprinter_visit
;
20 sp_visitor
->visit_parameter
= &simpleprinter_visit
;
21 sp_visitor
->visit_statement_list
= &simpleprinter_visit
;
22 sp_visitor
->visit_print_stmt
= &simpleprinter_visit
;
23 sp_visitor
->visit_assignment_stmt
= &simpleprinter_visit
;
24 sp_visitor
->visit_if_stmt
= &simpleprinter_visit
;
25 sp_visitor
->visit_while_stmt
= &simpleprinter_visit
;
26 sp_visitor
->visit_for_stmt
= &simpleprinter_visit
;
27 sp_visitor
->visit_rel_expr
= &simpleprinter_visit
;
28 sp_visitor
->visit_add_expr
= &simpleprinter_visit
;
29 sp_visitor
->visit_mul_expr
= &simpleprinter_visit
;
30 sp_visitor
->visit_notfactor
= &simpleprinter_visit
;
31 sp_visitor
->visit_call
= &simpleprinter_visit
;
32 sp_visitor
->visit_callparam_list
= &simpleprinter_visit
;
33 sp_visitor
->visit_identifier
= &simpleprinter_visit
;
34 sp_visitor
->visit_literal
= &simpleprinter_visit
;
35 sp_visitor
->close_group
= NULL
;
39 simpleprinter_visit(struct AstNode
*self
)
47 printf("(AstNode) %x : %s\n", self
, self
->name
);
48 printf("kind: %d\n", self
->kind
);
49 printf("type: %d\n", self
->type
);
51 value_print(&self
->value
, self
->type
);
52 printf("\nlinenum: %d\n", self
->linenum
);
53 if (self
->symbol
!= NULL
)
54 printf("symbol: %x (\"%s\")\n", self
->symbol
, self
->symbol
->name
);
56 printf("Parent: (AstNode) %x\n", self
->parent
);
58 if (self
->children
!= NULL
) {
60 for (temp
= self
->children
; temp
!= NULL
; temp
= temp
->sibling
) {
61 printf("\t(AstNode) %x", temp
);
62 if (temp
->name
!= NULL
)
63 printf(" : %s", temp
->name
);
69 simpleprinter_visit(self
->children
);
70 simpleprinter_visit(self
->sibling
);