6 include term-colours.4th
9 1 constant boolean-type
10 2 constant character-type
11 : istype? ( obj -- obj b )
17 variable stored-parse-idx
18 create parse-str 161 allot
19 variable parse-str-span
23 '\n' parse-str parse-str-span @ + ! ;
27 span @ parse-str-span !
38 parse-idx @ stored-parse-idx ! ;
41 stored-parse-idx @ parse-idx ! ;
44 : charavailable? ( -- bool )
45 parse-str-span @ parse-idx @ >
48 : nextchar ( -- char )
49 charavailable? false = if getline then
50 parse-str parse-idx @ + @ ;
52 : whitespace? ( -- bool )
59 nextchar [char] ( = or
60 nextchar [char] ) = or
80 digit? minus? or false = if
92 delim? charavailable? false = or if
101 : boolean? ( -- bool )
102 nextchar [char] # <> if false exit then
109 and if restore-parse-idx false exit then
115 : character? ( -- bool )
116 nextchar [char] # <> if false exit then
121 nextchar [char] \ <> if restore-parse-idx false exit then
125 charavailable? false = if restore-parse-idx false exit then
127 restore-parse-idx true
130 : readnum ( -- num-atom )
138 10 * nextchar [char] 0 - +
147 : readbool ( -- bool-atom )
150 nextchar [char] f = if
159 \ Parse a scheme expression
174 bold fg red ." Error parsing string starting at character '"
176 ." '. Aborting." reset-term cr
182 : self-evaluating? ( obj -- obj bool )
183 number-type istype? if true exit then
184 boolean-type istype? if true exit then
192 bold fg red ." Error evaluating expression - unrecognized type. Aborting." reset-term cr
198 : printnum ( numobj -- ) drop . ;
200 : printbool ( numobj -- )
210 number-type istype? if ." => " printnum exit then
211 boolean-type istype? if ." => " printbool exit then
217 cr ." Welcome to scheme.forth.jl!" cr
218 ." Use Ctrl-D to exit." cr
221 cr bold fg green ." > " reset-term
224 fg cyan print reset-term