4 ms·
And what's a point in such a complex approach, if a proper interpreter (or, even better, compiler) is much simpler?
by sklogic 11y ago
And what's a point in such a complex approach, if a proper interpreter (or, even better, compiler) is much simpler?
- Someone 11y agoComplex? Its building up from almost nothing, and shows how simple an interpreter can be. If you start with a grammar, you lose half your audience within 5 minutes (numbers made up) If you start with a program that reads a text file and plays notes for lines contaning do, re, and mi, part of that lost audience will get drawn in, complete the scale, add 'fart' commands, etc. Also, smart kids may figure out they can easily add single-statement loops on their own, by adding a case 'repeat' that scans for the number of iterations, removes the 'repeat' and that number of iterations from the line, and then calls the 'processALine' code. It's "learn by playing" vs "learn through study".
- sklogic 11y agoYou do not have to do such clumsy things to build from nothing. Split the input by whitespaces, lookup word definitions in a table (linked list is ok), push the addresses of the found words to the output stream as call instructions or execute immediately if marked so. That's it, a minimal direct threaded Forth compiler is done.