summaryrefslogtreecommitdiff
path: root/tests/lispparser.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lispparser.lisp')
-rw-r--r--tests/lispparser.lisp36
1 files changed, 22 insertions, 14 deletions
diff --git a/tests/lispparser.lisp b/tests/lispparser.lisp
index 4579b93..1d8c79c 100644
--- a/tests/lispparser.lisp
+++ b/tests/lispparser.lisp
@@ -9,7 +9,7 @@
(str-elem ch " \n\t\r"))
(define isdigit? (ch)
- (let ((n (ord ch))) (and (<= 48 n) (<= 57 n))))
+ (let ((n (ord ch))) (and (<= 48 n) (<= n 57))))
(define lowercase? (ch)
(let ((n (ord ch))) (and (<= 97 n) (<= n 122))))
@@ -18,7 +18,7 @@
(let ((n (ord ch))) (and (<= 65 n) (<= n 90))))
(define iswordchar? (ch)
- (or (str-elem ch "-_?")
+ (or (str-elem ch "-_?+/*")
(or (lowercase? ch) (uppercase? ch))))
(define isrestwordchar? (ch)
@@ -47,15 +47,23 @@
(list "(" rest)
(= ch ")")
(list ")" rest)
- (iswordchar? ch)
- (let ((restword (take-while isrestwordchar? rest)))
- (list (concat ch restword) (substr (length restword) -1 rest)))
- (isdigit? ch)
- (let ((word (concat ch (take-while isdigit? rest))))
- (list (parse-int word) (substr (length word) -1 str)))
- (do
- (print (concat "Invalid token: " ch))
- (exit)))))
-
-; (define parse-sexpr (tokens)
-; ...)
+ (or (iswordchar? ch) (isdigit? ch))
+ (let ((restword (take-while isrestwordchar? rest))
+ (rest2 (substr (length restword) -1 rest)))
+ (if (and (all isdigit? restword)
+ (or (isdigit? ch) (and (= ch "-") (> (length restword) 0))))
+ (list (parse-int (concat ch restword)) rest2)
+ (list (concat ch restword) rest2)))
+ (error (concat "Invalid token: " ch)))))
+
+(define go (lambdarec rec (str)
+ (let ((pair (next-token str)))
+ (if (null? pair)
+ '()
+ (let ((token (car pair))
+ (rest (cadr pair)))
+ (do
+ (print token)
+ (rec rest)))))))
+
+(go (read-file "tests/closuretest.lisp"))