implement vectors
This commit is contained in:
+9
-35
@@ -1,36 +1,10 @@
|
||||
(import "sets.slime")
|
||||
(define-module automata
|
||||
:exports (make-dfa)
|
||||
(import "sets.slime")
|
||||
|
||||
|
||||
(define (make-dfa Q S delta q0 F)
|
||||
(let ((q q0))
|
||||
(lambda (s)
|
||||
(mutate q (delta q s))
|
||||
`(,(if (set-contains? F q) :accept :fail) ,q))))
|
||||
|
||||
|
||||
(define (delta q s)
|
||||
(cond (s (case q
|
||||
(("q0") (case s (("M") "q1")))
|
||||
(("q1") (case s (("A") "q0")
|
||||
(("G") "q2")))
|
||||
(("q2") (case s (("E") "q0")))))
|
||||
(else q)))
|
||||
|
||||
|
||||
;; (make-delta
|
||||
;; ("q0" :: "M" -> "q1")
|
||||
;; ("q1" :: "A" -> "q0"
|
||||
;; "G" -> "q1")
|
||||
;; ("q2" :: "E" -> "q0"))
|
||||
|
||||
(define aut (make-dfa (make-set "q0" "q1" "q2")
|
||||
(make-set "M" "A" "G" "E")
|
||||
delta
|
||||
"q0"
|
||||
(make-set "q0")))
|
||||
|
||||
(printf (aut "M"))
|
||||
(printf (aut "A"))
|
||||
(printf (aut "M"))
|
||||
(printf (aut "G"))
|
||||
(printf (aut "E"))
|
||||
(define (make-dfa Q S delta q0 F)
|
||||
(let ((q q0))
|
||||
(lambda (s)
|
||||
(set! q (delta q s))
|
||||
(list (if (set::contains? F q) :accept :fail) q))))
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user