Background: As a short project over the winter break, I am trying to implement a programming language called Ax (designed for graphing calculators) using Python and PLY. Short note: the language only allows global variables and uses pointers heavily.
I am trying to implement goto in this language but don’t know how to do it.
My general method is to first use PLY to parse the code in ast, and then go through it, performing when I go.
For example, the statement
If 3 Disp 4 Disp 6 End
... will turn into ...
['PROGRAM', ['BLOCK', ['IF', ['CONDITION', 3], ['BLOCK', ['DISP', 4], ['DISP', 6] ] ] ] ]
... which I would do recursively (I added padding for readability).
Since ast is a tree, I'm not sure how to jump between different nodes. I suggested that perhaps converting the tree to a flat-ish array ['IF', ['CONDITION', 3], ['DISP', 4], ['DISP', 6]] so that I can use the array indices flat-ish to go to specific lines of code, but it doesn’t seem to have a certain elegance and almost feels like a step back (although I could be wrong).
I looked through this one but couldn't figure out how it works.
Any help or tips would be appreciated.