ETO PIZDEC BRATISHKI

  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
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
$EXTERN WriteLine, ReadLine, Inc, Dec, Compare, Sub, Add;
$ENUM OpenBr, CloseBr, OpenSet, CloseSet, Brackets, Set, LeftScanner, Stack;
$ENUM FxOpenSet, FxCloseSet;
Union {
(FxOpenSet) e.Set1-B t.Common e.Set1-E (FxCloseSet) (FxOpenSet) e.Set2-B t.Common e.Set2-E (FxCloseSet) =
<WriteLine 'union stage begin: ' (FxOpenSet) e.Set1-B t.Common e.Set1-E (FxCloseSet) (FxOpenSet) e.Set2-B t.Common e.Set2-E (FxCloseSet)>
<WriteLine 'go to stash: ' e.Set1-B e.Set2-B t.Common>
t.Common <Union (FxOpenSet) e.Set1-B e.Set1-E (FxCloseSet) (FxOpenSet) e.Set2-B e.Set2-E (FxCloseSet)>;
(FxOpenSet) e.Set1 (FxCloseSet) (FxOpenSet) e.Set2 (FxCloseSet) =
<WriteLine 'union stage final: ' e.Set1 e.Set2>
e.Set1 e.Set2;
}
Intersect {
(FxOpenSet) e.Set1-B t.Common e.Set1-E (FxCloseSet) (FxOpenSet) e.Set2-B t.Common e.Set2-E (FxCloseSet) =
t.Common <Intersect (FxOpenSet) e.Set1-E (FxCloseSet) (FxOpenSet) e.Set2-B e.Set2-E (FxCloseSet)>;
(FxOpenSet) e.Set1 (FxCloseSet) (FxOpenSet) e.Set2 (FxCloseSet) = ;
}
UnionSets {
(FxOpenSet s.Num) e.Set1 (FxCloseSet s.Num) (FxOpenSet s.Num) e.Set2 (FxCloseSet s.Num) =
(FxOpenSet s.Num) <Union (FxOpenSet) e.Set1 (FxCloseSet) (FxOpenSet) e.Set2 (FxCloseSet)> (FxCloseSet s.Num);
}
IntersectSets {
(FxOpenSet s.Num) e.Set1 (FxCloseSet s.Num) (FxOpenSet s.Num) e.Set2 (FxCloseSet s.Num) =
(FxOpenSet s.Num) <Intersect (FxOpenSet) e.Set1 (FxCloseSet) (FxOpenSet) e.Set2 (FxCloseSet)> (FxCloseSet s.Num);
}
Arithmetic {
e.Head (FxOpenSet s.Num1) e.Content1 (FxCloseSet s.Num1)
'*'
(FxOpenSet s.Num2) e.Content2 (FxCloseSet s.Num2) e.Tail =
<WriteLine 'Multiply step:'>
<WriteLine e.Head (FxOpenSet s.Num1) e.Content1 (FxCloseSet s.Num1) '*' (FxOpenSet s.Num2) e.Content2 (FxCloseSet s.Num2) e.Tail>
<Arithmetic e.Head
<IntersectSets (FxOpenSet s.Num1) e.Content1 (FxCloseSet s.Num1) (FxOpenSet s.Num1) e.Content2 (FxCloseSet s.Num1)> e.Tail>;
e.Head (FxOpenSet s.Num1) e.Content1 (FxCloseSet s.Num1)
'+'
(FxOpenSet s.Num2) e.Content2 (FxCloseSet s.Num2) e.Tail =
<WriteLine 'Summation step:'>
<WriteLine e.Head (FxOpenSet s.Num1) e.Content1 (FxCloseSet s.Num1) '+' (FxOpenSet s.Num2) e.Content2 (FxCloseSet s.Num2) e.Tail>
<Arithmetic e.Head
<UnionSets (FxOpenSet s.Num1) e.Content1 (FxCloseSet s.Num1) (FxOpenSet s.Num1) e.Content2 (FxCloseSet s.Num1)> e.Tail>;
e.Head (OpenBr s.Num) (FxOpenSet s.NumInner) e.SetContent (FxCloseSet s.numInner) (CloseBr s.Num) e.Tail =
<WriteLine 'Free from brackets step'>
<WriteLine e.Head (OpenBr s.Num) (FxOpenSet s.NumInner) e.SetContent (FxCloseSet s.numInner) (CloseBr s.Num) e.Tail>
<Arithmetic e.Head (FxOpenSet s.Num) e.SetContent (FxCloseSet s.Num) e.Tail>;
(FxOpenSet s.Num) e.Content (FxCloseSet s.Num) = (FxOpenSet s.Num) e.Content (FxCloseSet s.Num);
//e.All = e.All;
}
PairifyParens {
(Stack e.Stack) e.Head (LeftScanner s.Num) '(' e.Tail =
<PairifyParens (Stack e.Stack (s.Num)) e.Head (OpenBr s.Num) (LeftScanner <Inc s.Num>) e.Tail>;
(Stack e.Stack) e.Head (LeftScanner s.Num) '[' e.Tail =
<PairifyParens (Stack e.Stack (s.Num)) e.Head (OpenSet s.Num) (LeftScanner <Inc s.Num>) e.Tail>;
(Stack e.StackHead (s.Last)) e.Head (LeftScanner s.Num) ')' e.Tail =
<PairifyParens (Stack e.StackHead) e.Head (CloseBr s.Last) (LeftScanner s.Num) e.Tail>;
(Stack e.StackHead (s.Last)) e.Head (LeftScanner s.Num) ']' e.Tail =
<PairifyParens (Stack e.StackHead) e.Head (CloseSet s.Last) (LeftScanner s.Num) e.Tail>;
(Stack e.Stack) e.Head (LeftScanner s.Num) s.Other e.Tail =
<PairifyParens (Stack e.Stack) e.Head s.Other (LeftScanner s.Num) e.Tail>;
(Stack ) e.All (LeftScanner s.AllCount) =
e.All;
}
RemoveWhiteSpaces {
e.Head ' ' '+' e.Tail = <RemoveWhiteSpaces e.Head '+' e.Tail>;
e.Head '+' ' ' e.Tail = <RemoveWhiteSpaces e.Head '+' e.Tail>;
e.Head ' ' '*' e.Tail = <RemoveWhiteSpaces e.Head '*' e.Tail>;
e.Head '*' ' ' e.Tail = <RemoveWhiteSpaces e.Head '*' e.Tail>;
e.All = e.All;
}
DoWriteSetContent {
(e.Wrapped) s.Number e.Content =
<DoWriteSetContent (e.Wrapped (s.Number)) e.Content>;
(e.Wrapped) = e.Wrapped;
}
WrapSetContent {
e.Content = <DoWriteSetContent () e.Content>;
}
RemoveWhite {
e.Head ' ' e.Tail = <RemoveWhite e.Head e.Tail>;
e.Head '()' e.Tail = <RemoveWhite e.Head '([])' e.Tail>;
e.All = e.All;
}
NumbersToParens {
e.Head (OpenSet s.Num) e.SetContent (CloseSet s.Num) e.Tail =
<NumbersToParens e.Head (FxOpenSet s.Num) <WrapSetContent e.SetContent> (FxCloseSet s.Num) e.Tail>;
e.All = e.All;
}
$FORWARD Cmp;
DoSortedInsert {
(e.SortedList) (s.Num) () (s.Comparison) =
(e.SortedList (s.Num));
(e.SortedList) (s.Num) ((s.NextNum) e.Sorted) ('<') =
(e.SortedList (s.Num) (s.NextNum) e.Sorted);
(e.SortedList) (s.Num) ((s.NextNum) e.Sorted) ('=') =
(e.SortedList (s.Num) (s.NextNum) e.Sorted);
(e.SortedList) (s.Num) ((s.NextNum) (s.NextNext) e.Sorted) ('>') =
<DoSortedInsert (e.SortedList (s.NextNum)) (s.Num) ((s.NextNext) e.Sorted) (<Cmp (s.Num) (s.NextNext)>)>;
(e.SortedList) (s.Num) ((s.NextNum)) ('>') =
(e.SortedList (s.NextNum) (s.Num));
}
SortedInsert {
(s.Num) () = ((s.Num));
(s.Num) ((s.NextNum) e.Sorted) = <DoSortedInsert (/* list of sorted elements */) (s.Num) ((s.NextNum) e.Sorted) (<Cmp (s.Num) (s.NextNum)>)>;
}
Sort {
() (e.Sorted) = e.Sorted;
(e.Unsorted t.Sortable) (e.Sorted) = <Sort (e.Unsorted) <SortedInsert t.Sortable (e.Sorted)>>;
}
SetSort {
(FxOpenSet s.Num) e.Content (FxCloseSet s.Num) =
<WriteLine 'Unsorted: ' e.Content '||Sorted: ' <Sort (e.Content) ()>>
(FxOpenSet s.Num) <Sort (e.Content) ()> (FxCloseSet s.Num);
}
InvertCmpResult {
'<' = '>';
'=' = '=';
'>' = '<';
}
LenComp {
(s.Digit1 e.Seq1) (s.Digit2 e.Seq2) = <LenComp (e.Seq1) (e.Seq2)>;
(s.Digit1 e.Seq1) () = '>';
() (s.Digit2 e.Seq2) = '<';
() () = '=';
}
DoCmpRec {
(e.EqSeq1) (e.EqSeq2) ('<') = '<';
(e.EqSeq1) (e.EqSeq2) ('>') = '>';
(s.Digit1 e.EqSeq1) (s.Digit2 e.EqSeq2) ('=') = <DoCmpRec (e.EqSeq1) (e.EqSeq2) (<Compare (s.Digit1) (s.Digit2)>)>;
() () ('=') = '=';
}
DoCmp {
(e.Seq1) (e.Seq2) ('<') = '<';
(e.Seq1) (e.Seq2) ('>') = '>';
(e.Seq1) (e.Seq2) ('=') = <DoCmpRec (e.Seq1) (e.Seq2) ('=')>;
}
Cmp {
('-' e.Seq1) ('-' e.Seq2) = <InvertCmpResult <DoCmp (e.Seq1) (e.Seq2) (<LenComp (e.Seq1) (e.Seq2)>)>>;
('-' e.Seq1) (e.Seq2) = '<';
(e.Seq1) ('-' e.Seq2) = '<';
(e.Seq1) (e.Seq2) = <DoCmp (e.Seq1) (e.Seq2) (<LenComp (e.Seq1) (e.Seq2)>)>;
}
FilterCmp {
e.Num1 ' ' e.Num2 = <Cmp (e.Num1) (e.Num2)>;
}
UnpackNumbers {
(s.Number) = s.Number;
(s.Number) e.Packed =
s.Number ' ' <UnpackNumbers e.Packed>;
= ;
}
PrintSet {
(FxOpenSet s.Num) e.Content (FxCloseSet s.Num) =
<WriteLine '[' <UnpackNumbers e.Content> ']'>;
}
$ENTRY Go {
= <WriteLine
<PrintSet
<SetSort
<Arithmetic
<NumbersToParens
<PairifyParens
(Stack) (LeftScanner 0)
<RemoveWhiteSpaces
<RemoveWhite
<ReadLine>
>
>
>
>
>
>
>
>;
}