I need help on getting an interpreter to work. I have this 'bumpkin' code as a list right here.
LET A 1
GOSUB 6 <------ goes to line 6 of 'bumpkin' code (index starts at 1).
PRINT A
PRINT B
END
LET A 2
LET B 3
RETURN <------- returns to GOSUB 6 and continues on down list
Technically what GOSUB does is that it goes to the specified line (in this case line 6) and continues down until it hits RETURN and goes back to it again and continues on.
So technically while going in a downward fashion in the list, the GOSUB skips around the list a bit until it gets a call signal RETURN and then returns to the GOSUB line and continues downward again.
The main problem is that I don't know how to do this and append it to a new list so it becomes a new list of objects so I can execute it. The resulting new list would be:
LET A 1
LET A 2
LET B 3
PRINT A
PRINT B
END
I was curious how I would approach this. I can't use a for loop because then it'll loop through the entire 'bumpkin' code and parse them. I can't skip any lines with a loop.
Many thanks!
EDIT===========================================================EDIT
So heres my Python code so far:
oldlist = [['LET', 'A', '1'],
['GOSUB', '6'],
['PRINT', 'A'],
['PRINT', 'B'],
['END'],
['LET', 'A', '2'],
['LET', 'B', '3'],
['RETURN'],
['.']]
newlist = []
def NewLister():
ProgramCounter = 0
funcbool = True
while funcbool:
if oldlist[ProgramCounter][0] == 'LET':
newlist.append(oldlist[ProgramCounter])
ProgramCounter += 1
print(newlist)
elif oldlist[ProgramCounter][0] == 'GOSUB':
pass # <---------------------No Idea how to get this working
elif oldlist[ProgramCounter][0] == 'PRINT':
pass
elif oldlist[ProgramCounter][0] == 'END':
pass