Background: As a short project over winter break, I'm trying to implement a programming language called Axe (designed for graphing calculators) using Python and PLY. A brief note: the language allows only global variables and makes heavy use of pointers.
I'm trying to implement goto in this language, but have no idea how to do it.
My general method is to first use PLY to parse the code into an ast, then walk through it executing as I go.
For example, the statement
If 3
Disp 4
Disp 6
End
...would turn into...
['PROGRAM',
['BLOCK',
['IF',
['CONDITION', 3],
['BLOCK',
['DISP', 4],
['DISP', 6]
]
]
]
]
...which I would execute recursively (I added indents for readability).
Because the ast is a tree, I'm not sure how to jump between different nodes. I've considered perhaps converting the tree to a flat-ish array ['IF', ['CONDITION', 3], ['DISP', 4], ['DISP', 6]]
so that I can use the indices of the flat-ish array to go to specific lines in the code, but this seems to lack a certain elegance and almost feels like a step backwards (although I could be wrong).
I've looked at this, but was unable to understand how it worked.
Any help or hints would be appreciated.
goto
there are other problem - loops. How you want to implement loops without some sort of program counter? – Heddi