-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtokens.hpp
More file actions
115 lines (107 loc) · 2.56 KB
/
tokens.hpp
File metadata and controls
115 lines (107 loc) · 2.56 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
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
#pragma once
#include <vector>
#include <string>
#include "classes.hpp"
#include "syntax.hpp"
char operators[] = { '(', ')', '+', '-', '*', '/', '^', ';', ',', '=', ':', '<', '>', '&', '|', '{', '}' };
std::string multiOperators[] = { "->", "==", "!=", "<=", ">=", "||", "&&", ">>", "<<" };
namespace pl {
auto CpLastComplete(std::string CpNow, std::vector<pl::RtData>& CpTokens) -> void {
if (CpNow.size() == 0) {
CpNow.clear();
return;
}
else if (CpNow[0] == '\"') {
CpTokens.push_back(pl::RtData(3, pl::RtVar(3, CpNow.substr(1))));
CpNow.clear();
return;
}
else if ('0' <= CpNow[0] && CpNow[0] <= '9' || CpNow[0] == '-') {
bool isFloat = false;
for (auto& i : CpNow) {
if (i == '.') {
isFloat = true;
break;
}
}
if (isFloat) {
CpTokens.push_back(pl::RtData(3, pl::RtVar(2, CpNow)));
}
else {
CpTokens.push_back(pl::RtData(3, pl::RtVar(1, CpNow)));
}
CpNow.clear();
return;
}
else {
CpTokens.push_back(pl::RtData(2, CpNow));
CpNow.clear();
}
}
auto CpSplitTokens(std::vector<pl::RtData>& CpTokens, std::string this_line) -> void {
std::string CpNow;
bool isInStr = false;
for (size_t i = 0; i < this_line.size(); i++) {
if (this_line[i] == '\"') {
if (isInStr) isInStr = false;
else {
isInStr = true;
CpNow += this_line[i];
}
continue;
}
if (isInStr) {
CpNow += this_line[i];
continue;
}
if (this_line[i] == ' ' || this_line[i] == '\n') continue;
else {
bool isOperator = false;
for (auto& j : operators) {
if (this_line[i] == j) {
isOperator = true;
break;
}
}
if (isOperator) {
bool isMultiOperator = false;
if (i != this_line.size() - 1) {
for (auto& j : multiOperators) {
if (this_line.substr(i, 2) == j) {
if (CpNow.size() > 0) {
pl::CpLastComplete(CpNow, CpTokens);
}
CpTokens.push_back(pl::RtData(1, j));
i++;
CpNow.clear();
isMultiOperator = true;
break;
}
}
}
if (isMultiOperator) continue;
if (CpNow.size() > 0) {
if (this_line[i] == '(')
CpTokens.push_back(pl::RtData(4, CpNow));
else pl::CpLastComplete(CpNow, CpTokens);
}
if (this_line[i] == ':') {
CpNow = ':';
continue;
}
std::string tmp;
tmp += this_line[i];
CpTokens.push_back(pl::RtData(1, tmp));
CpNow.clear();
continue;
}
else {
CpNow += this_line[i];
continue;
}
}
}
pl::CpLastComplete(CpNow, CpTokens);
checkSyntax(CpTokens);
}
}