forked from salihdb/RhodeusScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommands.d
More file actions
1321 lines (1254 loc) · 42.7 KB
/
Commands.d
File metadata and controls
1321 lines (1254 loc) · 42.7 KB
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Rhodeus Script (c) by Talha Zekeriya Durmuş
Rhodeus Script is licensed under a
Creative Commons Attribution-NoDerivs 3.0 Unported License.
You should have received a copy of the license along with this
work. If not, see <http://creativecommons.org/licenses/by-nd/3.0/>.
*/
module Commands;
import pool;
import std.stdio;
import interpreter;
import std.conv;
import std.random ;
import std.string;
import std.array;
import std.format;
import std.algorithm;
import errorHandling.errorHandler;
public void setError(T...)(int ow, T args){
throw new RhError(ow, args);
}
string[] sign; //loop i
int*[] sign1; //loop i
int[] sign2; //loop max
int*[] sign3; //current command
int[] sign4; //max command
Command*[] sign5;
pool dataPool;
void linkIt(pool _pool){
dataPool = _pool;
}
class Command{
Command[] subs;
short typ;
uint line;
string type;
string value;
Command delegate (Command[], Command, dataManagement)[string] functions;
bool isIn(Command tl){ return 0;}
void opSet(Command a, Command b, dataManagement dM){}
this(string type){
this.type = type;
this.line = dataPool.line;
}
Command run(dataManagement dM){
if (subs.length==0) return this;
return locate(dM, this, subs);
}
override bool opEquals(Object T){
if (cast(Command) T is null) throw new Exception("Kontrol sadece 2 RhObject arasında yapılabilir.");
return false;
}
bool isEmpty(){return true;}
Command getMethod(string m, dataManagement dM){
throw new Exception(type ~ " veri türüne ait " ~ m ~ " alt fonksiyonu bulunmamaktadır.");
}
Command call(dataManagement dM, Command[] fonkParams){
throw new Exception(type~" veri türünü çağıramazsınız!");
}
Command opIndex(Command o){
throw new Exception(type~" veri türünün indeksine ulaşamazsınız.");
return new RhNone();
}
Command opIndexAssign(Command value, Command field){
throw new Exception(type~" veri türüne ait indexAssign bulunmamaktadır.");
}
override int opCmp(Object T){
return 0;
}
Command op(string operator, Command rhs, dataManagement dM=null){
final switch(operator){
case "+":
throw new Exception(type~" veri türünü "~rhs.type~" veri türüyle toplayamazsınız.");
case "*":
throw new Exception(type~" veri türünü "~rhs.type~" veri türüyle çarpamazsınız.");
case "/":
throw new Exception(type~" veri türünü "~rhs.type~" veri türüne bölemezsiniz.");
case "-":
throw new Exception(type~" veri türünü "~rhs.type~" veri türünden çıkartamazsınız.");
case "%":
throw new Exception(type~" veri türünü "~rhs.type~" veri türüne modunu alamazsınız.");
}
}
void setWop(string operator, Command rhs, dataManagement dM=null){
throw new Exception(type~" veri türü için "~operator~" operatörünü kullanamazsınız.");
}
}
class spec : Command{
this(string type, string value){
switch(type){
case "AO", "CO", "LO":
this.typ = 3;
break;
default:
break;
}
super(type);
this.value = value;
}
override Command run(dataManagement dM){
throw new Exception("Beklenmeyen karakter: '"~value~"'");
}
}
class RhWhile : Command{
Command condition;
Command[] codes;
this(Command condition, Command[] codes){
super("RhWhile");
this.condition = condition;
this.codes = codes;
}
override Command run(dataManagement dM){
int i;
Command cond;
sign ~= "while";
sign3~=&i;
sign4~=codes.length;
sign5~=&condition;
start:
cond = condition.run(dM);
if(cond is null || cond.isEmpty()) goto end;
for(i=0; i<codes.length; i++) codes[i].run(dM);
goto start;
end:
sign.length--;
sign3.length--;
sign4.length--;
sign5.length--;
return new RhNone();
}
}
class RhForeach : Command{
Command getIt;
string eqIt;
Command[] codes;
this(string eqIt, Command getIt, Command[] codes){
this.eqIt = eqIt;
this.getIt = getIt;
this.codes = codes;
super("RhForeach");
}
override Command run(dataManagement dM){
int i, i2, len;
Command ge = getIt.run(dM);
len = (cast(RhArray) ge).value.length;
start:
if (i2>=len) return null;
dM[eqIt] = (cast(RhArray) ge).value[i2];
i=0;
while(i<codes.length){
codes[i].run(dM);
i++;
}
i2++;
goto start;
return new RhNone();
}
}
class RhIf : Command{
RhIfS[] ifs;
this(RhIfS[] ifs){
this.ifs = ifs;
this.typ = 2;
super("RhIf");
}
override Command run(dataManagement dM){
int ix;
int i;
Command ret = new RhNone();
while(ix < ifs.length){
if(ifs[ix].cond is null){
i=0;
while(i<ifs[ix].codes.length){
ret = ifs[ix].codes[i].run(dM);
i++;
}break;
}else if(!ifs[ix].cond.run(dM).isEmpty()){
i=0;
while(i<ifs[ix].codes.length){
ret = ifs[ix].codes[i].run(dM);
i++;
}break;
}
ix++;
}
return ret;
}
}
class RhFor : Command{
Command a1, a2, a3;
Command[] codes;
this(Command a1,Command a2,Command a3, Command[] codes){
this.a1 = a1;
this.a2 = a2;
this.a3 = a3;
this.codes = codes;
super("RhFor");
}
override Command run(dataManagement dM){
int i;
Command cond;
a1.run(dM);
start:
cond = a2.run(dM);
if(cond is null || cond.isEmpty()) return null;
i=0;
while(i<codes.length){
codes[i].run(dM);
i++;
}
a3.run(dM);
goto start;
return new RhNone();
}
}
class RhArray : Command{
Command[] value;
bool t = true;
override bool isEmpty(){if(value.length==0) return true; else return false;}
override bool opEquals(Object T){
if (cast(RhArray) T is null) return false;
else if ((cast(RhArray) T ).value != this.value) return false;
return true;
}
override Command op(string operator, Command rhs, dataManagement dM=null){
final switch(operator){
case "+":
if(rhs.type=="ARRAY") return new RhArray(this.value ~ (cast(RhArray) rhs).value);
else throw new Exception(this.type~" veri türünü sadece ARRAY veri türüyle toplayabilirsiniz.");
case "*":
if(rhs.type=="INT") return new RhArray(this.value.replicate((cast(RhInt) rhs).value));
else throw new Exception(this.type~" veri türünü sadece INT veri türüyle toplayabilirsiniz.");
case "/":
if(rhs.type!="INT") throw new Exception(this.type~" veri türünü sadece INT veri türüyle toplayabilirsiniz.");
else if((cast(RhInt) rhs).value < 1) throw new Exception(this.type~" veri türünü 0 dan büyük bir rakama bölebilirsiniz.");
Command[] list;
for(int z; z<this.value.length; z+= (cast(RhInt) rhs).value)
if(z+(cast(RhInt) rhs).value > this.value.length)
list ~= new RhArray(this.value[z..$-1]);
else
list ~= new RhArray(this.value[z..z+(cast(RhInt) rhs).value]);
return new RhArray(list);
case "-":
throw new Exception(type~" veri türünü "~rhs.type~" veri türünden çıkartamazsınız.");
case "%":
throw new Exception(type~" veri türünü "~rhs.type~" veri türüne modunu alamazsınız.");
}
}
override int opCmp(Object T){
if (cast(RhArray) T is null) throw new Exception(type~" veri türüyle sadece "~type ~" veri türünü karşılaştırabilirsiniz.");
if(this.value > (cast(RhArray) T ).value) return 1;
else if(this.value < (cast(RhArray) T ).value) return -1;
return 0;
}
override Command opIndex(Command ri){
if (ri.type != "INT") throw new Exception("Indeks değeri olarak bir tam sayı bekleniyordu "~ri.type~" geldi.");
else if (value.length<=(cast(RhInt) ri).value) throw new Exception("Dizi uzunluğu: "~to!string(value.length)~". "~to!string((cast(RhInt) ri).value)~". indeksine ulaşamazsınız.");
else if ((cast(RhInt) ri).value < 0 ) throw new Exception("Dizi indeksi sıfırdan küçük olamaz.");
return this.value[(cast(RhInt) ri).value];
}
override Command opIndexAssign(Command value2, Command field){
if(field.type!="INT") throw new Exception("Indeks değeri olarak bir tam sayı bekleniyordu "~field.type~" geldi.");
else if (value.length<=(cast(RhInt) field).value) throw new Exception("Dizi uzunluğu: "~to!string(value.length)~". "~to!string((cast(RhInt) field).value)~". indeksine ulaşamazsınız.");
else if ((cast(RhInt) field).value < 0 ) throw new Exception("Dizi indeksi sıfırdan küçük olamaz.");
value[(cast(RhInt) field).value] = value2;
return null;
}
this(Command[] value = null){
this.functions = ["get": &get, "append": &append, "combine": &combine, "countValues": &countValues,
"getRandom": &getRandom, "search": &search
];
this.typ = 2;
this.value = value;
super("ARRAY");
}
override string toString(){
return to!string(value);
}
Command countValues(Command[] params,Command aktiv,dataManagement dM){
if(params.length != 0) throw new Exception("countValues işlemi için 0 parametre bekleniyordu!");
Command[string] temp;
string st;
for(int i = 0;i<(cast(RhArray)aktiv).value.length;i++){
st = (cast(RhArray) aktiv).value[i].toString();
if((st in temp) !is null)
(cast(RhInt) temp[st]).value++;
else
temp[st] = new RhInt(1);
}
return new RhDictionary(temp);
}
Command search(Command[] params,Command aktiv,dataManagement dM){
if(params.length != 1) throw new Exception("search işlemi için 1 parametre bekleniyordu!");
Command[string] temp;
Command t = params[0].run(dM);
for(int i = 0;i < value.length;i++){
if(params[0] == value[i])
return new RhInt(i);
}
return new RhInt(-1);
}
Command get(Command[] params,Command aktiv,dataManagement dM){
Command ri = params[0].run(dM);
return aktiv[ri];
}
Command getRandom(Command[] params,Command aktiv,dataManagement dM){
if(params.length > 1) throw new Exception("getRandom işlemi en fazla 1 parametre alabilir!");
int cur = 1;
if(params.length == 1){
if(params[0].type != "INT") throw new Exception("getRandom işlemi için INT bekleniyordu "~params[0].type~" geldi.");
else cur = (cast(RhInt) params[0]).value;
if(cur < 1) throw new Exception("getRandom işlemi için INT 0 dan büyük olmalıdır!");
else if(cur > (cast(RhArray) aktiv).value.length) throw new Exception("getRandom işlemi için INT dizi uzunluğundan büyük olamaz!");
}
Command[] liz;
foreach(elm; randomSample((cast(RhArray) aktiv).value, cur))
liz ~= elm;
return new RhArray(liz);
}
Command combine(Command[] params,Command aktiv,dataManagement dM){
if(params.length != 1) throw new Exception("combine işlemi için 1 parametre bekleniyordu!");
params[0] = params[0].run(dM);
if(params[0].type != "ARRAY") throw new Exception("combine işlemi için 1 parametre ARRAY türünde olmalıdır!");
Command[string] temp;
for(int i = 0;i < (cast(RhArray) aktiv).value.length;i++)
temp[( (cast(RhArray) aktiv).value[i]).toString()] = (cast(RhArray) params[0]).value[i];
return new RhDictionary(temp);
}
Command append(Command[] params,Command aktiv,dataManagement dM){
if(aktiv.type != "ARRAY") throw new Exception("Append işlemini sadece diziler için yapabilirsiniz.");
(cast(RhArray) aktiv).value ~= params[0].run(dM);
return aktiv;
}
override Command getMethod(string m, dataManagement dM){
switch(m){
case "str": return new RhString(to!string(value));
case "length": return new RhInt(value.length);
case "reverse": reverse(value); return this;
case "pop": value = value[0..$-1]; return value[$];
case "shift": value = value[1..$]; return *(&value[0] - 1);
default:
if (m in functions) return new dFunction(functions[m], this);
else throw new Exception(type ~ " tipine ait " ~ m ~ " alt fonksiyonu bulunmamaktadır.");
}
assert(0);
}
override Command run(dataManagement dM){
if (t) {for(int i=0; i<value.length; i++)value[i]=value[i].run(dM); t=false;}
return this;
}
}
class RhDictionary : Command{
Command[string] value;
bool t;
override bool isEmpty(){if(value.length==0) return true; else return false;}
override Command opIndex(Command ri){
if (ri.type != "STRING") throw new Exception("Anahtar değeri olarak bir metin bekleniyordu "~ri.type~" geldi.");
else if ((ri.value in value) is null) throw new Exception("Dizi içerisinde "~ri.value~" anahtarı bulunamadı.");
return this.value[ri.value];
}
override bool isIn(Command tl){
if(tl.value in value) return true;
return false;
}
override Command opIndexAssign(Command value2, Command field){
value[field.toString()] = value2;
return null;
}
this(Command[string] value = null){
this.functions = ["get": &get, "changeKeyCase": &changeKeyCase];
this.typ = 2;
this.value = value;
super("DICTIONARY");
}
Command[][] valueR;
this(Command[][] value){
this.functions = ["get": &get, "changeKeyCase": &changeKeyCase];
this.typ = 2;
super("DICTIONARY");
this.valueR = value;
this.t = true;
}
override string toString(){
return "{"~to!string(value)[1..$-1]~"}";
}
Command get(Command[] params,Command aktiv,dataManagement dM){
Command ri = params[0].run(dM);
return aktiv[ri];
}
Command changeKeyCase(Command[] params,Command aktiv,dataManagement dM){
if(params.length != 1) throw new Exception("changeKeyCase işlemi için 1 parametre bekleniyordu!");
else if(params[0].type != "STRING") throw new Exception("changeKeyCase işlemi için 1 parametre STRING türünde olmalıdır!");
Command[string] temp;
switch(params[0].value.toLower()){
case "upper": foreach(key, val;(cast(RhDictionary) aktiv).value) temp[key.toUpper()] = val; break;
case "lower": foreach(key, val;(cast(RhDictionary) aktiv).value) temp[key.toLower()] = val; break;
default: throw new Exception("changeKeyCase işlemi için sadece lower ve upper komutlarını kullanabilirsiniz!");
}
(cast(RhDictionary) aktiv).value = temp;
return new RhBool(true);
}
override Command getMethod(string m, dataManagement dM){
switch(m){
case "str": return new RhString(to!string(value));
case "length": return new RhInt(value.length);
default:
if (m in functions) return new dFunction(functions[m], this);
else throw new Exception(type ~ " tipine ait " ~ m ~ " alt fonksiyonu bulunmamaktadır.");
}
assert(0);
}
override Command run(dataManagement dM){
if (t) {
foreach(valueL; valueR){
value[valueL[0].run(dM).toString()]=valueL[1].run(dM);
}
t=false;
}
return this;
}
}
class RhCodeArea : Command{
Command[] value;
dataManagement cdM;
this(Command[] value){
this.value = value;
super("getParacodes");
this.functions = ["define": &define];
cdM = new dataManagement();
}
Command define(Command[] params,Command aktiv,dataManagement dM){
cdM[params[0].run(dM).value] = params[1].run(dM);
return this;
}
override Command getMethod(string m, dataManagement dM){
switch(m){
case "run":
cdM._root = dM;
foreach(val;value) val.run(cdM);
return new RhNone();
case "length": return new RhInt(value.length);
default:
if (m in functions) return new dFunction(functions[m], this);
else throw new Exception(type ~ " tipine ait " ~ m ~ " alt fonksiyonu bulunmamaktadır.");
}
assert(0);
}
Command runTimes(int zz, int* z, dataManagement dM){
start:
if (*z == zz) goto end;
foreach(val;value) val.run(dM);
(*z)++;
goto start;
end:
return null;
}
}
class RhInt : Command{
int value;
override bool isEmpty(){if(value==0) return true; else return false;}
override int opCmp(Object T){
if (cast(RhInt) T is null) throw new Exception(type~" veri türüyle sadece "~type ~" veri türünü karşılaştırabilirsiniz.");
return this.value - (cast(RhInt) T ).value;
}
override bool opEquals(Object T){
if (cast(RhInt) T is null) return false;
else if ((cast(RhInt) T ).value != this.value) return false;
return true;
}
override Command getMethod(string m, dataManagement dM){
switch(m){
case "str": return new RhString(to!string(value));
case "length": return new RhInt(to!string(value).length);
default:
if (m in functions) return new dFunction(functions[m], this);
else throw new Exception(type ~ " tipine ait " ~ m ~ " alt fonksiyonu bulunmamaktadır.");
}
assert(0);
}
override void setWop(string operator, Command rhs, dataManagement dM=null){
final switch(operator){
case "-":
if(rhs.type=="INT") this.value -= (cast(RhInt) rhs).value;
else if(rhs.type=="FLOAT") this.value -= (cast(RhFloat) rhs).value;
else throw new Exception(this.type~" veri türünü sadece Int veya Float türünden çıkartabilirsiniz.");
break;
case "+":
if(rhs.type=="INT") this.value += (cast(RhInt) rhs).value;
else if(rhs.type=="FLOAT") this.value += (cast(RhFloat) rhs).value;
else throw new Exception(this.type~" veri türünü sadece Int veya Float türüyle toplayabilirsiniz.");
break;
case "/":
if(rhs.type=="INT") this.value /= (cast(RhInt) rhs).value;
else if(rhs.type=="FLOAT") this.value /= (cast(RhFloat) rhs).value;
else throw new Exception(this.type~" veri türünü sadece Int veya Float türüne bölebilirsiniz.");
break;
case "*":
if(rhs.type=="INT") this.value *= (cast(RhInt) rhs).value;
else if(rhs.type=="FLOAT") this.value *= (cast(RhFloat) rhs).value;
else throw new Exception(this.type~" veri türünü sadece Int veya Float türüyle çarpabilirsiniz.");
break;
case "%":
if(rhs.type=="INT") this.value %= (cast(RhInt) rhs).value;
else if(rhs.type=="FLOAT") this.value %= (cast(RhFloat) rhs).value;
else throw new Exception(this.type~" veri türünü sadece Int veya Float türüne mod alabilirsiniz.");
break;
}
}
override Command op(string operator, Command rhs, dataManagement dM=null){
final switch(operator){
case "+":
if(rhs.type=="INT") return new RhInt(this.value + (cast(RhInt) rhs).value);
else if(rhs.type=="FLOAT") return new RhFloat(this.value + (cast(RhFloat) rhs).value);
else throw new Exception(this.type~" veri türünü sadece Int veya Float türüyle toplayabilirsiniz.");
case "*":
if(rhs.type=="INT") return new RhInt(this.value * (cast(RhInt) rhs).value);
else if(rhs.type=="FLOAT") return new RhFloat(this.value * (cast(RhFloat) rhs).value);
else throw new Exception(this.type~" veri türünü sadece Int veya Float türüyle çarpabilirsiniz.");
case "/":
if(rhs.type=="INT") return new RhInt(this.value / (cast(RhInt) rhs).value );
else if(rhs.type=="FLOAT") return new RhFloat(this.value/ (cast(RhFloat) rhs).value);
else throw new Exception(this.type~" veri türünü sadece Int veya Float türüne bölebilirsiniz.");
case "-":
if(rhs.type=="INT") return new RhInt(this.value - (cast(RhInt) rhs).value);
else if(rhs.type=="FLOAT") return new RhFloat(this.value - (cast(RhFloat) rhs).value);
else throw new Exception(this.type~" veri türünü sadece Int veya Float türünden çıkartabilirsiniz.");
case "%":
if(rhs.type=="INT") return new RhInt(this.value % (cast(RhInt) rhs).value);
else if(rhs.type=="FLOAT") return new RhFloat(this.value % (cast(RhFloat) rhs).value);
else throw new Exception(this.type~" veri türünü sadece Int veya Float türüne modunu alabilirsiniz.");
}
}
this(int value){
this.typ = 1;
this.value = value;
super("INT");
this.functions = ["times": ×];
}
Command times(Command[] params,Command aktiv,dataManagement dM){
int zz = (cast(RhInt) aktiv).value;
dM[params[0].value] = new RhInt(0);
(cast(RhCodeArea) params[1]).runTimes(zz, &(cast(RhInt) dM[params[0].value]).value, dM);
return null;
}
override string toString(){
return to!string(value);
}
}
class RhFloat : Command{
float value;
override int opCmp(Object T){
if (cast(RhFloat) T is null) throw new Exception(type~" veri türüyle sadece "~type ~" veri türünü karşılaştırabilirsiniz.");
if(this.value - (cast(RhFloat) T ).value > 0){
return 1;
}else if(this.value - (cast(RhFloat) T ).value < 0){
return -1;
}
return 0;
}
override bool opEquals(Object T){
if (cast(RhFloat) T is null) return false;
else if ((cast(RhFloat) T ).value != this.value) return false;
return true;
}
override bool isEmpty(){if(value==0) return true; else return false;}
override string toString(){
return to!string(value);
}
override Command op(string operator, Command rhs, dataManagement dM=null){
final switch(operator){
case "+":
if(rhs.type=="INT") return new RhFloat(this.value + (cast(RhInt) rhs).value);
else if(rhs.type=="FLOAT") return new RhFloat(this.value + (cast(RhFloat) rhs).value);
else throw new Exception(this.type~" veri türünü sadece Int veya Float türüyle toplayabilirsiniz.");
case "*":
if(rhs.type=="INT") return new RhFloat(this.value * (cast(RhInt) rhs).value);
else if(rhs.type=="FLOAT") return new RhFloat(this.value * (cast(RhFloat) rhs).value);
else throw new Exception(this.type~" veri türünü sadece Int veya Float türüyle çarpabilirsiniz.");
case "/":
if(rhs.type=="INT") return new RhFloat(this.value / (cast(RhInt) rhs).value);
else if(rhs.type=="FLOAT") return new RhFloat(this.value/ (cast(RhFloat) rhs).value);
else throw new Exception(this.type~" veri türünü sadece Int veya Float türüne bölebilirsiniz.");
case "-":
if(rhs.type=="INT") return new RhFloat(this.value - (cast(RhInt) rhs).value);
else if(rhs.type=="FLOAT") return new RhFloat(this.value - (cast(RhFloat) rhs).value);
else throw new Exception(this.type~" veri türünü sadece Int veya Float türünden çıkartabilirsiniz.");
case "%":
if(rhs.type=="INT") return new RhFloat(this.value % (cast(RhInt) rhs).value);
else if(rhs.type=="FLOAT") return new RhFloat(this.value % (cast(RhFloat) rhs).value);
else throw new Exception(this.type~" veri türünü sadece Int veya Float türüne modunu alabilirsiniz.");
}
}
this(float value){
this.typ = 1;
this.value = value;
super("FLOAT");
}
}
class RhString : Command{
override bool isEmpty(){if(value.length==0) return true; else return false;}
override void setWop(string operator, Command rhs, dataManagement dM=null){
final switch(operator){
case "+":
if(cast(RhString) rhs is null) throw new Exception("String'i sadece String ile toplayabilirsiniz.");
this.value ~= rhs.value;
break;
case "*":
if(cast(RhInt) rhs is null) throw new Exception("String'i sadece Int ile çarpabilirsiniz.");
this.value = std.array.replicate(this.value, (cast(RhInt) rhs).value);
break;
case "/":
throw new Exception(type~" veri türünü "~rhs.type~" veri türüne bölemezsiniz.");
case "-":
throw new Exception(type~" veri türünü "~rhs.type~" veri türünden çıkartamazsınız.");
case "%":
throw new Exception(type~" veri türünü "~rhs.type~" veri türüne modunu alamazsınız.");
}
}
override bool opEquals(Object T){
if (cast(RhString) T is null) return false;
else if ((cast(RhString) T ).value != this.value) return false;
return true;
}
override string toString(){
return value;
}
Command format(Command[] params,Command aktiv,dataManagement dM){
//Ali Çehreli hocama teşekkürler 26.12.2012
//http://ddili.org/forum/post/8379
auto düzen = FormatSpec!char(aktiv.toString());
auto yazıcı = appender!string;
string[] strl;
foreach(param; params){
strl ~= param.run(dM).toString();
}
foreach (i, değer; strl) {
if(!düzen.writeUpToNextSpec(yazıcı)) throw new Exception("Şu değer(ler) için belirteç bulunamadı:", text(strl[i..$]));
formatValue(yazıcı, değer, düzen);
}
if(düzen.writeUpToNextSpec(yazıcı)){
throw new Exception("Fazladan düzen belirteci bulundu");
}
return new RhString(yazıcı.data);
}
Command replace(Command[] params,Command aktiv,dataManagement dM){
return new RhString(std.array.replace(aktiv.value, params[0].run(dM).toString(), params[1].run(dM).toString()));
}
Command indexOf(Command[] params,Command aktiv,dataManagement dM){
if(params.length == 0) throw new Exception("indexOf fonksiyonu 2 parametre alıyor. (1 opsiyonel)");
else if(params.length > 2) throw new Exception("indexOf fonksiyonu 2 parametreden fazla parametre alamaz.");
CaseSensitive boo = CaseSensitive.yes;
if (params.length == 2 && !(cast(RhBool) params[1].run(dM)).value) boo = CaseSensitive.no;
return new RhInt(value.indexOf(params[0].run(dM).toString(), boo));
}
Command splitLines(Command[] params,Command aktiv,dataManagement dM){
if(params.length > 1) throw new Exception("indexOf fonksiyonu 1 parametreden fazla parametre alamaz.");
KeepTerminator boo = KeepTerminator.no;
if (params.length == 1 && (cast(RhBool) params[1].run(dM)).value) boo = KeepTerminator.yes;
Command list[];
foreach(x;value.splitLines(boo)){
list ~= new RhString(x);
}
return new RhArray(list);
}
Command lastIndexOf(Command[] params,Command aktiv,dataManagement dM){
if(params.length == 0) throw new Exception("indexOf fonksiyonu 2 parametre alıyor. (1 opsiyonel)");
else if(params.length > 2) throw new Exception("indexOf fonksiyonu 2 parametreden fazla parametre alamaz.");
CaseSensitive boo = CaseSensitive.yes;
if (params.length == 2 && !(cast(RhBool) params[1].run(dM)).value) boo = CaseSensitive.no;
return new RhInt(value.lastIndexOf(params[0].run(dM).toString(), boo));
}
override Command getMethod(string m, dataManagement dM){
switch(m){
case "str": return this;
case "length": return new RhInt(value.length);
case "lower": return new RhString(value.toLower());
case "upper": return new RhString(value.toUpper());
case "capitalize": return new RhString(value.capitalize());
case "strip": return new RhString(value.strip());
case "stripLeft": return new RhString(value.stripLeft());
case "stripRight": return new RhString(value.stripRight());
default:
if (m in functions) return new dFunction(functions[m], this);
else throw new Exception(type ~ " tipine ait " ~ m ~ " alt fonksiyonu bulunmamaktadır.");
}
assert(0);
}
override Command op(string operator, Command rhs, dataManagement dM=null){
final switch(operator){
case "+":
if(cast(RhString)rhs is null) throw new Exception("String'i sadece String ile toplayabilirsiniz.");
return new RhString(this.value ~ rhs.value);
case "*":
if(cast(RhInt) rhs is null) throw new Exception("String'i sadece Int ile çarpabilirsiniz.");
return new RhString(std.array.replicate(this.value, (cast(RhInt) rhs).value));
case "/":
throw new Exception(type~" veri türünü "~rhs.type~" veri türüne bölemezsiniz.");
case "-":
throw new Exception(type~" veri türünü "~rhs.type~" veri türünden çıkartamazsınız.");
case "%":
throw new Exception(type~" veri türünü "~rhs.type~" veri türüne modunu alamazsınız.");
}
}
this(string value){
this.functions = ["replace": &replace, "format": &format, "indexOf": &indexOf, "lastIndexOf": &lastIndexOf, "splitLines": &splitLines];
this.value = value;
super("STRING");
this.typ = 2;
}
}
class htmlprint : Command{
this(string html){
super("TYPE");
this.value = html;
}
public:
override Command run(dataManagement dM){
dataPool.html~= value;
return null;
}
}
Command _calc(Command[] rpn){
if(rpn.length==1) return rpn[0];
else return new calculate(rpn);
}
Command _calc2(Command[] rpn){
if(rpn.length==1) return rpn[0];
else return new calc(rpn);
}
class calculate : Command{//logic, comparing
Command[] rpn;
this(Command[] rpn){
super("CALCULATE");
this.rpn = rpn;
}
override Command run(dataManagement dM){
if(rpn.length==1) return rpn[0].run(dM);
Command rt1x = rpn[0].run(dM);
Command rt2x;
Command sonuc;
RhBool boo = new RhBool(true);
Command[] list;
int ilm;
bool wh = true;
while(rpn.length>ilm+2 && wh){
rt2x = rpn[ilm+2].run(dM);
final switch(rpn[ilm+1].value){
case "and":
if(rt1x.isEmpty()){ sonuc=rt1x; wh = false;}
else rt1x = sonuc= rpn[ilm+2].run(dM);
break;
case "or":
if(rt1x.isEmpty()) rt1x = sonuc= rpn[ilm+2].run(dM);
else{sonuc=rt1x; wh = false;}
break;
case "==": wh = boo.value = rt1x == rt2x; sonuc=boo; break;
case "!=": wh = boo.value = rt1x != rt2x; sonuc=boo; break;
case ">": wh = boo.value = rt1x > rt2x; sonuc=boo; break;
case "<": wh = boo.value = rt1x < rt2x; sonuc=boo; break;
case "<=": wh = boo.value = rt1x <= rt2x; sonuc=boo; break;
case ">=": wh = boo.value = rt1x >= rt2x; sonuc=boo; break;
case "in": wh = boo.value = rt2x.isIn(rt1x); sonuc=boo; break;
}
ilm+=2;
}
return sonuc;
}
}
class calc : Command{//Arithmetic
Command[] rpn;
this(Command[] rpn){
super("CALC");
this.rpn = rpn;
}
override Command run(dataManagement dM){
if(rpn.length==1) return rpn[0].run(dM);
Command[] list;
foreach(rp; rpn){
if (rp.type == "AO"){
list[$-2] = list[$-2].run(dM).op(rp.value, list[$-1].run(dM), dM);
list = list[0..$-1];
}else list ~= rp;
}
return list[0];
}
}
class dFunction : Command{
Command delegate (Command[], Command, dataManagement) dF;
Command sub;
this(Command delegate (Command[], Command, dataManagement) dF, Command sub = null){
this.sub = sub;
super("dFunction");
this.dF = dF;
}
override Command call(dataManagement dM, Command[] z){
return dF(z, sub, dM);
}
}
class word : Command{
this(string name){
this.value = name;
this.typ = 2;
super("WORD");
}
override Command run(dataManagement dM){
if (subs.length==0) return dM.get(value, true);
return locate(dM, dM.get(value, true), subs);
}
}
Command locate(dataManagement dM, Command aktivp, Command[] locs){
foreach(loc;locs){
aktivp = (cast(subOrder) loc).run(aktivp,dM);
}
return aktivp;
}
class subOrder : Command{
this(string type){
super(type);
}
Command run(Command var, dataManagement dM){
return var;
}
}
class getSubF : subOrder{
this(string value){
super("getSubF");
this.value = value;
}
override void opSet(Command a, Command b, dataManagement dM){
(cast(RhClassC) a).codes[value] = b;
}
override Command run(Command var, dataManagement dM){
return var.getMethod(value, dM);
}
}
class getIndex : subOrder{
Command value;
this(Command value){
super("getIndex");
this.value = value;
}
override void opSet(Command z, Command h, dataManagement dM){
z[value.run(dM)] = h;
}
override Command run(Command var, dataManagement dM){
return var[value.run(dM)];
}
}
class callIt : subOrder{
Command[] params;
this(Command[] params){
super("CallIt");
this.params = params;
}
override Command run(Command var, dataManagement dM){
return (var).call(dM, params);
}
}
class RhNone : Command{
this(){
super("NONE");
this.typ = 2;
}
override string toString(){
return "none";
}
}
class RhBool : Command{
bool value;
this(bool value){
super("BOOL");
this.value = value;
this.typ = 2;
}
Command set(bool value){
this.value=value;
return this;
}
override bool isEmpty(){return !value;}
override string toString(){
if (value) return "True"; else return "False";
}
}
struct RhParameter{
int lev;
string variable;
Command equal;
}
class RhClass : Command{
override Command op(string operator, Command rhs, dataManagement dM=null){
final switch(operator){
case "+":
throw new Exception(type~" veri türünü "~rhs.type~" veri türüyle toplayamazsınız.");
case "*":
throw new Exception(type~" veri türünü "~rhs.type~" veri türüyle çarpamazsınız.");
case "/":
throw new Exception(type~" veri türünü "~rhs.type~" veri türüne bölemezsiniz.");
case "-":
throw new Exception(type~" veri türünü "~rhs.type~" veri türünden çıkartamazsınız.");
case "%":
throw new Exception(type~" veri türünü "~rhs.type~" veri türüne modunu alamazsınız.");
}
}
override string toString(){
return "<"~value~" sınıfı>";
}
override Command opIndex(Command s){
throw new Exception(value ~ " sınıfının indeksine ulaşamazsınız. Belki de opIndex kullanmak istiyorsunuzdur?");
}
this(string value, Command[string] codes, string fatherName = ""){
this.fatherName = fatherName;
this.codes=codes;
this.value=value;
super("RhClass");
}
override Command run(dataManagement dM){
if(tanim== 0){
if (dM.hasKey(value)) setError(1014, value);
else if(fatherName!=""){
if ((this.father = cast(RhClass) dM.get(fatherName)) is null){
setError(1037);
}
}
dM[value] = this;
tanim++;
}
return null;
}
override Command getMethod(string m, dataManagement dM){
switch(m){
case "name": return new RhString(value);
default:
throw new Exception(type ~ " tipine ait " ~ m ~ " alt fonksiyonu bulunmamaktadır.");
}
assert(0);
}
override Command call(dataManagement dM, Command[] fonkParams){
return new RhClassC(value, fonkParams, codes, father, dM);
}
public:
string fatherName;
Command[string] codes;
int tanim;
RhClass father;
}