Skip to content

Commit 89e657e

Browse files
Version 4.0 bez kommentariev
1 parent 60ac64c commit 89e657e

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

lab5/src/classes/GSSNode.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,11 @@ class _GSSNode<T> {
115115

116116
void _getAncestorsRecursive(
117117
_GSSNode<T> currentNode, int k, Set<_GSSNode<T>> result) {
118-
if (k < 0) {
118+
if (k == 0) {
119+
result.add(currentNode);
119120
return;
120121
}
121122

122-
result.add(currentNode);
123-
124123
if (currentNode.level == 0) {
125124
return;
126125
}

lab5/src/lr0/lr0Parser.dart

+20-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class LR0Parser {
4545
} else {
4646
List<GSSNode<List<String>>> prevCopy = List.from(v_ss.prev.values);
4747
for (final l in prevCopy) {
48+
4849
if (l.value == v1_s.value) {
4950
int ind = node_id_next();
5051
nodes[ind] = stack.push(v_ss_value, v1_s as GSSNode<List<String>>?); //vc_ss
@@ -56,7 +57,9 @@ class LR0Parser {
5657
}
5758
}
5859
} else {
60+
5961
v_ss.addPrevByValue(v1_s);
62+
6063
if (P.contains(v_ss)) {
6164
int ind = node_id_next();
6265
nodes[ind] = stack.push(v_ss_value, v1_s as GSSNode<List<String>>?); //vc_ss
@@ -129,7 +132,14 @@ class LR0Parser {
129132
}
130133
}
131134

132-
for (final hidenode in reduced) {
135+
if(reduced.every((r) => P.contains(r)) && reduced.length != 0) {
136+
test = false;
137+
check = true;
138+
}
139+
140+
List<GSSNode<List<String>>> reducedCopy = List.from(reduced);
141+
142+
for (final hidenode in reducedCopy) {
133143
P.add(hidenode);
134144
final act = _table.lr0_table[int.parse(hidenode.value[1])]?[word_tokens[i]]!;
135145

@@ -146,6 +156,15 @@ class LR0Parser {
146156
}
147157
}
148158

159+
for (var obj in act) {
160+
if (obj.actionTitle.startsWith("r")) {
161+
Reduce(hidenode, obj.ruleNumber!, word_tokens[i], P, reduced);
162+
if (reduced.length != 0) {
163+
test = true;
164+
}
165+
}
166+
}
167+
149168
for (var obj in act) {
150169
if (obj.actionTitle == 'ACC') {
151170
GSSNode<List<String>> lastNode = stack.levels.last.nodes.values.last;

lab5/src/tests/GSS_test.dart

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'package:test/test.dart';
22
import '../classes/GSStack.dart';
33
import '../classes/GSSNode.dart';
4-
import '../types/Comparator.dart';
54

65
void main() {
76
group('GSStack: example', () {
@@ -20,20 +19,17 @@ void main() {
2019

2120
// {7,4,1,0}
2221
nodes[4] = stack.push(["4"], nodes[1]);
23-
nodes[9] = stack.push(["7"],
24-
nodes[4]); // 7 isn't duplicated, as it ends up in the same layer
22+
nodes[9] = stack.push(["7"], nodes[4]); // 7 isn't duplicated, as it ends up in the same layer
2523

2624
// {7,5,2,0}
2725
nodes[2] = stack.push(["2"], nodes[0]);
2826
nodes[5] = stack.push(["5"], nodes[2]);
29-
nodes[15] = stack.push(["7, 5"], nodes[5]);
27+
nodes[7] = stack.push(["7"], nodes[5]);
3028

3129
// {8,6,2,0}
3230
nodes[6] = stack.push(["6"], nodes[2]);
3331
nodes[8] = stack.push(["8"], nodes[6]);
3432

35-
var result = nodes[7]?.ancestors(1);
36-
3733
/*for (final ancestor in result!) {
3834
print(ancestor.id);
3935
}*/
@@ -42,7 +38,7 @@ void main() {
4238
});
4339

4440
test('random staff', () {
45-
print(nodes[8]?.prev);
41+
print(nodes[7]?.ancestors(3));
4642
});
4743

4844
/*test('has the right degrees: prev', () {

0 commit comments

Comments
 (0)