-
Notifications
You must be signed in to change notification settings - Fork 0
/
interpret.py
658 lines (565 loc) · 24 KB
/
interpret.py
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
#!/usr/bin/env python3
import sys
from xml.dom import minidom
from symtable import SymTable
from instruction import Instruction
from arg import Arg
from labels import Labels
from error import *
import argparse
def print_stats_to_file(file, cnt_insts, cnt_vars):
""" Used by STATI extension, writes statistics to an output file """
for arg in sys.argv:
if arg == "--insts":
file.write(str(cnt_insts) + "\n")
elif arg == "--vars":
file.write(str(cnt_vars) + "\n")
### Argument parsing ###
if ("--help" in sys.argv or "-h" in sys.argv) and len(sys.argv) > 2:
err.exit_script(err.missing_parameter)
parser = argparse.ArgumentParser()
parser.add_argument("--source", dest="source_file", help="input xml file, stdin will be used by default if not set")
parser.add_argument("--input", dest="input_file", help="input for source code interpretation, stdin will be used by default if not set (either --source or --input parameter must be set)")
parser.add_argument("--stats", dest="stats_file", help="output file for some interpretation statistics")
parser.add_argument("--insts", dest="stats_insts", help="prints amount of interpreted instructions into file set by --stats parameter", action="store_true")
parser.add_argument("--vars", dest="stats_vars", help="prints amount of defined variables into file set by --stats parameter", action="store_true")
parser.add_argument("--debug", dest="debug_mode", help="runs the interpreter in debug mode", action="store_true")
args = parser.parse_args()
# Both source file and input file not set
if (args.source_file == None and args.input_file == None):
err.exit_script(err.missing_parameter)
# Read instructions from source file or stdin
if (args.source_file != None):
source_file_stream = args.source_file
else:
source_file_stream = sys.stdin
# Check whether source XML is well-formed
try:
xml = minidom.parse(source_file_stream)
except:
err.exit_script(err.xml)
# Read input from stdin or redirect input file to stdin
if (args.input_file != None):
old_stdin = sys.stdin
try:
sys.stdin = open(args.input_file)
except:
err.exit_script(err.output_file)
# Check for STATI extension parameters
if (args.stats_insts or args.stats_vars):
if (args.stats_file != None):
try:
stats_file_stream = open(args.stats_file, "w")
except:
err.exit_script(err.output_file)
else:
err.exit_script(err.missing_parameter)
# Custom debug mode
debug = False
if (args.debug_mode):
debug = True
### Reading XML source file ###
# Check for language="IPPcode19"
if "language" not in xml.firstChild.attributes:
err.exit_script(err.lexical_or_syntax)
if xml.firstChild.attributes["language"].value != "IPPcode19":
err.exit_script(err.lexical_or_syntax)
# Check for excessive text in XML
for node in xml.firstChild.childNodes:
if node.nodeType == node.TEXT_NODE:
if (not node.nodeValue.isspace()):
err.exit_script(err.lexical_or_syntax)
elif node.nodeType == node.ELEMENT_NODE:
if node.localName != "instruction":
err.exit_script(err.lexical_or_syntax)
# Check for order attribute in instruction elements
instructions = xml.getElementsByTagName("instruction")
for err.inst_order in range (0, len(instructions)):
if "order" not in instructions[err.inst_order].attributes:
err.exit_script(err.lexical_or_syntax)
# Sort instruction elements by order number
instructions.sort(key=lambda x: int(x.attributes["order"].value))
# Check for valid order sequence
order_check = 1
for inst in instructions:
if order_check != int(inst.attributes["order"].value):
err.exit_script(err.lexical_or_syntax)
order_check += 1
### Interpretation ###
# 1st passing of all instructions to define labels
labels = Labels()
err.inst_order = 0
for inst_order in range (0, len(instructions)):
err.inst_order += 1
inst = Instruction(instructions[inst_order])
if inst.opcode == "LABEL":
labels.add(inst.arg1, inst_order)
# 2nd passing of all instructions to interprete them
inst_order = 0
inst_exectuted = 0
err.inst_order = 0
symtable = SymTable()
while inst_order < len(instructions):
err.inst_order += 1
inst = Instruction(instructions[inst_order])
if debug == True:
inst.debug()
if inst.opcode == "CREATEFRAME":
symtable.create_frame()
elif inst.opcode == "PUSHFRAME":
symtable.push_frame()
elif inst.opcode == "POPFRAME":
symtable.pop_frame()
elif inst.opcode == "RETURN":
inst_order = labels.ret()
elif inst.opcode == "BREAK":
sys.stderr.write("Instructions order: " + str(inst_order + 1) + "\n")
sys.stderr.write("Instructions executed: " + str(inst_exectuted + 1) + "\n")
symtable.print()
elif inst.opcode == "CLEARS":
symtable.clears()
#1 arg: var
elif inst.opcode == "DEFVAR":
symtable.defvar(inst.arg1)
elif inst.opcode == "POPS":
symtable.set_var(inst.arg1, symtable.pops())
#1 arg: label
elif inst.opcode == "JUMP":
inst_order = labels.jump(inst.arg1)
elif inst.opcode == "CALL":
inst_order = labels.call(inst.arg1, inst_order)
#1 arg: symb
elif inst.opcode == "PUSHS":
symtable.pushs(inst.arg1)
elif inst.opcode == "WRITE":
symtable.get_value(inst.arg1).write(sys.stdout)
elif inst.opcode == "EXIT":
exit_arg = symtable.get_value(inst.arg1)
if exit_arg.datatype == "int":
if 0 <= exit_arg.value <= 49:
if args.stats_file != None:
print_stats_to_file(stats_file_stream, inst_exectuted, symtable.max_defined_vars)
sys.exit(exit_arg.value)
else:
err.exit_script(err.operand_value)
else:
err.exit_script(err.operand_type)
elif inst.opcode == "DPRINT":
symtable.get_value(inst.arg1).write(sys.stderr)
#2 arg: var symb
elif inst.opcode == "MOVE":
move_arg = symtable.get_value(inst.arg2)
symtable.set_var(inst.arg1, move_arg)
elif inst.opcode == "INT2CHAR" or inst.opcode == "INT2CHARS":
if inst.opcode == "INT2CHAR":
operand1_arg = symtable.get_value(inst.arg2)
else:
operand1_arg = symtable.pops()
result_arg = Arg(None)
result_arg.datatype = "string"
if operand1_arg.datatype == "int":
if 0 <= operand1_arg.value <= 1114111:
result_arg.value = chr(operand1_arg.value)
else:
err.exit_script(err.string_operation)
else:
err.exit_script(err.operand_type)
if inst.opcode == "INT2CHAR":
symtable.set_var(inst.arg1, result_arg)
else:
symtable.pushs(result_arg)
elif inst.opcode == "STRLEN":
operand1_arg = symtable.get_value(inst.arg2)
result_arg = Arg(None)
result_arg.datatype = "int"
if operand1_arg.datatype == "string":
result_arg.value = len(operand1_arg.value)
else:
err.exit_script(err.operand_type)
symtable.set_var(inst.arg1, result_arg)
elif inst.opcode == "TYPE":
src_var = symtable.get_var_even_uninitialised(inst.arg2)
dst_var = Arg(None)
dst_var.datatype = "string"
if src_var == None:
dst_var.value = ""
elif src_var.datatype == "int":
dst_var.value = "int"
elif src_var.datatype == "bool":
dst_var.value = "bool"
elif src_var.datatype == "string":
dst_var.value = "string"
elif src_var.datatype == "nil":
dst_var.value = "nil"
elif src_var.datatype == "float":
dst_var.value = "float"
symtable.set_var(inst.arg1, dst_var)
#2 arg: var type
elif inst.opcode == "READ":
input_arg = Arg(None)
input_arg.read(inst.arg2.value)
symtable.set_var(inst.arg1, input_arg)
#3 arg: var symb symb
elif inst.opcode == "ADD" or inst.opcode == "ADDS":
if inst.opcode == "ADD":
operand1_arg = symtable.get_value(inst.arg2)
operand2_arg = symtable.get_value(inst.arg3)
else:
operand2_arg = symtable.pops()
operand1_arg = symtable.pops()
result_arg = Arg(None)
if operand1_arg.datatype == "int" and operand2_arg.datatype == "int":
result_arg.datatype = "int"
result_arg.value = operand1_arg.value + operand2_arg.value
elif operand1_arg.datatype == "float" and operand2_arg.datatype == "float":
result_arg.datatype = "float"
result_arg.value = operand1_arg.value + operand2_arg.value
else:
err.exit_script(err.operand_type)
if inst.opcode == "ADD":
symtable.set_var(inst.arg1, result_arg)
else:
symtable.pushs(result_arg)
elif inst.opcode == "SUB" or inst.opcode == "SUBS":
if inst.opcode == "SUB":
operand1_arg = symtable.get_value(inst.arg2)
operand2_arg = symtable.get_value(inst.arg3)
else:
operand2_arg = symtable.pops()
operand1_arg = symtable.pops()
result_arg = Arg(None)
if operand1_arg.datatype == "int" and operand2_arg.datatype == "int":
result_arg.datatype = "int"
result_arg.value = operand1_arg.value - operand2_arg.value
elif operand1_arg.datatype == "float" and operand2_arg.datatype == "float":
result_arg.datatype = "float"
result_arg.value = operand1_arg.value - operand2_arg.value
else:
err.exit_script(err.operand_type)
if inst.opcode == "SUB":
symtable.set_var(inst.arg1, result_arg)
else:
symtable.pushs(result_arg)
elif inst.opcode == "MUL" or inst.opcode == "MULS":
if inst.opcode == "MUL":
operand1_arg = symtable.get_value(inst.arg2)
operand2_arg = symtable.get_value(inst.arg3)
else:
operand2_arg = symtable.pops()
operand1_arg = symtable.pops()
result_arg = Arg(None)
if operand1_arg.datatype == "int" and operand2_arg.datatype == "int":
result_arg.datatype = "int"
result_arg.value = operand1_arg.value * operand2_arg.value
elif operand1_arg.datatype == "float" and operand2_arg.datatype == "float":
result_arg.datatype = "float"
result_arg.value = operand1_arg.value * operand2_arg.value
else:
err.exit_script(err.operand_type)
if inst.opcode == "MUL":
symtable.set_var(inst.arg1, result_arg)
else:
symtable.pushs(result_arg)
elif inst.opcode == "IDIV" or inst.opcode == "IDIVS":
if inst.opcode == "IDIV":
operand1_arg = symtable.get_value(inst.arg2)
operand2_arg = symtable.get_value(inst.arg3)
else:
operand2_arg = symtable.pops()
operand1_arg = symtable.pops()
result_arg = Arg(None)
result_arg.datatype = "int"
if operand1_arg.datatype == "int" and operand2_arg.datatype == "int":
if operand2_arg.value == 0:
err.exit_script(err.operand_value)
else:
result_arg.value = operand1_arg.value // operand2_arg.value
else:
err.exit_script(err.operand_type)
if inst.opcode == "IDIV":
symtable.set_var(inst.arg1, result_arg)
else:
symtable.pushs(result_arg)
elif inst.opcode == "DIV" or inst.opcode == "DIVS":
if inst.opcode == "DIV":
operand1_arg = symtable.get_value(inst.arg2)
operand2_arg = symtable.get_value(inst.arg3)
else:
operand2_arg = symtable.pops()
operand1_arg = symtable.pops()
result_arg = Arg(None)
result_arg.datatype = "float"
if operand1_arg.datatype == "float" and operand2_arg.datatype == "float":
if operand2_arg.value == 0:
err.exit_script(err.operand_value)
else:
result_arg.value = operand1_arg.value / operand2_arg.value
else:
err.exit_script(err.operand_type)
if inst.opcode == "DIV":
symtable.set_var(inst.arg1, result_arg)
else:
symtable.pushs(result_arg)
elif inst.opcode == "LT" or inst.opcode == "LTS":
if inst.opcode == "LT":
operand1_arg = symtable.get_value(inst.arg2)
operand2_arg = symtable.get_value(inst.arg3)
else:
operand2_arg = symtable.pops()
operand1_arg = symtable.pops()
result_arg = Arg(None)
result_arg.datatype = "bool"
result_arg.value = "false"
if operand1_arg.datatype == "int" and operand2_arg.datatype == "int":
if operand1_arg.value < operand2_arg.value:
result_arg.value = "true"
elif operand1_arg.datatype == "bool" and operand2_arg.datatype == "bool":
if operand1_arg.value == "false" and operand2_arg.value == "true":
result_arg.value = "true"
elif operand1_arg.datatype == "string" and operand2_arg.datatype == "string":
if operand1_arg.value < operand2_arg.value:
result_arg.value = "true"
else:
err.exit_script(err.operand_type)
if inst.opcode == "LT":
symtable.set_var(inst.arg1, result_arg)
else:
symtable.pushs(result_arg)
elif inst.opcode == "GT" or inst.opcode == "GTS":
if inst.opcode == "GT":
operand1_arg = symtable.get_value(inst.arg2)
operand2_arg = symtable.get_value(inst.arg3)
else:
operand2_arg = symtable.pops()
operand1_arg = symtable.pops()
result_arg = Arg(None)
result_arg.datatype = "bool"
result_arg.value = "false"
if operand1_arg.datatype == "int" and operand2_arg.datatype == "int":
if operand1_arg.value > operand2_arg.value:
result_arg.value = "true"
elif operand1_arg.datatype == "bool" and operand2_arg.datatype == "bool":
if operand1_arg.value == "true" and operand2_arg.value == "false":
result_arg.value = "true"
elif operand1_arg.datatype == "string" and operand2_arg.datatype == "string":
if operand1_arg.value > operand2_arg.value:
result_arg.value = "true"
else:
err.exit_script(err.operand_type)
if inst.opcode == "GT":
symtable.set_var(inst.arg1, result_arg)
else:
symtable.pushs(result_arg)
elif inst.opcode == "EQ" or inst.opcode == "EQS":
if inst.opcode == "EQ":
operand1_arg = symtable.get_value(inst.arg2)
operand2_arg = symtable.get_value(inst.arg3)
else:
operand2_arg = symtable.pops()
operand1_arg = symtable.pops()
result_arg = Arg(None)
result_arg.datatype = "bool"
result_arg.value = "false"
if operand1_arg.datatype == "int" and operand2_arg.datatype == "int":
if operand1_arg.value == operand2_arg.value:
result_arg.value = "true"
elif operand1_arg.datatype == "bool" and operand2_arg.datatype == "bool":
if operand1_arg.value == operand2_arg.value:
result_arg.value = "true"
elif operand1_arg.datatype == "string" and operand2_arg.datatype == "string":
if operand1_arg.value == operand2_arg.value:
result_arg.value = "true"
elif operand1_arg.datatype == "nil" and operand2_arg.datatype == "nil":
if operand1_arg.value == operand2_arg.value:
result_arg.value = "true"
elif operand1_arg.datatype == "nil" or operand2_arg.datatype == "nil":
...
else:
err.exit_script(err.operand_type)
if inst.opcode == "EQ":
symtable.set_var(inst.arg1, result_arg)
else:
symtable.pushs(result_arg)
elif inst.opcode == "AND" or inst.opcode == "ANDS":
if inst.opcode == "AND":
operand1_arg = symtable.get_value(inst.arg2)
operand2_arg = symtable.get_value(inst.arg3)
else:
operand2_arg = symtable.pops()
operand1_arg = symtable.pops()
result_arg = Arg(None)
result_arg.datatype = "bool"
if operand1_arg.datatype == "bool" and operand2_arg.datatype == "bool":
if operand1_arg.value == "true" and operand2_arg.value == "true":
result_arg.value = "true"
else:
result_arg.value = "false"
else:
err.exit_script(err.operand_type)
if inst.opcode == "AND":
symtable.set_var(inst.arg1, result_arg)
else:
symtable.pushs(result_arg)
elif inst.opcode == "OR" or inst.opcode == "ORS":
if inst.opcode == "OR":
operand1_arg = symtable.get_value(inst.arg2)
operand2_arg = symtable.get_value(inst.arg3)
else:
operand2_arg = symtable.pops()
operand1_arg = symtable.pops()
result_arg = Arg(None)
result_arg.datatype = "bool"
if operand1_arg.datatype == "bool" and operand2_arg.datatype == "bool":
if operand1_arg.value == "true" or operand2_arg.value == "true":
result_arg.value = "true"
else:
result_arg.value = "false"
else:
err.exit_script(err.operand_type)
if inst.opcode == "OR":
symtable.set_var(inst.arg1, result_arg)
else:
symtable.pushs(result_arg)
elif inst.opcode == "NOT" or inst.opcode == "NOTS":
if inst.opcode == "NOT":
operand1_arg = symtable.get_value(inst.arg2)
else:
operand1_arg = symtable.pops()
result_arg = Arg(None)
result_arg.datatype = "bool"
if operand1_arg.datatype == "bool":
if operand1_arg.value == "true":
result_arg.value = "false"
else:
result_arg.value = "true"
else:
err.exit_script(err.operand_type)
if inst.opcode == "NOT":
symtable.set_var(inst.arg1, result_arg)
else:
symtable.pushs(result_arg)
elif inst.opcode == "STRI2INT" or inst.opcode == "STRI2INTS":
if inst.opcode == "STRI2INT":
operand1_arg = symtable.get_value(inst.arg2)
operand2_arg = symtable.get_value(inst.arg3)
else:
operand2_arg = symtable.pops()
operand1_arg = symtable.pops()
result_arg = Arg(None)
result_arg.datatype = "int"
if operand1_arg.datatype == "string" and operand2_arg.datatype == "int":
if 0 <= operand2_arg.value < len(operand1_arg.value):
result_arg.value = ord(operand1_arg.value[operand2_arg.value])
else:
err.exit_script(err.string_operation)
else:
err.exit_script(err.operand_type)
if inst.opcode == "STRI2INT":
symtable.set_var(inst.arg1, result_arg)
else:
symtable.pushs(result_arg)
elif inst.opcode == "FLOAT2INT" or inst.opcode == "FLOAT2INTS":
if inst.opcode == "FLOAT2INT":
operand1_arg = symtable.get_value(inst.arg2)
else:
operand1_arg = symtable.pops()
result_arg = Arg(None)
result_arg.datatype = "int"
if operand1_arg.datatype == "float":
result_arg.value = int(operand1_arg.value)
else:
err.exit_script(err.operand_type)
if inst.opcode == "FLOAT2INT":
symtable.set_var(inst.arg1, result_arg)
else:
symtable.pushs(result_arg)
elif inst.opcode == "INT2FLOAT" or inst.opcode == "INT2FLOATS":
if inst.opcode == "INT2FLOAT":
operand1_arg = symtable.get_value(inst.arg2)
else:
operand1_arg = symtable.pops()
result_arg = Arg(None)
result_arg.datatype = "float"
if operand1_arg.datatype == "int":
result_arg.value = float(operand1_arg.value)
else:
err.exit_script(err.operand_type)
if inst.opcode == "INT2FLOAT":
symtable.set_var(inst.arg1, result_arg)
else:
symtable.pushs(result_arg)
elif inst.opcode == "CONCAT":
operand1_arg = symtable.get_value(inst.arg2)
operand2_arg = symtable.get_value(inst.arg3)
if operand1_arg.datatype == "string" and operand2_arg.datatype == "string":
result_arg = Arg(None)
result_arg.datatype = "string"
result_arg.value = operand1_arg.value + operand2_arg.value
symtable.set_var(inst.arg1, result_arg)
else:
err.exit_script(err.operand_type)
symtable.set_var(inst.arg1, result_arg)
elif inst.opcode == "GETCHAR":
operand1_arg = symtable.get_value(inst.arg2)
operand2_arg = symtable.get_value(inst.arg3)
result_arg = Arg(None)
result_arg.datatype = "int"
if operand1_arg.datatype == "string" and operand2_arg.datatype == "int":
if 0 <= operand2_arg.value < len(operand1_arg.value):
result_arg.value = operand1_arg.value[operand2_arg.value]
else:
err.exit_script(err.string_operation)
else:
err.exit_script(err.operand_type)
symtable.set_var(inst.arg1, result_arg)
elif inst.opcode == "SETCHAR":
operand1_arg = symtable.get_value(inst.arg2)
operand2_arg = symtable.get_value(inst.arg3)
result_arg = symtable.get_var(inst.arg1)
if result_arg.datatype == "string" and operand1_arg.datatype == "int" and operand2_arg.datatype == "string":
if 0 <= operand1_arg.value < len(result_arg.value) and len(operand2_arg.value) > 0:
result_string = list(result_arg.value)
result_string[operand1_arg.value] = operand2_arg.value[0]
result_arg.value = "".join(result_string)
else:
err.exit_script(err.string_operation)
else:
err.exit_script(err.operand_type)
symtable.set_var(inst.arg1, result_arg)
#3 arg: label symb symb
elif inst.opcode == "JUMPIFEQ" or inst.opcode == "JUMPIFEQS":
if inst.opcode == "JUMPIFEQ":
operand1_arg = symtable.get_value(inst.arg2)
operand2_arg = symtable.get_value(inst.arg3)
else:
operand2_arg = symtable.pops()
operand1_arg = symtable.pops()
if operand1_arg.datatype == "int" and operand2_arg.datatype == "int" or \
operand1_arg.datatype == "string" and operand2_arg.datatype == "string" or \
operand1_arg.datatype == "bool" and operand2_arg.datatype == "bool" or \
operand1_arg.datatype == "nil" and operand2_arg.datatype == "nil":
if operand1_arg.value == operand2_arg.value:
inst_order = labels.jump(inst.arg1)
else:
err.exit_script(err.operand_type)
elif inst.opcode == "JUMPIFNEQ" or inst.opcode == "JUMPIFNEQS":
if inst.opcode == "JUMPIFNEQ":
operand1_arg = symtable.get_value(inst.arg2)
operand2_arg = symtable.get_value(inst.arg3)
else:
operand1_arg = symtable.pops()
operand2_arg = symtable.pops()
if operand1_arg.datatype == "int" and operand2_arg.datatype == "int" or \
operand1_arg.datatype == "string" and operand2_arg.datatype == "string" or \
operand1_arg.datatype == "bool" and operand2_arg.datatype == "bool" or \
operand1_arg.datatype == "nil" and operand2_arg.datatype == "nil":
if operand1_arg.value != operand2_arg.value:
inst_order = labels.jump(inst.arg1)
else:
err.exit_script(err.operand_type)
inst_order += 1
inst_exectuted += 1
if args.stats_vars:
symtable.count_vars()
if args.stats_file != None:
print_stats_to_file(stats_file_stream, inst_exectuted, symtable.max_defined_vars)