-
Notifications
You must be signed in to change notification settings - Fork 1
/
Analyzer.cc
160 lines (114 loc) · 3.78 KB
/
Analyzer.cc
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include "Analyzer.h"
void Analyzer::Show(SyntaxToken* root)
{
PrintNode(root);
}
void Analyzer::PrintNode(SyntaxToken* token, int indent)
{
if(token == NULL) return;
for(int i=0; i < indent;i++) cout << " ";
cout << GetTypeName(token->GetType()) << " (" << token->Children().size() << " children) ";
cout << "[" << GetValue(token) << "]" << endl;
for(auto i = token->Children().begin(); i != token->Children().end(); ++i)
{
PrintNode(*i, indent+1);
}
}
string Analyzer::GetValue(SyntaxToken* token)
{
if(typeid(*token) == typeid(StringSyntaxToken))
{
return dynamic_cast<StringSyntaxToken*>(token)->GetValue();
}
else if (typeid(*token) == typeid(FloatSyntaxToken))
{
return ToString(dynamic_cast<FloatSyntaxToken*>(token)->GetValue());
}
else if (typeid(*token) == typeid(IntegerSyntaxToken))
{
return ToString(dynamic_cast<IntegerSyntaxToken*>(token)->GetValue());
}
else if (typeid(*token) == typeid(BooleanSyntaxToken))
{
return ToString(dynamic_cast<BooleanSyntaxToken*>(token)->GetValue());
}
return "";
}
string Analyzer::GetTypeName(SyntaxTokenType tokenType)
{
switch(tokenType)
{
case SyntaxTokenType::NilToken:
return "Nil token";
case SyntaxTokenType::ExpressionList:
return "Expression list";
case SyntaxTokenType::IntegerToken:
return "IntegerToken";
case SyntaxTokenType::FloatToken:
return "FloatToken";
case SyntaxTokenType::LiteralToken:
return "LiteralToken";
case SyntaxTokenType::BooleanToken:
return "BooleanToken";
case SyntaxTokenType::IdentifierToken:
return "IdentifierToken";
case SyntaxTokenType::GlobalIdentifierToken:
return "GlobalIdentifierToken";
case SyntaxTokenType::FunctionIdentifierToken:
return "FunctionIdentifierToken";
case SyntaxTokenType::FunctionDefinition:
return "FunctionDefinition";
case SyntaxTokenType::FunctionDefinitionHeader:
return "FunctionDefinitionHeader";
case SyntaxTokenType::FunctionDefinitionParams:
return "FunctionDefinitionParams";
case SyntaxTokenType::FunctionCall:
return "FunctionCall";
case SyntaxTokenType::FunctionCallParams:
return "FunctionCallParams";
case SyntaxTokenType::IfToken:
return "IfToken";
case SyntaxTokenType::TernaryToken:
return "TernaryToken";
case SyntaxTokenType::UndefToken:
return "UndefToken";
case SyntaxTokenType::RequireToken:
return "RequireToken";
case SyntaxTokenType::DefinedToken:
return "DefinedToken";
case SyntaxTokenType::CaseToken:
return "CaseToken";
case SyntaxTokenType::CaseListToken:
return "CaseListToken";
case SyntaxTokenType::CaseWhenToken:
return "CaseWhenToken";
case SyntaxTokenType::CaseDefaultToken:
return "CaseDefaultToken";
case SyntaxTokenType::AliasToken:
return "AliasToken";
case SyntaxTokenType::ReturnToken:
return "ReturnToken";
case SyntaxTokenType::UnlessToken:
return "UnlessToken";
case SyntaxTokenType::BreakToken:
return "BreakToken";
case SyntaxTokenType::RetryToken:
return "RetryToken";
case SyntaxTokenType::WhileToken:
return "WhileToken";
case SyntaxTokenType::WhileExpressionList:
return "WhileExpressionList";
case SyntaxTokenType::Assignment:
return "Assignment";
case SyntaxTokenType::ArrayDefinition:
return "ArrayDefinition";
case SyntaxTokenType::ArraySelector:
return "ArraySelector";
case SyntaxTokenType::OperationToken:
return "OperationToken";
case SyntaxTokenType::OperationTypeToken:
return "OperationTypeToken";
default:
return "Some shit!";
}
}