*** empty log message ***

original commit: 5c256671397865fcdae77cb7e6eeb8699a6398e6
tokens
Scott Owens 21 years ago
parent 51f67183a2
commit fddf5e115f

@ -58,14 +58,14 @@
((get-char-groups (->re `(& (* ,r1) (@ (* ,r2) "3") "4") c) #f) ((get-char-groups (->re `(& (* ,r1) (@ (* ,r2) "3") "4") c) #f)
(list r1 r2 (->re "3" c) (->re "4" c))) (list r1 r2 (->re "3" c) (->re "4" c)))
) )
(define loc:member? is:member?)
;; deriveR : re char cache -> re ;; deriveR : re char cache -> re
(define (deriveR r c cache) (define (deriveR r c cache)
(cond (cond
((or (eq? r e) (eq? r z)) z) ((or (eq? r e) (eq? r z)) z)
((char-setR? r) ((char-setR? r)
(if (is:member? c (char-setR-chars r)) e z)) (if (loc:member? c (char-setR-chars r)) e z))
((concatR? r) ((concatR? r)
(let* ((r1 (concatR-re1 r)) (let* ((r1 (concatR-re1 r))
(r2 (concatR-re2 r)) (r2 (concatR-re2 r))
@ -180,6 +180,8 @@
(define (get-key s) (define (get-key s)
(map (lambda (x) (re-index (car x))) s)) (map (lambda (x) (re-index (car x))) s))
(define loc:partition is:partition)
;; compute-chars : (list-of state) -> (list-of char-set) ;; compute-chars : (list-of state) -> (list-of char-set)
;; Computed the sets of equivalent characters for taking the ;; Computed the sets of equivalent characters for taking the
;; derivative of the car of st. Only one derivative per set need to be taken. ;; derivative of the car of st. Only one derivative per set need to be taken.
@ -187,7 +189,7 @@
(cond (cond
((null? st) null) ((null? st) null)
(else (else
(is:partition (map char-setR-chars (loc:partition (map char-setR-chars
(apply append (map (lambda (x) (get-char-groups (car x) #f)) (apply append (map (lambda (x) (get-char-groups (car x) #f))
(state-spec (car st))))))))) (state-spec (car st)))))))))
@ -210,6 +212,8 @@
;; The finals and transitions are sorted by state number, and duplicate free. ;; The finals and transitions are sorted by state number, and duplicate free.
(define-struct dfa (num-states start-state final-states/actions transitions) (make-inspector)) (define-struct dfa (num-states start-state final-states/actions transitions) (make-inspector))
(define loc:get-integer is:get-integer)
;; build-dfa : (list-of re-action) cache -> dfa ;; build-dfa : (list-of re-action) cache -> dfa
(define (build-dfa rs cache) (define (build-dfa rs cache)
(let* ((transitions (make-hash-table)) (let* ((transitions (make-hash-table))
@ -243,7 +247,7 @@
(else (else
(let* ((state (car old-states)) (let* ((state (car old-states))
(c (car cs)) (c (car cs))
(new-re (derive (state-spec state) (is:get-integer c) cache))) (new-re (derive (state-spec state) (loc:get-integer c) cache)))
(cond (cond
(new-re (new-re
(let* ((new-state? #f) (let* ((new-state? #f)

@ -22,6 +22,7 @@
; (define (dfa->1d-table dfa) ; (define (dfa->1d-table dfa)
; (let ( ; (let (
(define loc:foldr is:foldr)
;; dfa->2d-table : dfa -> (same as build-lexer) ;; dfa->2d-table : dfa -> (same as build-lexer)
(define (dfa->2d-table dfa) (define (dfa->2d-table dfa)
@ -38,7 +39,7 @@
(let ((from-state (car trans))) (let ((from-state (car trans)))
(for-each (lambda (chars/to) (for-each (lambda (chars/to)
(let ((to-state (cdr chars/to))) (let ((to-state (cdr chars/to)))
(is:foldr (lambda (char _) (loc:foldr (lambda (char _)
(vector-set! char-table (vector-set! char-table
(bitwise-ior (bitwise-ior
char char
@ -98,13 +99,13 @@
(cache (make-cache)) (cache (make-cache))
(re-acts (map (lambda (s-re-act) (re-acts (time (map (lambda (s-re-act)
(cons (->re (car s-re-act) cache) (cons (->re (car s-re-act) cache)
(cdr s-re-act))) (cdr s-re-act)))
s-re-acts)) s-re-acts)))
(dfa (build-dfa re-acts cache))) (dfa (time (build-dfa re-acts cache))))
;(print-dfa dfa) ;(print-dfa dfa)
;(printf "states: ~a~n" (dfa-num-states dfa)) ;(printf "states: ~a~n" (dfa-num-states dfa))
(values (dfa->2d-table dfa) (dfa-start-state dfa) (dfa->actions dfa) (dfa->no-look dfa)))) (values (time (dfa->2d-table dfa)) (dfa-start-state dfa) (dfa->actions dfa) (dfa->no-look dfa))))
) )

@ -62,10 +62,15 @@
;; The null or `(:) means match nothing. The null carat `(^) means match ;; The null or `(:) means match nothing. The null carat `(^) means match
;; any character. The null intersection `(&) means match string.) ;; any character. The null intersection `(&) means match string.)
(define loc:make-range is:make-range)
(define loc:union is:union)
(define loc:split is:split)
(define loc:complement is:complement)
;; ->re : s-re cache -> re ;; ->re : s-re cache -> re
(define (->re exp cache) (define (->re exp cache)
(match exp (match exp
((? char?) (build-char-set (is:make-range (char->integer exp)) cache)) ((? char?) (build-char-set (loc:make-range (char->integer exp)) cache))
((? string?) (->re `(@ ,@(string->list exp)) cache)) ((? string?) (->re `(@ ,@(string->list exp)) cache))
((? re?) exp) ((? re?) exp)
(`(epsilon) (build-epsilon)) (`(epsilon) (build-epsilon))
@ -80,12 +85,12 @@
(build-or (list e c) cache)))) (build-or (list e c) cache))))
(`(: ,rs ...) (`(: ,rs ...)
(build-or (flatten-res (map (lambda (r) (->re r cache)) rs) (build-or (flatten-res (map (lambda (r) (->re r cache)) rs)
orR? orR-res is:union cache) orR? orR-res loc:union cache)
cache)) cache))
(`(& ,rs ...) (`(& ,rs ...)
(build-and (flatten-res (map (lambda (r) (->re r cache)) rs) (build-and (flatten-res (map (lambda (r) (->re r cache)) rs)
andR? andR-res (lambda (a b) andR? andR-res (lambda (a b)
(let-values (((i _ __) (is:split a b))) i)) (let-values (((i _ __) (loc:split a b))) i))
cache) cache)
cache)) cache))
(`(~ ,r) (`(~ ,r)
@ -99,14 +104,14 @@
(let ((i1 (char->integer (if (string? c1) (string-ref c1 0) c1))) (let ((i1 (char->integer (if (string? c1) (string-ref c1 0) c1)))
(i2 (char->integer (if (string? c2) (string-ref c2 0) c2)))) (i2 (char->integer (if (string? c2) (string-ref c2 0) c2))))
(if (<= i1 i2) (if (<= i1 i2)
(build-char-set (is:make-range i1 i2) cache) (build-char-set (loc:make-range i1 i2) cache)
z))) z)))
(`(^ ,crs ...) (`(^ ,crs ...)
(let ((cs (->re `(: ,@crs) cache))) (let ((cs (->re `(: ,@crs) cache)))
(cond (cond
((zeroR? cs) (build-char-set (is:make-range 0 255) cache)) ((zeroR? cs) (build-char-set (loc:make-range 0 255) cache))
((char-setR? cs) ((char-setR? cs)
(build-char-set (is:complement (char-setR-chars cs) 0 255) cache)) (build-char-set (loc:complement (char-setR-chars cs) 0 255) cache))
(else z)))))) (else z))))))
@ -140,9 +145,11 @@
(define (build-zero) z) (define (build-zero) z)
(define loc:integer-set-contents is:integer-set-contents)
;; build-char-set : char-set cache -> re ;; build-char-set : char-set cache -> re
(define (build-char-set cs cache) (define (build-char-set cs cache)
(let ((l (is:integer-set-contents cs))) (let ((l (loc:integer-set-contents cs)))
(cond (cond
((null? l) z) ((null? l) z)
(else (else

Loading…
Cancel
Save