Forth parser

From ScienceZero
Revision as of 14:33, 24 April 2018 by Bjoern (Talk | contribs) (Created page with " : lsl for dup + next ; ( Simple complete function that implements left shift by repeated addition ) ":" this tells the parser to define a new function "lsl" is the n...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
 : lsl for dup + next ;    ( Simple complete function that implements left shift by repeated addition )
 ":" this tells the parser to define a new function
 "lsl" is the name of the function
 
 
 Adr Value  
 0   0xF0  ( for )
 1   0xE0  ( dup )
 2   0xC0  ( add )
 3   0xF1  ( next )
 
 ltwo tells the parser that it has reached the end of the definition
 
 
 The parser should create an "object" in memory like:
 "lsl",0xF0,0xE0,0xC0,0xF1
 
 
 input text --> look up tables --> output binary
 
 How to encode numbers:
   if number = 0 then emit LDC #0
   else
     find the topmost hex digit that is not 0, call it x
     emit LDC #x
     zero out that digit
     for each remaining digit y, zero or not
     emit LDE #y