forked from amtuazon4/PyGUI
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck_semantics.py
More file actions
2091 lines (1783 loc) · 104 KB
/
Copy pathcheck_semantics.py
File metadata and controls
2091 lines (1783 loc) · 104 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
# Semantics Analyzer Implementation
import grab_lexeme
import re
from operator import xor
from tkinter import simpledialog
import copy
import math
lexemeArr = []
operations_arr = ["SUM OF", "DIFF OF", "PRODUKT OF",
"QUOSHUNT OF", "MOD OF", "BIGGR OF", "SMALLR OF", "BOTH SAEM", "DIFFRINT", "NOT", "BOTH OF", "EITHER OF", "WON OF", "ALL OF", "ANY OF"]
arithmetic_arr = ["SUM OF", "DIFF OF", "PRODUKT OF",
"QUOSHUNT OF", "MOD OF", "BIGGR OF", "SMALLR OF"]
comparison_arr = ["BOTH SAEM", "DIFFRINT"]
boolean_arr = ["BOTH OF", "EITHER OF", "WON OF"]
boolean_start = ["ALL OF", "ANY OF"]
datatypes_arr = ["NUMBR Literal", "NUMBAR Literal",
"YARN Literal", "TROOF Literal", "NOOB"]
def get_input(value):
input_promt = "Input value of " + value + " :"
x = simpledialog.askstring(title="GIMMEH", prompt=input_promt)
if len(x) == 0:
x = x.replace(x, "\"\"")
return [x, "YARN Literal"]
def print_symbolTable(symbolTable):
for i in symbolTable:
print(i)
def grab_identifiers(symbolTable):
identifiers = []
for i in symbolTable:
identifiers.append(i[0])
return identifiers
def truncate(number, digits):
nbDecimals = len(str(number).split('.')[1])
if nbDecimals <= digits:
return number
stepper = 10.0 ** digits
return math.trunc(stepper * number) / stepper
def insertInSymbolTable(symbolTable, new_identifier, new_value, data_type):
print("Adding " + new_identifier + "")
if new_identifier not in grab_identifiers(symbolTable):
symbolTable.append([new_identifier, new_value, data_type])
else:
dupIndex = grab_identifiers(symbolTable).index(
new_identifier)
del symbolTable[dupIndex]
symbolTable.insert(
dupIndex, [new_identifier, new_value, data_type])
def findValue(symbolTable, identifier):
for i in range(len(symbolTable)):
if symbolTable[i][0] == identifier:
# return value and identifier
return [symbolTable[i][1], symbolTable[i][2]]
return False
def boolean_not(value1, type1):
if type1 == "TROOF Literal":
if value1 == "WIN":
value1 = 1
else:
value1 = 0
elif type1 != "TROOF Literal":
if value1 == "\"\"":
value1 = 0
elif int(value1) == 0:
value1 = 0
else:
value1 = 1
print("Not", value1)
if value1 == 0:
return [True, "WIN", "TROOF Literal"]
else:
return [True, "FAIL", "TROOF Literal"]
def boolean_op(value1, type1, value2, type2, op):
# The empty string (“”) and numerical zero values are cast to FAIL.
# All other values, except those mentioned above, are cast to WIN.
print("Initial v1", value1)
print("Initial v2", value2)
# typecast to TROOF
if type1 == "TROOF Literal":
if value1 == "WIN":
value1 = 1
else:
value1 = 0
if type2 == "TROOF Literal":
if value2 == "WIN":
value2 = 1
else:
value2 = 0
if type1 != "TROOF Literal":
if value1 == "\"\"":
value1 = 0
elif int(value1) == 0:
value1 = 0
else:
value1 = 1
type1 = type1.replace(type1, "TROOF Literal")
if type2 != "TROOF Literal":
if value2 == "\"\"":
value2 = 0
elif int(value2) == 0:
value2 = 0
else:
value2 = 1
print("Value2", value2)
type2 = type2.replace(type2, "TROOF Literal")
print(value1, "vs", value2)
if op == "BOTH OF":
result = value1 and value2
print("Result:", result)
if result == 1:
return [True, "WIN", "TROOF Literal"]
else:
return [True, "FAIL", "TROOF Literal"]
elif op == "EITHER OF":
result = value1 or value2
if result == 1:
return [True, "WIN", "TROOF Literal"]
else:
return [True, "FAIL", "TROOF Literal"]
elif op == "WON OF":
result = xor(bool(value1), bool(value2))
if result == 1:
return [True, "WIN", "TROOF Literal"]
else:
return [True, "FAIL", "TROOF Literal"]
def comparison_op(value1, type1, value2, type2, op):
# there is no typecasting for BOTH SAEM and DIFFRINT
error_prompt = ""
result_type = ""
# if type1 not in ["NUMBR Literal", "NUMBAR Literal"]:
# print("HEREEEEEEEEEEEEEEEEEE 1")
# errorPrompt = "SemanticsError: no automatic typecast of " + \
# str(type1) + " \"" + str(value1) + \
# "\" to NUMBR Literal/NUMBAR Literal"
# print(errorPrompt)
# return [False, errorPrompt]
# if type2 not in ["NUMBR Literal", "NUMBAR Literal"]:
# print("HEREEEEEEEEEEEEEEEEEE 2")
# errorPrompt = "SemanticsError: no automatic typecast of " + \
# str(type2) + " \"" + str(value2) + \
# "\" to NUMBR Literal/NUMBAR Literal"
# print(errorPrompt)
# return [False, errorPrompt]
if type1 != type2:
errorPrompt = "SemanticsError: no automatic typecast for " + \
str(type1) + " \'" + str(value1) + "\' and " + \
str(type2) + " \'" + str(value2) + "\'"
print(errorPrompt)
return [False, errorPrompt]
else:
if type1 == "NUMBR Literal":
value1 = int(value1)
value2 = int(value2)
else:
value1 = float(value1)
value2 = float(value2)
if op == "BOTH SAEM":
if value1 == value2:
return [True, "WIN", "TROOF Literal"]
else:
return [True, "FAIL", "TROOF Literal"]
elif op == "DIFFRINT":
if value1 != value2:
return [True, "WIN", "TROOF Literal"]
else:
return [True, "FAIL", "TROOF Literal"]
def arithmetic_op(value1, type1, value2, type2, op):
# check string. If possible, typecast
errorPrompt = ""
if type1 == "YARN Literal":
if (re.search('(^[0-9]+$)', value1)):
value1 = int(value1)
type1 = type1.replace(type1, "NUMBR Literal")
elif (re.search('(^-?\d*\.(\d)+$)', value1)):
value1 = float(value1)
type1 = type1.replace(type1, "NUMBAR Literal")
else:
errorPrompt = "SemanticsError: invalid implicit typecast of " + \
str(value1) + " to NUMBR/NUMBAR Literal"
print(errorPrompt)
return [False, errorPrompt]
if type2 == "YARN Literal":
if (re.search('(^[0-9]+$)', value2)):
value2 = int(value2)
type2 = type2.replace(type2, "NUMBR Literal")
elif (re.search('(^-?\d*\.(\d)+$)', value2)):
value2 = float(value2)
type2 = type2.replace(type2, "NUMBAR Literal")
else:
errorPrompt = "SemanticsError: invalid implicit typecast of " + \
str(value2) + " to NUMBR/NUMBAR Literal"
print(errorPrompt)
return [False, errorPrompt]
# typecast to TROOF to numerical
if type1 == "TROOF Literal":
if value1 == "WIN":
value1 = 1
else:
value1 = 0
type1 = type1.replace(type1, "NUMBR Literal")
if type2 == "TROOF Literal":
if value2 == "WIN":
value2 = 1
else:
value2 = 0
type2 = type2.replace(type2, "NUMBR Literal")
# typecast NOOB to numerical
if type1 == "NOOB":
# The empty string (“”) and numerical zero values are cast to FAIL.
if value1 == "" or value1 == 0: # convert value1 to TROOF equivalent
value1 = 0 # FAIL = 0
else:
value1 = 1 # WIN = 1
type1 = type1.replace(type1, "NUMBR Literal")
if type2 == "NOOB":
if value2 == "" or value2 == 0: # convert value1 to TROOF equivalent
value2 = 0 # FAIL = 0
else:
value2 = 1 # WIN = 1
type2 = type2.replace(type2, "NUMBR Literal")
# compare the two data types
result_type = ""
if type1 == type2:
if type1 == "NUMBR Literal":
value1 = int(value1)
value2 = int(value2)
result_type = "NUMBR Literal"
elif type1 == "NUMBAR Literal":
value1 = float(value1)
value2 = float(value2)
result_type = "NUMBAR Literal"
else:
value1 = float(value1)
value2 = float(value2)
result_type = "NUMBAR Literal"
# compute with the final data types
if op == "SUM OF":
return [True, value1 + value2, result_type]
elif op == "DIFF OF":
return [True, value1 - value2, result_type]
elif op == "PRODUKT OF":
return [True, value1 * value2, result_type]
elif op == "QUOSHUNT OF":
result = value1 / value2
if value1 % value2 != 0:
return [True, result, "NUMBAR Literal"]
else:
return [True, int(result), result_type]
elif op == "MOD OF":
return [True, value1 % value2, result_type]
elif op == "BIGGR OF":
return [True, max(value1, value2), result_type]
elif op == "SMALLR OF":
return [True, min(value1, value2), result_type]
def typecast(prevVal, prevType, newType):
newType = newType.replace(newType, newType + " Literal")
newValue = copy.deepcopy(prevVal)
if prevType == "NUMBR Literal":
prevVal = int(prevVal)
if newType == "NUMBAR Literal":
newValue = float(prevVal)
elif newType == "TROOF Literal":
if prevVal == 0:
newValue = "FAIL"
else:
newValue = "WIN"
elif newType == "YARN Literal":
newValue = str(prevVal)
elif prevType == "NUMBAR Literal":
prevVal = float(prevVal)
if newType == "NUMBR Literal":
newValue = int(prevVal)
elif newType == "TROOF Literal":
if prevVal == 0.0:
newValue = "FAIL"
else:
newValue = "WIN"
elif newType == "YARN Literal":
# casting NUMBARs to YARN will truncate the decimal portion up to two decimal places.
return [True, truncate(prevVal, 2), newType]
elif prevType == "TROOF Literal":
if newType == "NUMBR Literal":
if prevVal == "FAIL":
return [True, 0, newType]
elif prevVal == "WIN":
return [True, 1, newType]
if newType == "NUMBAR Literal":
if prevVal == "FAIL":
return [True, 0, newType]
elif prevVal == "WIN":
return [True, 1.0, newType]
if newType == "YARN Literal":
return [True, prevVal, newType]
elif prevType == "YARN Literal":
if newType == "NUMBR Literal":
if (re.search('(^[0-9]+$)', prevVal)):
return [True, int(prevVal), newType]
elif (re.search('(^-?\d*\.(\d)+$)', prevVal)):
prevValFloat = float(prevVal)
# prevValInt = prevValFoat - (prevValFoat % 0.01)
return [True, int(prevValFloat), newType]
else:
error_prompt = "SemanticsError: cannot typecast " + \
str(prevVal) + " to NUMBR Literal"
return [False, error_prompt]
if newType == "NUMBAR Literal":
if (re.search('(^-?\d*\.(\d)+$)', prevVal)) or (re.search('(^[0-9]+$)', prevVal)):
return [True, float(prevVal), newType]
else:
error_prompt = "SemanticsError: cannot typecast " + \
str(prevVal) + " to NUMBAR Literal"
return [False, error_prompt]
if newType == "TROOF Literal":
if prevVal == "\"\"" or prevVal == "0":
return [True, "FAIL", newType]
else:
return [True, "WIN", newType]
return [True, newValue, newType]
def smoosh(datatypes_arr, to_eval_list):
print("====================START OF SMOOOOOOSH=======================")
global operations_arr
global arithmetic_arr
global comparison_arr
global boolean_arr
global boolean_start
global output_arr
global symbolTable
global error_prompt
# evaluate all expressions inside first
while (True):
change = False
for index, i in enumerate(to_eval_list):
if i[0] == "NOT" and (index + 1) < len(to_eval_list):
if to_eval_list[index+1][1] in datatypes_arr:
evaluated = boolean_not(
to_eval_list[index+1][0], to_eval_list[index+1][1])
if evaluated[0] != False:
del to_eval_list[(index):(index+2)]
print("---Before-----")
print(to_eval_list)
to_eval_list.insert(index, evaluated[1:3])
print("---After-----")
print(to_eval_list)
change = True
else:
output_arr.append(evaluated[1])
return [False, error_prompt, symbolTable, output_arr]
if i[0] in operations_arr and (index + 3) < len(to_eval_list):
if to_eval_list[index+1][1] in datatypes_arr and to_eval_list[index+2][0] == "AN" and to_eval_list[index+3][1] in datatypes_arr:
if i[0] in arithmetic_arr: # check if to peform arithmetic
evaluated = arithmetic_op(
to_eval_list[index+1][0], to_eval_list[index+1][1], to_eval_list[index+3][0], to_eval_list[index+3][1], i[0])
elif i[0] in comparison_arr: # check if to perform comparison
evaluated = comparison_op(
to_eval_list[index+1][0], to_eval_list[index+1][1], to_eval_list[index+3][0], to_eval_list[index+3][1], i[0])
elif i[0] in boolean_arr: # check if to perform boolean
evaluated = boolean_op(
to_eval_list[index+1][0], to_eval_list[index+1][1], to_eval_list[index+3][0], to_eval_list[index+3][1], i[0])
print("EVALUATED: ")
print(evaluated)
if evaluated[0] != False:
del to_eval_list[(index):(index+4)]
to_eval_list.insert(
index, evaluated[1:3])
print("NEW")
print(to_eval_list)
change = True
else:
output_arr.append(evaluated[1])
return [False, error_prompt, symbolTable, output_arr]
if change == False:
print("DONE WITH EVALUATING EXPRESSIONS INSIDE")
break
# convert non-yarn to yarn
for index, i in enumerate(to_eval_list):
if i[1] in datatypes_arr and i[1] != "YARN Literal":
i[0] = str(i[0])
i[1] = "YARN Literal"
# concatenate the expressions
while (True):
change = False
for index, i in enumerate(to_eval_list):
# evaluate all inner expressions first
if i[1] in datatypes_arr and (index + 2) < len(to_eval_list):
if to_eval_list[index+1][0] == "AN" and to_eval_list[index + 2][1] in datatypes_arr:
newStr = str(i[0]) + " " + str(to_eval_list[index + 2][0])
del to_eval_list[index: index + 3]
to_eval_list.insert(index, [newStr, "YARN Literal"])
change = True
if i[1] in datatypes_arr and (index + 1) < len(to_eval_list):
if to_eval_list[index + 1][1] in datatypes_arr:
newStr = str(i[0]) + " " + str(to_eval_list[index + 1][0])
print(newStr)
del to_eval_list[index: index + 2]
to_eval_list.insert(index, [newStr, "YARN Literal"])
change = True
if change == False:
print(to_eval_list)
break
return to_eval_list[0]
def grab_symbol_table(lexemeArr, symbolTable):
testing_list = []
error_prompt = ""
output_arr = []
for i in lexemeArr:
testing_list.append(i)
while (True):
change = False
for index, i in enumerate(testing_list):
# remove quotation marks
if i[0] == "\"" and (index + 2) < len(testing_list):
if testing_list[index+1][1] == "YARN Literal" and testing_list[index+2][0] == "\"":
temp = testing_list[index+1]
del testing_list[index: (index + 3)]
testing_list.insert(index, temp)
change = True
# remove optional A (return MAEK varident TYPE)
if i[0] == "MAEK" and (index + 2) < len(testing_list):
if testing_list[index+1][1] == "Variable Identifier" and testing_list[index+2][0] == "A" and testing_list[index+3][1] == "TYPE Literal":
del testing_list[index+2]
change = True
# number R MAEK number YARN
if i[1] == "Variable Identifier" and (index + 4) < len(testing_list):
if testing_list[index+1][0] == "R" and testing_list[index+2][0] == "MAEK" and testing_list[index+3][0] == i[0]:
del testing_list[index+1: index+4]
testing_list.insert(index+1, ["IS NOW A", 'keyword'])
# remove lexemes related to comment
if i[0] == "OBTW" or i[1] == "comment" or i[0] == "TLDR" or i[0] == "BTW":
del testing_list[index]
change = True
# remove optional MKAY
if i[0] == "MKAY":
del testing_list[index]
change = True
if (change == False):
print("Phase 1")
print(testing_list)
break
# ------------------------------------------------------------------------------------------------------------------------------
while (True):
change = False
for index, i in enumerate(testing_list):
# print(index)
# single line variable stored in the IT variable
if (i[1] == "linebreak" and (index+1) < len(testing_list)):
if (testing_list[index+1][1] in "Variable Identifier" and testing_list[index+2][1] == "linebreak"):
value = findValue(symbolTable, testing_list[index+1][0])
if value != False:
insertInSymbolTable(
symbolTable, "IT", value[0], value[1])
else:
error_prompt = "SemanticsError: variable identifier \'" + \
testing_list[index+1][0] + "\' is not defined"
return [False, error_prompt, symbolTable, output_arr]
# single line expressions stored in the IT variable
if (i[0] in operations_arr):
start_index = index
j = start_index
while testing_list[j][1] != 'linebreak':
j = j + 1
# get that portion of line then evaluate until only
to_eval_list = testing_list[start_index: j]
print("----Eval----")
print(to_eval_list)
print("------------")
# replace all variabes first
for index, i in enumerate(to_eval_list):
if i[1] == "Variable Identifier":
value = findValue(
symbolTable, to_eval_list[index][0])
if value != False:
del to_eval_list[index]
to_eval_list.insert(index, value)
else:
error_prompt = "SemanticsError: variable identifier \'" + \
to_eval_list[index][0] + \
"\' is not defined"
print(error_prompt) # temp
return [False, error_prompt, symbolTable, output_arr]
# evaluate expressions
while (True):
change1 = False
for index, i in enumerate(to_eval_list):
if i[0] == "NOT" and (index + 1) < len(to_eval_list):
if to_eval_list[index+1][1] in datatypes_arr:
evaluated = boolean_not(
to_eval_list[index+1][0], to_eval_list[index+1][1])
if evaluated[0] != False:
del to_eval_list[(index):(index+2)]
print("---Before-----")
print(to_eval_list)
to_eval_list.insert(
index, evaluated[1:3])
print("---After-----")
print(to_eval_list)
change1 = True
else:
output_arr.append(evaluated[1])
return [False, error_prompt, symbolTable, output_arr]
if i[0] in operations_arr and (index + 3) < len(to_eval_list):
if to_eval_list[index+1][1] in datatypes_arr and to_eval_list[index+2][0] == "AN" and to_eval_list[index+3][1] in datatypes_arr:
# call function that accepts value1, type1, value2, type2 and operation
if i[0] in arithmetic_arr: # check if to peform arithmetic
evaluated = arithmetic_op(
to_eval_list[index+1][0], to_eval_list[index+1][1], to_eval_list[index+3][0], to_eval_list[index+3][1], i[0])
elif i[0] in comparison_arr: # check if to perform comparison
evaluated = comparison_op(
to_eval_list[index+1][0], to_eval_list[index+1][1], to_eval_list[index+3][0], to_eval_list[index+3][1], i[0])
elif i[0] in boolean_arr: # check if to perform boolean
evaluated = boolean_op(
to_eval_list[index+1][0], to_eval_list[index+1][1], to_eval_list[index+3][0], to_eval_list[index+3][1], i[0])
print(evaluated)
if evaluated[0] != False:
del to_eval_list[(index):(index+4)]
to_eval_list.insert(
index, evaluated[1:3])
change1 = True
else:
output_arr.append(evaluated[1])
return [False, error_prompt, symbolTable, output_arr]
if (change1 == False):
print("Done evaluating!")
print("----Before-----")
print(testing_list)
print("----After-----")
insertInSymbolTable(
symbolTable, "IT", to_eval_list[0][0], to_eval_list[0][1])
del testing_list[start_index: j]
testing_list.insert(start_index, to_eval_list[0])
print(testing_list)
print("-------------")
break
# if else block
if (i[0] == "O RLY?"):
if (testing_list[index+1][1] == "linebreak" and testing_list[index+2][0] == "YA RLY"):
print("DRIFTOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO")
start_index = index+4
j = start_index
while testing_list[j][0] not in ["OIC", "NO WAI"]:
j = j + 1
print(testing_list[j][0])
print(testing_list[j][0] == "OIC")
if (testing_list[j][0] == "OIC"):
itVal = findValue(symbolTable, "IT")
# print(itVal)
if (itVal[1] != "TROOF Literal"):
itVal = typecast(itVal[0], itVal[1], "TROOF")
del itVal[0]
# print(itVal)
new_testing_list = testing_list[start_index:j]
del testing_list[start_index:j]
if (itVal[0] == "WIN"):
x = grab_symbol_table(
new_testing_list, symbolTable)
# print(x[0])
# print(x[1])
# print(x[2])
# print(x[3])
if (x[0]):
for symbolTableVal in x[2]:
insertInSymbolTable(
symbolTable, symbolTableVal[0], symbolTableVal[1], symbolTableVal[2])
# print(symbolTableVal)
for output_arrVal in x[3]:
output_arr.append(output_arrVal)
# print(output_arrVal)
if (testing_list[j][0] == "NO WAI"):
start_index2 = j+2
k = start_index2
while testing_list[k][0] != "OIC":
k = k + 1
# print(testing_list[k][0])
new_testing_list2 = testing_list[start_index2:k]
del testing_list[start_index2:k]
new_testing_list = testing_list[start_index:j]
del testing_list[start_index:j]
itVal = findValue(symbolTable, "IT")
# print(itVal)
if (itVal[1] != "TROOF Literal"):
itVal = typecast(itVal[0], itVal[1], "TROOF")
del itVal[0]
if (itVal[0] == "WIN"):
x = grab_symbol_table(
new_testing_list, symbolTable)
else:
x = grab_symbol_table(
new_testing_list2, symbolTable)
if (x[0]):
for symbolTableVal in x[2]:
insertInSymbolTable(
symbolTable, symbolTableVal[0], symbolTableVal[1], symbolTableVal[2])
# symbolTable.append(symbolTableVal)
# print(symbolTableVal)
for output_arrVal in x[3]:
output_arr.append(output_arrVal)
# print(output_arrVal)
print("DRIFTOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO")
# switch case
if (i[0] == "WTF?"):
if (testing_list[index+1][1] == "linebreak" and testing_list[index+2][0] == "OMG"):
caseOccur = False
while (testing_list[index+2][0] != "OIC"):
if (testing_list[index+2][0] == "GTFO"):
start_index = index+2
j = start_index+1
while (testing_list[j][0] not in ["OMG", "OMGWTF", "OIC", "GTFO"]):
j = j + 1
del testing_list[start_index:j]
continue
if (testing_list[index+2][0] == "OMGWTF" and caseOccur == False):
start_index = index+2
j = start_index+1
while (testing_list[j][0] not in ["OMG", "OMGWTF", "OIC", "GTFO"]):
j = j + 1
new_testing_list = testing_list[start_index:j]
del testing_list[start_index:j]
afterExec = grab_symbol_table(
new_testing_list, symbolTable)
if (afterExec[0]):
for symbolTableVal in afterExec[2]:
insertInSymbolTable(
symbolTable, symbolTableVal[0], symbolTableVal[1], symbolTableVal[2])
# symbolTable.append(symbolTableVal)
# print(symbolTableVal)
for output_arrVal in afterExec[3]:
output_arr.append(output_arrVal)
continue
caseVal = testing_list[index+3][0]
caseValType = re.sub(
" Literal", "", testing_list[index+3][1])
caseVal = typecast(
caseVal, "YARN Literal", caseValType)[1]
start_index = index+2
j = start_index+1
while (testing_list[j][0] not in ["OMG", "OMGWTF", "OIC", "GTFO"]):
j = j + 1
new_testing_list = testing_list[start_index:j]
del testing_list[start_index:j]
print("TESTING:", new_testing_list)
it = findValue(symbolTable, "IT")
itVal = it[0]
itValType = re.sub(" Literal", "", it[1])
itVal = typecast(itVal, "YARN Literal", itValType)[1]
if (itVal == caseVal):
afterExec = grab_symbol_table(
new_testing_list, symbolTable)
if (afterExec[0]):
for symbolTableVal in afterExec[2]:
insertInSymbolTable(
symbolTable, symbolTableVal[0], symbolTableVal[1], symbolTableVal[2])
# symbolTable.append(symbolTableVal)
# print(symbolTableVal)
for output_arrVal in afterExec[3]:
output_arr.append(output_arrVal)
# print(output_arrVal)
caseOccur = True
print(caseOccur)
# Loop block
if (i[0] == "IM IN YR"):
it = findValue(symbolTable, "IT")
print("it:", it)
label = testing_list[index+1][0]
# print("label:", label)
operation = testing_list[index+2][0]
# print("operation:",operation)
var = testing_list[index+4][0]
# print("var:", var)
tilWhile = testing_list[index+5][0]
# print(tilWhile)
start_index = index+6
j = start_index
while (testing_list[j][1] != "linebreak"):
j += 1
# -----------------------------------------------------
# getting condition statement
condList = testing_list[start_index:(j+1)]
print("condList:", condList)
# -----------------------------------------------------
# executing condition statement
afterExec = grab_symbol_table(condList, symbolTable)
# print("after =====>", afterExec)
if (afterExec[0]):
for symbolTableVal in afterExec[2]:
insertInSymbolTable(
symbolTable, symbolTableVal[0], symbolTableVal[1], symbolTableVal[2])
# getting the value of condition statement through the IT variable
itVal = findValue(symbolTable, "IT")[0]
# print("itVal========>", itVal)
# -----------------------------------------------------
incDecList = []
if (operation == "UPPIN"):
incDecList = [[var, "Variable Identifier"], ["R", "keyword"], ["SUM OF", "keyword"], [
var, "Variable Identifier"], ["AN", "keyword"], ["1", "NUMBR Literal"], ["<linebreak>", "linebreak"]]
else:
incDecList = [[var, "Variable Identifier"], ["R", "keyword"], ["DIFF OF", "keyword"], [
var, "Variable Identifier"], ["AN", "keyword"], ["1", "NUMBR Literal"], ["<linebreak>", "linebreak"]]
start_index2 = j+1
k = start_index2
while (testing_list[k][0] not in ["GTFO", "IM OUTTA YR"]):
k += 1
loopBlock = testing_list[start_index2:k]
if (testing_list[k][0] == "GTFO"):
while (testing_list[k][0] != "IM OUTTA YR"):
k += 1
del testing_list[start_index: (k+1)]
if (tilWhile == "WILE"):
while (itVal == "WIN"):
# Loop block execution
x = grab_symbol_table(loopBlock, symbolTable)
if (x[0]):
for symbolTableVal in x[2]:
insertInSymbolTable(
symbolTable, symbolTableVal[0], symbolTableVal[1], symbolTableVal[2])
# print(symbolTableVal)
for output_arrVal in x[3]:
output_arr.append(output_arrVal)
# incrementing or decrementing
x = grab_symbol_table(incDecList, symbolTable)
if (x[0]):
for symbolTableVal in x[2]:
insertInSymbolTable(
symbolTable, symbolTableVal[0], symbolTableVal[1], symbolTableVal[2])
# print(symbolTableVal)
for output_arrVal in x[3]:
output_arr.append(output_arrVal)
# after execution process
afterExec = grab_symbol_table(condList, symbolTable)
# print("after =====>", afterExec)
if (afterExec[0]):
for symbolTableVal in afterExec[2]:
insertInSymbolTable(
symbolTable, symbolTableVal[0], symbolTableVal[1], symbolTableVal[2])
# getting the value of condition statement through the IT variable
itVal = findValue(symbolTable, "IT")[0]
else:
while (itVal == "FAIL"):
# Loop block execution
x = grab_symbol_table(loopBlock, symbolTable)
if (x[0]):
for symbolTableVal in x[2]:
insertInSymbolTable(
symbolTable, symbolTableVal[0], symbolTableVal[1], symbolTableVal[2])
# print(symbolTableVal)
for output_arrVal in x[3]:
output_arr.append(output_arrVal)
# incrementing or decrementing
x = grab_symbol_table(incDecList, symbolTable)
if (x[0]):
for symbolTableVal in x[2]:
insertInSymbolTable(
symbolTable, symbolTableVal[0], symbolTableVal[1], symbolTableVal[2])
# print(symbolTableVal)
for output_arrVal in x[3]:
output_arr.append(output_arrVal)
# after execution process
afterExec = grab_symbol_table(condList, symbolTable)
# print("after =====>", afterExec)
if (afterExec[0]):
for symbolTableVal in afterExec[2]:
insertInSymbolTable(
symbolTable, symbolTableVal[0], symbolTableVal[1], symbolTableVal[2])
# getting the value of condition statement through the IT variable
itVal = findValue(symbolTable, "IT")[0]
print("BRUHHHHHHHHH", testing_list)
# variable assignment (I HAS A var)
if (i[0] == "I HAS A" and (index+1) < len(testing_list)):
if testing_list[index+1][1] == "Variable Identifier":
if (index + 2) < len(testing_list):
if testing_list[index+2][0] != "ITZ":
insertInSymbolTable(symbolTable, testing_list[index+1][0],
"NOOB", "NOOB")
elif (index + 2) == len(testing_list):
insertInSymbolTable(symbolTable, testing_list[index+1][0],
"NOOB", "NOOB")
# Variable assignment (I HAS A var ITZ literal)
if (i[0] == "I HAS A" and (index+3) < len(testing_list)):
if testing_list[index+1][1] == "Variable Identifier" and testing_list[index+2][0] == "ITZ" and testing_list[index+3][1] in datatypes_arr:
insertInSymbolTable(
symbolTable, testing_list[index+1][0], testing_list[index+3][0], testing_list[index+3][1])
# Variable assignment (I HAS A var ITZ variable)
if (i[0] == "I HAS A" and (index+3) < len(testing_list)):
if testing_list[index+1][1] == "Variable Identifier" and testing_list[index+2][0] == "ITZ" and testing_list[index+3][1] == "Variable Identifier":
value = findValue(symbolTable, testing_list[index+3][0])
if value != False:
insertInSymbolTable(
symbolTable, testing_list[index+1][0], value[0], value[1])
else:
error_prompt = "SemanticsError: variable identifier \'" + \
testing_list[index+3][0] + "\' is not defined"
print(error_prompt) # temp
return [False, error_prompt, symbolTable, output_arr]
# Variable assignment (I HAS A var ITZ expr)
if i[0] == "I HAS A" and testing_list[index+1][1] == "Variable Identifier" and testing_list[index+2][0] == "ITZ":
to_eval_list = []
if testing_list[index+3][0] in operations_arr:
# find the index of the line break
start_index = index + 3
j = start_index
while testing_list[j][1] != 'linebreak':
j = j + 1
# get that portion of line then evaluate until only
to_eval_list = testing_list[start_index: j]
print("----Eval----")
print(to_eval_list)
print("------------")
# replace all variabes first
for index, i in enumerate(to_eval_list):
if i[1] == "Variable Identifier":
value = findValue(
symbolTable, to_eval_list[index][0])
if value != False:
del to_eval_list[index]
to_eval_list.insert(index, value)
else:
error_prompt = "SemanticsError: variable identifier \'" + \
to_eval_list[index][0] + \
"\' is not defined"
print(error_prompt) # temp
return [False, error_prompt, symbolTable, output_arr]
# evaluate expressions
while (True):
change1 = False
for index, i in enumerate(to_eval_list):
if i[0] == "ALL OF":
print("=====START OF ALL OF=======")
to_eval_list1 = to_eval_list[index +
1: len(to_eval_list)]
print("----All of Expr Eval----")
print(to_eval_list1)
print("-------------------------")
# replace all variabes first
for index, i in enumerate(to_eval_list1):
if i[1] == "Variable Identifier":
value = findValue(
symbolTable, to_eval_list1[index][0])
if value != False:
del to_eval_list1[index]
to_eval_list1.insert(index, value)
else:
error_prompt = "SemanticsError: variable identifier \'" + \
to_eval_list1[index][0] + \
"\' is not defined"
print(error_prompt) # temp
return [False, error_prompt, symbolTable, output_arr]
while (True):
change = False
for index, i in enumerate(to_eval_list1):
if i[0] == "NOT" and (index + 1) < len(to_eval_list):
if to_eval_list1[index+1][1] in datatypes_arr:
evaluated = boolean_not(
to_eval_list1[index+1][0], to_eval_list1[index+1][1])
if evaluated[0] != False:
del to_eval_list1[(
index):(index+2)]
print("---Before-----")
print(to_eval_list1)
to_eval_list1.insert(
index, evaluated[1:3])
print("---After-----")
print(to_eval_list1)
change = True
else: