-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5_10.cpp
More file actions
41 lines (34 loc) · 948 Bytes
/
5_10.cpp
File metadata and controls
41 lines (34 loc) · 948 Bytes
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
#include <algorithm>
#include <iostream>
#include <vector>
#include "5_9.cpp"
// Test for LR(k)-ness
bool Check_k(Grammar G, size_t k) {
V_k_G_collection Y = FindCollection(G, k);
for (auto s : Y.collection) {
for (auto sit1 : s.set) {
for (auto sit2 : s.set) {
if (!(sit1 == sit2)) {
sentential_form betta_u = sit2.rule.right_part;
betta_u.str_.erase(betta_u.str_.begin(), betta_u.str_.begin() + sit2.point); //
for (size_t i = 0; i < sit2.u.size(); i++) {
betta_u.str_.push_back({sit2.u[i], false});
}
First_k eff = EFF(k, betta_u, G);
if (sit1.point == sit1.rule.right_part.str_.size() && (eff.set.find(sit1.u) != eff.set.end())) {
return false;
}
}
}
}
}
return true;
}
size_t FindCorrectK(Grammar G) {
size_t k = 0;
while (true) {
if (Check_k(G, k)) break;
++k;
}
return k;
}