|
|
@ -6,6 +6,7 @@
|
|
|
|
(require "lr0.ss"
|
|
|
|
(require "lr0.ss"
|
|
|
|
"grammar.ss"
|
|
|
|
"grammar.ss"
|
|
|
|
"array2d.ss"
|
|
|
|
"array2d.ss"
|
|
|
|
|
|
|
|
"graph.ss"
|
|
|
|
(lib "list.ss")
|
|
|
|
(lib "list.ss")
|
|
|
|
(lib "class.ss"))
|
|
|
|
(lib "class.ss"))
|
|
|
|
|
|
|
|
|
|
|
@ -41,25 +42,12 @@
|
|
|
|
(define (compute-read a g)
|
|
|
|
(define (compute-read a g)
|
|
|
|
(let* ((dr (compute-DR a g))
|
|
|
|
(let* ((dr (compute-DR a g))
|
|
|
|
(reads (compute-reads a g)))
|
|
|
|
(reads (compute-reads a g)))
|
|
|
|
(digraph-tk->terml (send a get-mapped-non-term-keys)
|
|
|
|
(digraph-tk->terml (send a get-mapped-non-term-keys)
|
|
|
|
reads
|
|
|
|
reads
|
|
|
|
dr
|
|
|
|
dr
|
|
|
|
(send a get-num-states)
|
|
|
|
(send a get-num-states)
|
|
|
|
(send g get-num-terms)
|
|
|
|
(send g get-num-terms)
|
|
|
|
(send g get-num-non-terms))))
|
|
|
|
(send g get-num-non-terms))))
|
|
|
|
|
|
|
|
|
|
|
|
; ;; run-lr0-backward: lr0-automaton * gram-sym list * kernel * int -> kernel list
|
|
|
|
|
|
|
|
; ;; returns the list of all k such that state k transitions to state start on the
|
|
|
|
|
|
|
|
; ;; transitions in rhs (in order)
|
|
|
|
|
|
|
|
; (define (run-lr0-backward a rhs start num-states)
|
|
|
|
|
|
|
|
; (let loop ((states (list start))
|
|
|
|
|
|
|
|
; (rhs (reverse rhs)))
|
|
|
|
|
|
|
|
; (cond
|
|
|
|
|
|
|
|
; ((null? rhs) states)
|
|
|
|
|
|
|
|
; (else (loop (send a run-automaton-back states (car rhs))
|
|
|
|
|
|
|
|
; (cdr rhs))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; gram-sym list * kernel * int -> kernel list
|
|
|
|
|
|
|
|
;; returns the list of all k such that state k transitions to state start on the
|
|
|
|
;; returns the list of all k such that state k transitions to state start on the
|
|
|
|
;; transitions in rhs (in order)
|
|
|
|
;; transitions in rhs (in order)
|
|
|
|
(define (run-lr0-backward a rhs dot-pos start num-states)
|
|
|
|
(define (run-lr0-backward a rhs dot-pos start num-states)
|
|
|
@ -124,40 +112,6 @@
|
|
|
|
num-states))))
|
|
|
|
num-states))))
|
|
|
|
items)))))))
|
|
|
|
items)))))))
|
|
|
|
|
|
|
|
|
|
|
|
; ;; compute-includes: lr0-automaton * grammar -> (trans-key -> trans-key list)
|
|
|
|
|
|
|
|
; (define (compute-includes a g)
|
|
|
|
|
|
|
|
; (let* ((non-terms (send g get-non-terms))
|
|
|
|
|
|
|
|
; (num-states (vector-length (send a get-states)))
|
|
|
|
|
|
|
|
; (num-non-terms (length non-terms))
|
|
|
|
|
|
|
|
; (includes (make-array2d num-states num-non-terms null)))
|
|
|
|
|
|
|
|
; (send a for-each-state
|
|
|
|
|
|
|
|
; (lambda (state)
|
|
|
|
|
|
|
|
; (for-each
|
|
|
|
|
|
|
|
; (lambda (non-term)
|
|
|
|
|
|
|
|
; (for-each
|
|
|
|
|
|
|
|
; (lambda (prod)
|
|
|
|
|
|
|
|
; (let loop ((i (make-item prod 0))
|
|
|
|
|
|
|
|
; (p state))
|
|
|
|
|
|
|
|
; (if (and p i)
|
|
|
|
|
|
|
|
; (let* ((next-sym (sym-at-dot i))
|
|
|
|
|
|
|
|
; (new-i (move-dot-right i)))
|
|
|
|
|
|
|
|
; (if (and (non-term? next-sym)
|
|
|
|
|
|
|
|
; (send g nullable-after-dot? new-i))
|
|
|
|
|
|
|
|
; (array2d-add! includes
|
|
|
|
|
|
|
|
; (kernel-index p)
|
|
|
|
|
|
|
|
; (gram-sym-index next-sym)
|
|
|
|
|
|
|
|
; (make-trans-key state non-term)))
|
|
|
|
|
|
|
|
; (if next-sym
|
|
|
|
|
|
|
|
; (loop new-i
|
|
|
|
|
|
|
|
; (send a run-automaton p next-sym)))))))
|
|
|
|
|
|
|
|
; (send g get-prods-for-non-term non-term)))
|
|
|
|
|
|
|
|
; non-terms)))
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
; (lambda (tk)
|
|
|
|
|
|
|
|
; (array2d-ref includes
|
|
|
|
|
|
|
|
; (kernel-index (trans-key-st tk))
|
|
|
|
|
|
|
|
; (gram-sym-index (trans-key-gs tk))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; compute-lookback: lr0-automaton * grammar -> (kernel * proc -> trans-key list)
|
|
|
|
;; compute-lookback: lr0-automaton * grammar -> (kernel * proc -> trans-key list)
|
|
|
|
(define (compute-lookback a g)
|
|
|
|
(define (compute-lookback a g)
|
|
|
|
(let ((num-states (send a get-num-states)))
|
|
|
|
(let ((num-states (send a get-num-states)))
|
|
|
|