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
108 delim? charavailable? false = or if
117 : boolean? ( -- bool )
118 nextchar [char] # <> if false exit then
125 and if pop-parse-idx false exit then
131 : str-equiv? ( str -- bool )
146 delim? <> if drop false then
151 : character? ( -- bool )
152 nextchar [char] # <> if false exit then
157 nextchar [char] \ <> if pop-parse-idx false exit then
161 S" newline" str-equiv? if true exit then
162 S" space" str-equiv? if true exit then
163 S" tab" str-equiv? if true exit then
165 charavailable? false = if pop-parse-idx false exit then
170 : readnum ( -- num-atom )
178 10 * nextchar [char] 0 - +
187 : readbool ( -- bool-atom )
190 nextchar [char] f = if
201 \ Parse a scheme expression
217 bold fg blue ." Moriturus te saluto." reset-term ." ok" cr
221 bold fg red ." Error parsing string starting at character '"
223 ." '. Aborting." reset-term cr
229 : self-evaluating? ( obj -- obj bool )
230 number-type istype? if true exit then
231 boolean-type istype? if true exit then
239 bold fg red ." Error evaluating expression - unrecognized type. Aborting." reset-term cr
245 : printnum ( numobj -- ) drop . ;
247 : printbool ( numobj -- )
257 number-type istype? if printnum exit then
258 boolean-type istype? if printbool exit then
264 cr ." Welcome to scheme.forth.jl!" cr
265 ." Use Ctrl-D to exit." cr
270 cr bold fg green ." > " reset-term
273 fg cyan print reset-term