From: Tim Vaughan Date: Sun, 12 Jun 2016 08:28:59 +0000 (+1200) Subject: Fiddling with parser (reader?) X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=123ce52c0fe63b568a3c9c11dc1b85d4dfd17c8e;p=scheme.forth.jl.git Fiddling with parser (reader?) --- diff --git a/scheme.4th b/scheme.4th index 65c64a8..48ab564 100644 --- a/scheme.4th +++ b/scheme.4th @@ -19,6 +19,16 @@ create types memsize allot variable nextfree 0 nextfree ! +: make-bool + nextfree @ + + car nextfree @ + ! + cdr nextfree @ + 0 ! + types nextfree @ + bool-type ! + + 1 nextfree +! +; + : stack create here 1+ , allot ; @@ -80,25 +90,36 @@ variable parse-str : parsebool - nextchar emit cr - trace - - false - nextchar [char] # <> if exit then + nextchar [char] # <> if false exit then 1 inc-parse-idx nextchar dup [char] t = swap [char] f = or not if 1 dec-parse-idx - exit + false exit then 1 inc-parse-idx ?delim not if 2 dec-parse-idx - exit + false exit + else + 1 dec-parse-idx + nextchar [char] t = make-bool + 1 inc-parse-idx + true exit + then +; + +\ Set cdr at i to j, leaving j on the stack +: append ( i j -- j ) + dup rot + dup 0> if + cdr + ! + else + 2drop then ; @@ -119,8 +140,9 @@ variable parse-str then parsebool if + append exit - exit + then ; \ Parse a counted string into a scheme expression