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
21 create parse-idx-stack 10 allot
23 parse-idx-stack parse-idx-sp !
26 parse-idx @ parse-idx-sp @ !
31 parse-idx-sp @ parse-idx-stack <= abort" Parse index stack underflow."
35 parse-idx-sp @ @ parse-idx ! ;
39 '\n' parse-str parse-str-span @ + !
47 parse-str 160 expect cr
48 span @ parse-str-span !
58 : charavailable? ( -- bool )
59 parse-str-span @ parse-idx @ > ;
61 : nextchar ( -- char )
62 charavailable? false = if getline then
63 parse-str parse-idx @ + @ ;
65 : whitespace? ( -- bool )
74 nextchar [char] ( = or
75 nextchar [char] ) = or
95 digit? minus? or false = if
116 : boolean? ( -- bool )
117 nextchar [char] # <> if false exit then
124 and if pop-parse-idx false exit then
136 : str-equiv? ( str -- bool )
151 delim? <> if drop false then
156 : character? ( -- bool )
157 nextchar [char] # <> if false exit then
162 nextchar [char] \ <> if pop-parse-idx false exit then
166 S" newline" str-equiv? if true exit then
167 S" space" str-equiv? if true exit then
168 S" tab" str-equiv? if true exit then
170 charavailable? false = if pop-parse-idx false exit then
175 : readnum ( -- num-atom )
183 10 * nextchar [char] 0 - +
192 : readbool ( -- bool-atom )
195 nextchar [char] f = if
206 : readchar ( -- char-atom )
210 S" newline" str-equiv? if '\n' character-type exit then
211 S" space" str-equiv? if bl character-type exit then
212 S" tab" str-equiv? if 9 character-type exit then
214 nextchar character-type
219 \ Parse a scheme expression
240 bold fg blue ." Moriturus te saluto." reset-term ." ok" cr
244 bold fg red ." Error parsing string starting at character '"
246 ." '. Aborting." reset-term cr
252 : self-evaluating? ( obj -- obj bool )
253 number-type istype? if true exit then
254 boolean-type istype? if true exit then
262 bold fg red ." Error evaluating expression - unrecognized type. Aborting." reset-term cr
268 : printnum ( numobj -- ) drop . ;
270 : printbool ( numobj -- )
278 : printchar ( charobj -- )
282 bl of ." #\space" endof
283 '\n' of ." #\newline" endof
289 number-type istype? if printnum exit then
290 boolean-type istype? if printbool exit then
291 character-type istype? if printchar exit then
297 cr ." Welcome to scheme.forth.jl!" cr
298 ." Use Ctrl-D to exit." cr
303 cr bold fg green ." > " reset-term
306 fg cyan print reset-term