-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrintVisitor.cpp
95 lines (83 loc) · 1.96 KB
/
PrintVisitor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// Created by nalle on 8/15/2017.
//
#include "PrintVisitor.h"
#include <iostream>
using std::cout;
using std::endl;
void PrintVisitor::printPos(std::shared_ptr<ASTNode> node)
{
cout << "(" << node->getLine() << ", " << node->getColumn() << ")\n";
}
void PrintVisitor::visit(std::shared_ptr<ASTNode> node)
{
cout << "astnode ";
printPos(node);
}
void PrintVisitor::visit(std::shared_ptr<ASTExp> node)
{
cout << "astExp ";
printPos(node);
}
void PrintVisitor::visit(std::shared_ptr<ASTOp> node)
{
cout << "astOp ";
printPos(node);
}
void PrintVisitor::visit(std::shared_ptr<ASTAdd> node)
{
cout << "astAdd ";
printPos(node);
cout << "left: \n";
node->getLeft()->accept(*this);
cout << "right: \n";
node->getRight()->accept(*this);
}
void PrintVisitor::visit(std::shared_ptr<ASTSub> node)
{
cout << "astSub ";
printPos(node);
cout << "left: \n";
node->getLeft()->accept(*this);
cout << "right: \n";
node->getRight()->accept(*this);
}
void PrintVisitor::visit(std::shared_ptr<ASTMul> node)
{
cout << "astMul ";
printPos(node);
cout << "left: \n";
node->getLeft()->accept(*this);
cout << "right: \n";
node->getRight()->accept(*this);
}
void PrintVisitor::visit(std::shared_ptr<ASTDiv> node)
{
cout << "astDiv ";
printPos(node);
cout << "left: \n";
node->getLeft()->accept(*this);
cout << "right: \n";
node->getRight()->accept(*this);
}
void PrintVisitor::visit(std::shared_ptr<ASTVar> node)
{
cout << "astVar ";
printPos(node);
cout << "var: " << node->getVarName() << "\n";
}
void PrintVisitor::visit(std::shared_ptr<ASTNum> node)
{
cout << "astNum ";
printPos(node);
cout << "num str: " << node->getValueStr() << "\n";
}
void PrintVisitor::visit(std::shared_ptr<ASTAssign> node)
{
cout << "astAssign";
printPos(node);
cout << "var: ";
node->getLeft()->accept(*this);
cout << "right: \n";
node->getRight()->accept(*this);
}