Advertisement
Guest User

Untitled

a guest
Jun 7th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 0.68 KB | None | 0 0
  1. "a(ab|ba)+aa*b"
  2. (define (acc1 lst)
  3.   (cond ((null? lst) #f)
  4.         ((eq? (car lst) 'a) (acc2 (cdr lst)))))
  5. (define (acc2 lst)
  6.   (cond ((null? lst) #f)
  7.         ((null? (cdr lst)) #f)
  8.         ((and (eq? (car lst) 'a) (eq? (cadr lst) 'a)) (acc3 (cddr lst)))
  9.         ((and (eq? (car lst) 'a) (eq? (cadr lst) 'b) (null? (cddr lst))) #t)
  10.         ((and (eq? (car lst) 'a) (eq? (cadr lst) 'b)) (acc2 (cddr lst)))
  11.         ((and (eq? (car lst) 'b) (eq? (cadr lst) 'a)) (acc2 (cddr lst)))
  12.         (else #f)
  13.         ))
  14. (define (acc3 lst)
  15.   (cond ((null? lst) #f)
  16.         ((eq? (car lst) 'a) (acc3 (cdr lst)))
  17.         ((and (eq? (car lst) 'b) (null? (cdr lst))) #t)
  18.         (else #f)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement