define is_operator input and member input define is_sep input and memb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(define (is_operator? input)
(and (member input '(#\+ #\- #\/ #\*)) #t))
(define (is_sep? input)
(and (member input '(#\space #\tab #\newline)) #t))
(define (digit? input)
(and (>= (char->integer input) 48)
(<= (char->integer input) 57)))
(define (make-numbers xs)
(cond ((null? xs) '())
((empty? xs) #f)
(else (if (not (equal? (car xs) ""))
(cons (string->number (car xs))
(make-numbers (cdr xs)))
(make-numbers (cdr xs))))))
(define (empty? xs)
(member (car xs) '("+" "-" "/" "*")))
(define (sign? x)
(if (eq? x #\-)
-
+))
(define (check-integer string)
(define (f x i)
(cond ((null? x))
((and (= i 0)
(> (length x) 1)
(sign? (car x)))
(f (cdr x) (+ i 1)))
((digit? (car x)) (f (cdr x) 1))
(else #f)))
(f (string->list string) 0))
(define (scan-integer input)
(cond ((check-integer input) input)
(else #f)))
(define (scan-many-integers string)
(define (f x stack result)
(cond ((null? x) (make-numbers (reverse (cons (list->string (reverse stack))
result))))
((and (is_sep? (car x))
(null? stack)) (f (cdr x) stack result))
((is_sep? (car x)) (f (cdr x) '() (cons (list->string (reverse stack))
result)))
((or (and (null? stack)
(sign? (car x)))
(digit? (car x)))
(f (cdr x) (cons (car x) stack) result))
(else #f)))
(f (string->list string) '() '()))