-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpredictiveTable.js
76 lines (61 loc) · 2.17 KB
/
predictiveTable.js
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
const getFirst = require('./first');
const getFollow = require('./follow');
module.exports = function getTable(rulesArray) {
varSimbols = [];
finalSimbols = [' '];
table = [];
rulesArray.forEach(element => {
element.forEach(simbols => {
simbols.split('').forEach(simbol => {
if(simbol === simbol.toLowerCase() && simbol != 'Ɛ') {
if(!finalSimbols.includes(simbol)) {
finalSimbols.push(simbol)
}
} else {
if(!varSimbols.includes(simbol) && simbol != 'Ɛ') {
varSimbols.push(simbol)
}
}
})
})
})
finalSimbols.push('$')
table.push(finalSimbols);
// Rule 1
rulesArray.forEach(rule => {
element = rule[0];
aux = [];
aux.push(element);
for(i = 1; i < finalSimbols.length; i++) {
if(getFirst(rulesArray, element).includes(finalSimbols[i])){
if(rule.length < 3) {
aux.push(rule)
} else {
myRule = rule.filter(element => (element[0].includes(finalSimbols[i]) || getFirst(rulesArray, element).includes(finalSimbols[i])))
aux.push(myRule)
}
} else {
aux.push('error')
};
}
table.push(aux);
})
// Rule 2
rulesArray.forEach(rule => {
element = rule[0];
if(getFirst(rulesArray, element).includes('Ɛ')) {
follow = getFollow(rulesArray, element);
follow.forEach(simbol => {
indexSimbol = finalSimbols.indexOf(simbol);
table.forEach(rules => {
if(rules[0] == element) {
myRule = rule.filter(element => (element[0].includes(simbol) || getFollow(rulesArray, element).includes(simbol)))
aux.push(myRule)
rules[indexSimbol] = myRule;
}
})
})
}
})
return table
}