Add standard library and preload command line parameter
This commit is contained in:
parent
cf86b463b2
commit
620bcfc951
18
rforth.py
18
rforth.py
|
@ -1,3 +1,4 @@
|
|||
import argparse
|
||||
stack = []
|
||||
compiling = False
|
||||
words = {}
|
||||
|
@ -201,11 +202,24 @@ def add_to_stack(value):
|
|||
stack.insert(0, int(value))
|
||||
|
||||
|
||||
def main():
|
||||
def main(args):
|
||||
if args.preload != None:
|
||||
f = open(args.preload, "r")
|
||||
file_data = f.readlines()
|
||||
preload = []
|
||||
for line in file_data:
|
||||
split_line = line.split(' ')
|
||||
for word in split_line:
|
||||
preload.append(word)
|
||||
parse_input(preload, False)
|
||||
f.close()
|
||||
print("Welcome to rforth!")
|
||||
while True:
|
||||
i = get_input()
|
||||
parse_input(i.split(' '))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
parser = argparse.ArgumentParser(description='A weird little Forth implementation')
|
||||
parser.add_argument('-p', '--preload', default="standard-library.f", type=str, help='A file to preload')
|
||||
args = parser.parse_args()
|
||||
main(args)
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
: loop 1 swap - 2dup . 0 = if else loop then ;
|
||||
: loop2 2 swap - 2dup . 0 = if else loop2 then ;
|
Loading…
Reference in New Issue