6 include term-colours.4th
9 1 constant boolean-type
10 2 constant character-type
11 : istype? ( obj -- obj b )
17 variable dummy-parse-idx
26 parse-idx @ dummy-parse-idx ! ;
29 dummy-parse-idx @ parse-idx ! ;
33 : charavailable? ( -- bool )
34 parse-str @ @ parse-idx @ >
37 : nextchar ( -- char )
39 parse-str @ 1+ parse-idx @ + @
45 : whitespace? ( -- bool )
52 nextchar [char] ( = or
53 nextchar [char] ) = or
73 digit? minus? or false = if
85 delim? charavailable? false = or if
94 : boolean? ( -- bool )
95 nextchar [char] # <> if false exit then
102 and if restore-parse-idx false exit then
108 : character? ( -- bool )
109 nextchar [char] # <> if false exit then
114 nextchar [char] \ <> if restore-parse-idx false exit then
118 charavailable? false = if restore-parse-idx false exit then
120 restore-parse-idx true
123 : readnum ( -- num-atom )
131 10 * nextchar [char] 0 - +
140 : readbool ( -- bool-atom )
143 nextchar [char] f = if
152 \ Parse a counted string into a scheme expression
167 bold fg red ." Error parsing string starting at character '"
169 ." '. Aborting." reset-term cr
175 : self-evaluating? ( obj -- obj bool )
176 number-type istype? if true exit then
177 boolean-type istype? if true exit then
185 bold fg red ." Error evaluating expression - unrecognized type. Aborting." reset-term cr
191 : printnum ( numobj -- ) drop . ;
193 : printbool ( numobj -- )
203 number-type istype? if ." => " printnum exit then
204 boolean-type istype? if ." => " printbool exit then
209 create repl-buffer 161 allot
210 repl-buffer parse-str !
213 repl-buffer 1+ 160 expect span @ repl-buffer ! ;
216 repl-buffer @ 0= if false exit then
217 repl-buffer 1+ @ 4 <> if false exit then
221 cr ." Welcome to scheme.forth.jl!" cr
222 ." Use Ctrl-D to exit." cr
225 cr bold fg green ." > " reset-term
229 cr bold fg blue ." Moriturus te saluto." reset-term
237 fg cyan print reset-term