1 | //This file contains formulas processing functions such as subformulas and variables ``getters''. |
---|
2 | |
---|
3 | function getSubFormulasIndexed(formInd) |
---|
4 | { |
---|
5 | var i; |
---|
6 | var stack = Vector.new(); |
---|
7 | var setOfSubforms = Vector.new(); |
---|
8 | setOfSubforms.add(formInd); |
---|
9 | if(formInd[0] < 4) |
---|
10 | { |
---|
11 | stack = getIndexedMainArgs(formInd); |
---|
12 | for(i = 0; i < stack.size; i++) |
---|
13 | { |
---|
14 | if(findPlainList(setOfSubforms, stack[i]) == -1) |
---|
15 | setOfSubforms.add(stack[i]); |
---|
16 | } |
---|
17 | } |
---|
18 | |
---|
19 | while(stack.size > 0) |
---|
20 | { |
---|
21 | if(stack[0][0] < 4) |
---|
22 | { |
---|
23 | var tempForms = Vector.new(); |
---|
24 | tempForms = getIndexedMainArgs(stack[0]); |
---|
25 | for(i = 0; i < tempForms.size; i++) |
---|
26 | { |
---|
27 | if(findPlainList(setOfSubforms, tempForms[i]) == -1) |
---|
28 | { |
---|
29 | setOfSubforms.add(tempForms[i]); |
---|
30 | stack.add(tempForms[i]); |
---|
31 | } |
---|
32 | } |
---|
33 | } |
---|
34 | stack.remove(0); |
---|
35 | } |
---|
36 | |
---|
37 | return setOfSubforms; |
---|
38 | } |
---|
39 | |
---|
40 | function getVariablesIndexed(setOfSubforms) |
---|
41 | { |
---|
42 | var i; |
---|
43 | var variables = Vector.new(); |
---|
44 | |
---|
45 | for(i = 0; i < setOfSubforms.size; i++) |
---|
46 | if(setOfSubforms[i][0] > 3 && variables.find(setOfSubforms[i]) == -1) |
---|
47 | variables.add(setOfSubforms[i]); |
---|
48 | |
---|
49 | |
---|
50 | return variables; |
---|
51 | } |
---|
52 | |
---|
53 | function getIndexedMainArgs(formInd) |
---|
54 | { |
---|
55 | |
---|
56 | var argsList = Vector.new(); |
---|
57 | if(formInd[0] > 0 && formInd[0] < 4) |
---|
58 | { |
---|
59 | var firstArgStart = Vector.new(); |
---|
60 | firstArgStart.add(formInd[1]); |
---|
61 | var firstArg = Vector.new(); |
---|
62 | var secondArg = Vector.new(); |
---|
63 | |
---|
64 | |
---|
65 | if(firstArgStart[0] > 3) |
---|
66 | { |
---|
67 | argsList.add(firstArgStart); |
---|
68 | secondArg = plainListRight(formInd, formInd.size - 2); |
---|
69 | argsList.add(secondArg); |
---|
70 | } |
---|
71 | else |
---|
72 | { |
---|
73 | var i; |
---|
74 | var p = 2, p_temp = 2, e = 1; |
---|
75 | var check_conj = 1; |
---|
76 | |
---|
77 | |
---|
78 | while(check_conj == 1) |
---|
79 | { |
---|
80 | for(i = e; i < p; i++) |
---|
81 | { |
---|
82 | if(formInd[i] == 0) |
---|
83 | { |
---|
84 | p_temp++; |
---|
85 | } |
---|
86 | if(formInd[i] > 0 && formInd[i] < 4) |
---|
87 | { |
---|
88 | p_temp += 2; |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | if(p == p_temp) |
---|
93 | check_conj = 0; |
---|
94 | |
---|
95 | e = p; |
---|
96 | p = p_temp; |
---|
97 | } |
---|
98 | |
---|
99 | firstArg = plainListSubList(formInd, 1, p - 1); |
---|
100 | argsList.add(firstArg); |
---|
101 | secondArg = plainListRight(formInd, formInd.size - p); |
---|
102 | argsList.add(secondArg); |
---|
103 | } |
---|
104 | |
---|
105 | return argsList; |
---|
106 | } |
---|
107 | else |
---|
108 | { |
---|
109 | if(formInd[0] == 0) |
---|
110 | { |
---|
111 | argsList.add(plainListRight(formInd, formInd.size - 1)); |
---|
112 | return argsList; |
---|
113 | } |
---|
114 | else |
---|
115 | { |
---|
116 | Simulator.print("There is no proper operator"); |
---|
117 | return Vector.new(); |
---|
118 | } |
---|
119 | } |
---|
120 | |
---|
121 | } |
---|