Add basic string support

This commit is contained in:
rmgr 2022-06-29 17:09:31 +09:30
parent 9b90f3fa33
commit 680626f125
1 changed files with 22 additions and 4 deletions

View File

@ -1,9 +1,10 @@
#!/usr/bin/python3
import argparse
stack = []
heap = [0] * 20
heap = [0] * 100
next_heap = 0
compiling = False
reading_string = False
words = {}
word_name = ""
@ -19,7 +20,7 @@ def get_input():
def parse_input(input_string, say_ok=True):
while len(input_string) > 0:
string = str(input_string[0])
if not compiling:
if not compiling and not reading_string:
if string.isnumeric():
add_to_stack(string)
elif string == "stack":
@ -66,7 +67,14 @@ def parse_input(input_string, say_ok=True):
dump_heap()
elif string == "alloc":
alloc()
else:
elif string == 's"':
start_reading_string()
elif reading_string:
if string == '"':
stop_reading_string()
else:
add_new_word_to_string(string)
elif compiling and not reading_string:
if string == ";":
stop_compiling()
else:
@ -74,7 +82,9 @@ def parse_input(input_string, say_ok=True):
input_string = get_next(input_string)
if say_ok:
print("ok.")
def add_new_word_to_string(string):
for char in string[::-1]:
stack.insert(0, ord(char))
def dump_heap():
print(heap)
@ -179,6 +189,14 @@ def add_to_new_word(value):
else:
words[word_name] = words[word_name] + value + " "
def start_reading_string():
global reading_string
reading_string = True
def stop_reading_string():
global reading_string
reading_string = False
def start_compiling():
global compiling
compiling = True