Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define (list-head s i stek)
- (if (= i 0) stek (list-head (cdr s) (- i 1) (append stek (list (car s))))))
- (define (findclose s i)
- (if (null? s)
- #f
- (if (eq? (car s) #\)) i (findclose (cdr s) (+ i 1)))))
- (define (findopen s i)
- (if (or (not i) (= i (- 1)))
- #f
- (if (eq? (list-ref s i) #\() i (findopen s (- i 1)))))
- (define (convert s)
- (if (string->number s) (string->number s) (string->symbol s)))
- (define (read-string s)
- (define (skan s i stek st)
- (if (< i 0)
- (if (eq? st "")
- stek
- (cons (convert st)stek))
- (let ((a (string-ref s i)))
- (cond ((or (eq? a #\() (eq? a #\))) (skan s (- i 1) (cons a (if (eq? st "") stek (cons (convert st) stek))) ""))
- ((or (eq? a #\space) (eq? a #\newline) (eq? a #\tab))
- (if (eq? "" st)
- (skan s (- i 1) stek "")
- (skan s (- i 1) (cons (convert st) stek) "")))
- (else (skan s (- i 1) stek (string-append (string a) st)))))))
- (define (list->list s)
- (let* ((r (findclose s 0))
- (l (findopen s r)))
- (if l
- (list->list (append (list-head s l '()) (list (list-head (list-tail s (+ l 1)) (- r l 1) '())) (list-tail s (+ r 1))))
- s)))
- (define (checking s k)
- (if (null? s)
- (zero? k)
- (if (< k 0)
- #f
- (cond ((eq? (car s) #\() (checking (cdr s) (+ k 1)))
- ((eq? (car s) #\)) (checking (cdr s) (- k 1)))
- (else (checking (cdr s) k))))))
- (define (check s)
- (if (and (> (length s) 1) (not (eq? (car s) #\())) #f (checking s 0)))
- (let ((s (skan s (- (string-length s) 1) '() "")))
- (if (and (check s) (not (null? s))) (car (list->list s)) #f)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement