3 ms·
The tokens coming in are the tokens from the user's ("Him") input. The outer interpreter is what translates those tokens into actions to perform. The inner inte
by Someone 13y ago
The tokens coming in are the tokens from the user's ("Him") input. The outer interpreter is what translates those tokens into actions to perform. The inner interpreter performs those actions.
In a Forth, both the inner and the outer interpreter are extremely simple. The story describes them in detail.
Outer interpreter: look up token in dictionary/dictionaries. If found, instruct inner interpreter to execute it by giving it the address of the function that the token describes. If not found, try interpreting the word as a number in the current base. If that succeeds, push the number on the stack. If it fails, signal an error and clear some state.
Inner interpreter: start reading at the address supplied. Recursively interpret every word read as address of another function until encountering a 'end of function' marker.
Leo Brodie's variant of this story doesn't use the terms inner and outer interpreter because it was written before the names were invented, but it may be instructive, anyways: http://www.forth.com/starting-forth/sf1/sf1.html http://www.forth.com/starting-forth/sf1/sf1.html
- raverbashing 13y agoSo the inner interpreter is a VM of some sort? Outer interpreter looks like exactly that, an interpreter (as opposed to a compiler)
- Someone 13y agoYes, it has been described as such. A main difference/interesting property of this VM is that end users write programs in Forth by extending the VM's instruction set (= the set of dictionary definitions). While in interpreted mode or at compile time (i.e. when the user types words in the terminal), the instruction lookup is slow, through one or more linked lists. At run time, definitions simply consist of lists of pointers to other functions.