-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.cpp
More file actions
75 lines (69 loc) · 1.13 KB
/
parser.cpp
File metadata and controls
75 lines (69 loc) · 1.13 KB
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
#include "parser.h"
#include <unordered_map>
wstring escape_char(const wchar_t& esc)
{
switch (esc)
{
case L'n':
return L"\n";
case L't':
return L"\t";
case L'r':
return L"\r";
case L'a':
return L"\a";
case L'v':
return L"\v";
case L'\\':
return L"\\";
case L'\'':
return L"'";
case L'"':
return L"\"";
default:
return wstring(1, esc);
break;
}
}
wstring escape_str(wstring str)
{
wstring new_str = L"";
for (wstring::iterator iter = str.begin(); iter != str.end(); ++iter)
{
if (*iter == L'\\')
{
new_str.append(escape_char(*(iter + 1)));
*(iter + 1) = NULL;
}
else
{
new_str.push_back(*iter);
}
}
return new_str;
}
unordered_map<string, unordered_map<string, string>> variables;
class ExprNode
{
public:
virtual ~ExprNode() {}
};
class NumberNode : ExprNode
{
public:
long double number;
NumberNode(const long double& num) : number(num) {}
};
class VarNode : ExprNode
{
public:
string name;
VarNode(const string& name) : name(name) {}
};
class InitNode : ExprNode
{
public:
string name;
string type;
InitNode(const string& name, const string& type): name(name), type(type) {}
};