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
22 create parse-idx-stack 10 allot
24 parse-idx-stack parse-idx-sp !
27 parse-idx @ parse-idx-sp @ !
32 parse-idx-sp @ parse-idx-stack <= abort" Parse index stack underflow."
36 parse-idx-sp @ @ parse-idx ! ;
40 '\n' parse-str parse-str-span @ + !
48 parse-str 160 expect cr
49 span @ parse-str-span !
59 : charavailable? ( -- bool )
60 parse-str-span @ parse-idx @ > ;
62 : nextchar ( -- char )
63 charavailable? false = if getline then
64 parse-str parse-idx @ + @ ;
66 : whitespace? ( -- bool )
75 nextchar [char] ( = or
76 nextchar [char] ) = or
96 digit? minus? or false = if
117 : boolean? ( -- bool )
118 nextchar [char] # <> if false exit then
125 and if pop-parse-idx false exit then
137 : str-equiv? ( str -- bool )
152 delim? <> if drop false then
157 : character? ( -- bool )
158 nextchar [char] # <> if false exit then
163 nextchar [char] \ <> if pop-parse-idx false exit then
167 S" newline" str-equiv? if true exit then
168 S" space" str-equiv? if true exit then
169 S" tab" str-equiv? if true exit then
171 charavailable? false = if pop-parse-idx false exit then
176 : readnum ( -- num-atom )
184 10 * nextchar [char] 0 - +
193 : readbool ( -- bool-atom )
196 nextchar [char] f = if
207 \ Parse a scheme expression
223 bold fg blue ." Moriturus te saluto." reset-term ." ok" cr
227 bold fg red ." Error parsing string starting at character '"
229 ." '. Aborting." reset-term cr
235 : self-evaluating? ( obj -- obj bool )
236 number-type istype? if true exit then
237 boolean-type istype? if true exit then
245 bold fg red ." Error evaluating expression - unrecognized type. Aborting." reset-term cr
251 : printnum ( numobj -- ) drop . ;
253 : printbool ( numobj -- )
263 number-type istype? if printnum exit then
264 boolean-type istype? if printbool exit then
270 cr ." Welcome to scheme.forth.jl!" cr
271 ." Use Ctrl-D to exit." cr
276 cr bold fg green ." > " reset-term
279 fg cyan print reset-term