Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## imports ##
- import sys, msvcrt
- ## variables ##
- file = open(sys.argv[1], "r")
- loadstring = file.read()
- tokens, slots = [], []
- index = 0
- identifier_set = "_qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789"
- for i in range(255): slots.append(0)
- ## lexer ##
- while len(loadstring) > index:
- if (loadstring[index] in identifier_set):
- temporary_string = ""
- try:
- while (loadstring[index] in identifier_set):
- temporary_string += loadstring[index]
- index += 1
- except: ...
- tokens.append(temporary_string)
- index += 1
- index = 0
- ## interpreter ##
- while len(tokens) > index:
- ## load and copy #
- if (tokens[index] == "load"):
- index += 1
- value = int(tokens[index])
- index += 1
- slot = int(tokens[index])
- slots[slot] = value
- elif (tokens[index] == "copy"):
- index += 1
- value = slots[int(tokens[index])]
- index += 1
- slot = int(tokens[index])
- slots[slot] = value
- ## set_length ##
- elif (tokens[index] == "set_length"):
- index += 1
- value = int(tokens[index])
- index += 1
- slots = []
- for i in range(value): slots.append(int(tokens[index]))
- ## input ##
- elif (tokens[index] == "get_character"):
- index += 1
- mode = int(tokens[index])
- if (mode == 1): value = ord(msvcrt.getch())
- else: value = int(msvcrt.getch())
- index += 1
- slot = int(tokens[index])
- slots[slot] = value
- elif (tokens[index] == "get_character_output"):
- index += 1
- mode = int(tokens[index])
- if (mode == 1): value = ord(msvcrt.getche())
- else: value = int(msvcrt.getche())
- index += 1
- slot = int(tokens[index])
- slots[slot] = value
- ## compare #
- elif (tokens[index] == "compare"):
- index += 1
- register1 = slots[int(tokens[index])]
- index += 1
- register2 = slots[int(tokens[index])]
- compare_table = [register1, register2]
- ## jump instructions ##
- elif (tokens[index] == "jump_equal"):
- if (compare_table[0] == compare_table[1]):
- index += 1
- jump_index = int(tokens[index])
- index = jump_index
- continue
- elif (tokens[index] == "jump_greater"):
- if (compare_table[0] > compare_table[1]):
- index += 1
- jump_index = int(tokens[index])
- index = jump_index
- continue
- elif (tokens[index] == "jump_less"):
- if (compare_table[0] < compare_table[1]):
- index += 1
- jump_index = int(tokens[index])
- index = jump_index
- continue
- elif (tokens[index] == "jump"):
- index += 1
- jump_index = int(tokens[index])
- index = jump_index
- continue
- ## math operations ##
- elif (tokens[index] == "add"):
- index += 1
- slot1 = int(tokens[index])
- index += 1
- slot0 = int(tokens[index])
- slots[slot0] += slots[slot1]
- elif (tokens[index] == "subtract"):
- index += 1
- slot1 = int(tokens[index])
- index += 1
- slot0 = int(tokens[index])
- slots[slot0] -= slots[slot1]
- elif (tokens[index] == "clamp"):
- index += 1
- slot1 = tokens[index]
- index += 1
- slot0 = tokens[index]
- slots[int(slot0)] = int(str(slots[int(slot1)]) + str(slots[int(slot0)]))
- ## output ##
- elif (tokens[index] == "print"):
- index += 1
- mode = int(tokens[index])
- index += 1
- if (mode == 0): print(slots[int(tokens[index])], end = "")
- else: print(chr(slots[int(tokens[index])]), end = "")
- ## halt / break loop ##
- elif (tokens[index] == "halt"):
- print("process finished!1!1!11!!")
- break
- index += 1
- input("\n")
Add Comment
Please, Sign In to add comment