BitWise wrote:
BASIC and LISP are normally interpreted on 8-bit machines.
BASIC is a curios one in many respects. FORTRAN too, surprisingly. One way to compile FORTRAN is a one-pass compiler that generates an intermediate code plus a symbol table - a block of variable storage, if you like, followed by an interpreter for this intermediate code. I have such a system on my PDP-8.
BASIC - often 'tokenised' then "detokenised" for the LIST or editing command (With note that some Forths do this too) However some BASICS only tokenise the keywords, so you end up with
Code:
PRINT 3.14
being stored as a token for PRINT, then the textual representation of 3.14 which has to subsequently be parsed at run-time.
Some years back I wrote what I considered my "ideal" BASIC and I took it a stage further - I turned
everything into a token. So the above was turned into 2 tokens - one for keyword and one for a constant - stored in floating point binary representation a symbol table. The token was an index into the symbol table. That made run-time fast as there were never any numbers to parse or variables to create storage for. It also made LIST hard because you now had a binary representation of a number to print out (So I cheated and also stored the textual representation for nothing other than the LIST command. I even tokenised comments.
Back to compilers - what I did was essentially a one-pass compiler with the symbol table and some run-time fixups (scan for goto/gosub/proc/func targets) there is also a "just in time" compiler for expression evaluation - I cache the RPN generated by the shunting yard expression evaluator so turning that into a 2-pass compiler would not be that hard - and it's on my "to-do" list once I'm happy with my BCPL system on my '816 board. (Although plan A there is to translate the existing tokeniser/sym. table builder into BCPL then have the run-time in ASM, however after doing a lot more with BCPL I'm now looking at compiling directly into code for the BCPL Cintcode VM)
Cheers,
-Gordon
_________________
--
Gordon Henderson.
See my
Ruby 6502 and 65816 SBC projects here:
https://projects.drogon.net/ruby/