Advertisement
Guest User

Untitled

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