# attempt to write parser in forth # bootstrapping is done using preparse.pf # REQUIREMENTS: # * needs to be pre-emptable # * needs to be re-enterable # * needs to be able to be fed by character source # special characters : open? 0x28 = ; # ( : close? 0x29 = ; # ) : quote? 0x22 = ; # " : backslash? 0x5c = ; # \ : newline? 0x0d = ; # \n : comment? 0x23 = ; # # : space? 0x20 = ; # space : tab? 0x08 = ; # tab : whitespace? >r r newline? r space? or r> space? or ; # state variable parser-in variable parser-out 10 variable! base : next-char parser-in pop ; # eof handler : eof ` eof throw ; # converters # numbers : range? >r dup 0 >= swap r> < and ; : a-z? 0x61 - 26 range? ; : A-Z? 0x41 - 26 range? ; : 0-9? 0x30 - 10 range? ; : >upper dup a-z? if 0x20 - then ; : digit dup 0-9? if 0x30 - leave then >upper dup A-Z? if [ 10 0x41 - ]L + leave then -1 ; : base? base @ range? ; : >base split? if >r swap base @ * r> + swap pass >base then ; : >number ' digit map 0 swap >base ; # other : skip-ws next-char dup whitespace? if drop pass skip-ws then ; : read-char skip-ws ; # what about REQUIRING a whitespace before and after lists? this will # make the grammar simpler, and also the parser, but no longer # compatible with s-expressions