Reverse Polish Notation. Forth is the main language.
RPN is evaluated strictly left to right. There is a data stack, which is in an array (or more strictly, a last-in first-out queue).
Numbers are pushed onto the stack in order in which they are encountered, so if we have tokens 27 33 the stack looks like this:
- 33 // top stack - known as TOS
- 27
Operators pop things from the stack and do something with them, so + in the example will pop two values, add them, and then push the result onto the stack:
- 60
There are many stack operators which manipulate the stack. We could define a new "word" using the definition introducer :
: SQUARED DUP * ;
We could then have: 2 SQUARED
This would push a 2 onto the stack, push a copy of the TOS value onto the stack, multiply the two values on the stack and push the result onto the stack.
Without going into too much detail, the system consists of a
Dictionary (the keywords or defined words, a
Code Area, which contains what the words in the dictionary do, a
Data Stack (as above) and a
Return Stack, which goes back to the point where a new word was executed (think gosub and return).
Finally - if an unknown word is used (such as 23) the interpreter attempts to convert it to a number.
It would be fairly easy to make a simple system for AppGameKit T1. But actually I think for most people it would be better to have the Basic compiler (optionally) built into the run-time system, so that scripts could be parsed, compiled and executed.
Onwards and sometimes upwards