-
Notifications
You must be signed in to change notification settings - Fork 1
/
statement.js
86 lines (70 loc) · 1.75 KB
/
statement.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
77
78
79
80
81
82
83
84
85
86
class Statement{
static sourceAmount = {
'ua': 0,
'uo': 1,
'ux': 2,
'u-': 2,
'i-': 1,
'u+': 1,
'i+': 5,
'u*': 2,
'i*': 1,
'u>': 2,
'i>': 2,
//'u=': 2,
//'i=': 2,
'uA': 1, //http://kgracin.com/logika/ndPravilaTeoremi.pdf kaze da su 2, ali jedan je zapravo nepotreban
'iA': 1,
'uE': 1,
'iE': 3,
}
static methodFormat = {
'ua': "",
'uo': "",
'ux': ",",
'u-': "-",
'i-': "",
'u+': "",
'i+': ",-,-",
'u*': ",",
'i*': "",
'u>': "-",
'i>': ",",
//'u=': 2,
//'i=': 2,
'uA': "",
'iA': "",
'uE': "",
'iE': ",-",
}
type = "Statement";
constructor(expression, method, ...sources){
this.expression = expression;
this.method = method;
this.sources = sources;
this.valid = false;
}
printSelf(){
console.log(`${this.expression} | ${this.sources} (${this.method})`);
//this.expression, ' ', this.sources, ' ', this.method,
}
stringOfSelf(){
return str(this.expression.stringOfSelf()) + ' ' + str(this.sources) + ' ( ' + str(this.method) + ' ) ';
}
stringOfMetadata(){
if(this.method == 'ua'){
return `p.`;
}
//add appropreate symbols betweewn numbers, "" if the symbol is undefined (end of string from Statement.methodFormat)
let formattedSources = this.sources.map((x, i) => `${x}${Statement.methodFormat[this.method][i] || ""}`);
formattedSources = formattedSources.join("");
return `${formattedSources} ${this.method[0]} ${Expression.expressionMap[this.method[1]]}`;
}
addSource(n){
if(this.sources.length < Statement.sourceAmount[this.method]){
this.sources.push(n);
} else {
this.sources = [n];
}
}
}