From 3b89f609cc50768cd60f196a661b11a51c283e17 Mon Sep 17 00:00:00 2001 From: Scott Owens Date: Mon, 12 Apr 2004 21:14:21 +0000 Subject: [PATCH] *** empty log message *** original commit: 96163685dcbea3076547debb0dd5b6ac1d895a22 --- collects/parser-tools/private-lex/deriv.ss | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/collects/parser-tools/private-lex/deriv.ss b/collects/parser-tools/private-lex/deriv.ss index db70023..b151176 100644 --- a/collects/parser-tools/private-lex/deriv.ss +++ b/collects/parser-tools/private-lex/deriv.ss @@ -244,14 +244,15 @@ (cache (cons 'state (get-key rs)) (lambda () start)) (let loop ((old-states (list start)) (new-states null) + (all-states (list start)) (cs (compute-chars (list start)))) (cond ((and (null? old-states) (null? new-states)) (make-dfa (get-state-number) (state-index start) (mergesort (filter (lambda (x) (cdr x)) - (hash-table-map transitions - (lambda (state _) - (cons (state-index state) (get-final (state-spec state)))))) + (map (lambda (state) + (cons (state-index state) (get-final (state-spec state)))) + all-states)) (lambda (a b) (< (car a) (car b)))) (mergesort (hash-table-map transitions (lambda (state trans) @@ -262,9 +263,9 @@ trans)))) (lambda (a b) (< (car a) (car b)))))) ((null? old-states) - (loop new-states null (compute-chars new-states))) + (loop new-states null all-states (compute-chars new-states))) ((null? cs) - (loop (cdr old-states) new-states (compute-chars (cdr old-states)))) + (loop (cdr old-states) new-states all-states (compute-chars (cdr old-states)))) (else (let* ((state (car old-states)) (c (car cs)) @@ -275,7 +276,8 @@ (new-state (cache (cons 'state (get-key new-re)) (lambda () (set! new-state? #t) - (make-state new-re (get-state-number)))))) + (make-state new-re (get-state-number))))) + (new-all-states (if new-state? (cons new-state all-states) all-states))) (hash-table-put! transitions state (cons (cons c new-state) @@ -283,10 +285,10 @@ (lambda () null)))) (cond (new-state? - (loop old-states (cons new-state new-states) (cdr cs))) + (loop old-states (cons new-state new-states) new-all-states (cdr cs))) (else - (loop old-states new-states (cdr cs)))))) - (else (loop old-states new-states (cdr cs)))))))))) + (loop old-states new-states new-all-states (cdr cs)))))) + (else (loop old-states new-states all-states (cdr cs)))))))))) (define (print-dfa x) (printf "number of states: ~a~n" (dfa-num-states x))