-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParser.h
More file actions
113 lines (102 loc) · 1.89 KB
/
Copy pathParser.h
File metadata and controls
113 lines (102 loc) · 1.89 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
#pragma once
#include <iostream>
#include <string>
#include "List.h"
#include "Stack.h"
class Parser {
List<std::string> lexems;
std::string example;
std::string line;
public:
Parser();
Parser(std::string examp);
Parser(Parser& par);
bool check();
void parse();
int size();
std::string getline();
std::string getlex();
void prnt();
};
Parser::Parser() {
example = "";
}
Parser::Parser(std::string examp){
example = examp;
}
Parser::Parser(Parser& par) {
example = par.example;
lexems = par.lexems;
}
bool Parser::check() {
StList<char> brekets;
for (size_t i = 0; i < example.size(); i++) {
if (example[i] == '(') {
brekets.push(example[i]);
}
else if (example[i] == ')') {
if (brekets.isEmpty()) {
std::cout << "Uncorrect brekets subsequence";
return false;
}
brekets.pop();
}
}
if (!brekets.isEmpty()) {
std::cout << "Lack of brackets";
return false;
}
return true;
}
void Parser::parse() {
int stat = 0;
std::string tmp = "";
for (size_t i = 0; i < example.size(); i++) {
if (stat == 0) {
if (std::isdigit(example[i])) {
tmp += example[i];
}
else {
stat = 1;
if (tmp != "") {
lexems.push_back(tmp);
}
line += "1";
tmp = "";
}
}
if (stat == 1) {
if (!std::isdigit(example[i])) {
std::string str(1, example[i]);
lexems.push_back(str);
line += "0";
}
else {
stat = 0;
tmp += example[i];
}
}
}
}
int Parser::size() {
int temp1 = 0;
List<std::string> temp2 = lexems;
while (!temp2.isEmpty()) {
if (!temp2.isEmpty()) {
temp1 += 1;
temp2.pop_back();
}
}
return temp1;
}
std::string Parser::getline() {
return line;
}
std::string Parser::getlex() {
std::string temp = "";
temp += lexems.pop_back();
return temp;
}
void Parser::prnt() {
lexems.prnt();
}