|
|
@ -14,7 +14,7 @@
|
|
|
|
(table-code
|
|
|
|
(table-code
|
|
|
|
`((lambda (table-list)
|
|
|
|
`((lambda (table-list)
|
|
|
|
(let ((v (list->vector table-list)))
|
|
|
|
(let ((v (list->vector table-list)))
|
|
|
|
(let loop ((i 0))
|
|
|
|
(let build-table-loop ((i 0))
|
|
|
|
(cond
|
|
|
|
(cond
|
|
|
|
((< i (vector-length v))
|
|
|
|
((< i (vector-length v))
|
|
|
|
(let ((vi (vector-ref v i)))
|
|
|
|
(let ((vi (vector-ref v i)))
|
|
|
@ -27,7 +27,7 @@
|
|
|
|
((eq? 'r (car vi))
|
|
|
|
((eq? 'r (car vi))
|
|
|
|
(make-reduce (cadr vi) (caddr vi) (cadddr vi)))
|
|
|
|
(make-reduce (cadr vi) (caddr vi) (cadddr vi)))
|
|
|
|
((eq? 'a (car vi)) (make-accept)))))))
|
|
|
|
((eq? 'a (car vi)) (make-accept)))))))
|
|
|
|
(loop (add1 i)))
|
|
|
|
(build-table-loop (add1 i)))
|
|
|
|
(else v)))))
|
|
|
|
(else v)))))
|
|
|
|
(quote
|
|
|
|
(quote
|
|
|
|
,(map (lambda (action)
|
|
|
|
,(map (lambda (action)
|
|
|
@ -71,26 +71,12 @@
|
|
|
|
(values s v))))
|
|
|
|
(values s v))))
|
|
|
|
(fix-error
|
|
|
|
(fix-error
|
|
|
|
(lambda (stack ip get-token)
|
|
|
|
(lambda (stack ip get-token)
|
|
|
|
(let remove-states ()
|
|
|
|
(letrec ((remove-input
|
|
|
|
(let ((a (find-action stack 'error)))
|
|
|
|
(lambda ()
|
|
|
|
(cond
|
|
|
|
|
|
|
|
((shift? a)
|
|
|
|
|
|
|
|
(printf "shift:~a~n" (shift-state a))
|
|
|
|
|
|
|
|
(set! stack (cons (shift-state a) (cons #f stack))))
|
|
|
|
|
|
|
|
(else
|
|
|
|
|
|
|
|
(printf "discard-state:~a~n" (car stack))
|
|
|
|
|
|
|
|
(cond
|
|
|
|
|
|
|
|
((< (length stack) 3)
|
|
|
|
|
|
|
|
(printf "Unable to shift error token~n")
|
|
|
|
|
|
|
|
#f)
|
|
|
|
|
|
|
|
(else
|
|
|
|
|
|
|
|
(set! stack (cddr stack))
|
|
|
|
|
|
|
|
(remove-states)))))))
|
|
|
|
|
|
|
|
(let remove-input ()
|
|
|
|
|
|
|
|
(let ((a (find-action stack ip)))
|
|
|
|
(let ((a (find-action stack ip)))
|
|
|
|
(cond
|
|
|
|
(cond
|
|
|
|
((shift? a)
|
|
|
|
((shift? a)
|
|
|
|
(printf "shift:~a~n" (shift-state a))
|
|
|
|
;; (printf "shift:~a~n" (shift-state a))
|
|
|
|
(cons (shift-state a)
|
|
|
|
(cons (shift-state a)
|
|
|
|
(cons (if (token? ip)
|
|
|
|
(cons (if (token? ip)
|
|
|
|
(token-value ip)
|
|
|
|
(token-value ip)
|
|
|
@ -101,7 +87,25 @@
|
|
|
|
(token-name ip)
|
|
|
|
(token-name ip)
|
|
|
|
ip))
|
|
|
|
ip))
|
|
|
|
(set! ip (get-token))
|
|
|
|
(set! ip (get-token))
|
|
|
|
(remove-input)))))))
|
|
|
|
(remove-input))))))
|
|
|
|
|
|
|
|
(remove-states
|
|
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
|
|
(let ((a (find-action stack 'error)))
|
|
|
|
|
|
|
|
(cond
|
|
|
|
|
|
|
|
((shift? a)
|
|
|
|
|
|
|
|
;; (printf "shift:~a~n" (shift-state a))
|
|
|
|
|
|
|
|
(set! stack (cons (shift-state a) (cons #f stack)))
|
|
|
|
|
|
|
|
(remove-input))
|
|
|
|
|
|
|
|
(else
|
|
|
|
|
|
|
|
;; (printf "discard-state:~a~n" (car stack))
|
|
|
|
|
|
|
|
(cond
|
|
|
|
|
|
|
|
((< (length stack) 3)
|
|
|
|
|
|
|
|
(printf "Unable to shift error token~n")
|
|
|
|
|
|
|
|
#f)
|
|
|
|
|
|
|
|
(else
|
|
|
|
|
|
|
|
(set! stack (cddr stack))
|
|
|
|
|
|
|
|
(remove-states)))))))))
|
|
|
|
|
|
|
|
(remove-states))))
|
|
|
|
|
|
|
|
|
|
|
|
(find-action
|
|
|
|
(find-action
|
|
|
|
(lambda (stack tok)
|
|
|
|
(lambda (stack tok)
|
|
|
@ -113,7 +117,7 @@
|
|
|
|
tok)
|
|
|
|
tok)
|
|
|
|
err)))))
|
|
|
|
err)))))
|
|
|
|
(lambda (get-token)
|
|
|
|
(lambda (get-token)
|
|
|
|
(let loop ((stack (list 0))
|
|
|
|
(let parsing-loop ((stack (list 0))
|
|
|
|
(ip (get-token)))
|
|
|
|
(ip (get-token)))
|
|
|
|
;;(display stack)
|
|
|
|
;;(display stack)
|
|
|
|
;;(newline)
|
|
|
|
;;(newline)
|
|
|
@ -126,7 +130,7 @@
|
|
|
|
(let ((val (if (token? ip)
|
|
|
|
(let ((val (if (token? ip)
|
|
|
|
(token-value ip)
|
|
|
|
(token-value ip)
|
|
|
|
#f)))
|
|
|
|
#f)))
|
|
|
|
(loop (cons (shift-state action) (cons val stack))
|
|
|
|
(parsing-loop (cons (shift-state action) (cons val stack))
|
|
|
|
(get-token))))
|
|
|
|
(get-token))))
|
|
|
|
((reduce? action)
|
|
|
|
((reduce? action)
|
|
|
|
;; (printf "reduce:~a~n" (reduce-prod-num action))
|
|
|
|
;; (printf "reduce:~a~n" (reduce-prod-num action))
|
|
|
@ -136,7 +140,7 @@
|
|
|
|
null)))
|
|
|
|
null)))
|
|
|
|
(let* ((A (reduce-lhs-num action))
|
|
|
|
(let* ((A (reduce-lhs-num action))
|
|
|
|
(goto (array2d-ref table (car new-stack) A)))
|
|
|
|
(goto (array2d-ref table (car new-stack) A)))
|
|
|
|
(loop (cons goto
|
|
|
|
(parsing-loop (cons goto
|
|
|
|
(cons (apply
|
|
|
|
(cons (apply
|
|
|
|
(vector-ref actions
|
|
|
|
(vector-ref actions
|
|
|
|
(reduce-prod-num action))
|
|
|
|
(reduce-prod-num action))
|
|
|
@ -150,10 +154,9 @@
|
|
|
|
(err)
|
|
|
|
(err)
|
|
|
|
(let ((new-stack (fix-error stack ip get-token)))
|
|
|
|
(let ((new-stack (fix-error stack ip get-token)))
|
|
|
|
(if new-stack
|
|
|
|
(if new-stack
|
|
|
|
(loop new-stack (get-token))
|
|
|
|
(parsing-loop new-stack (get-token))
|
|
|
|
(void)))))))))))
|
|
|
|
(void)))))))))))
|
|
|
|
(datum->syntax-object
|
|
|
|
(datum->syntax-object
|
|
|
|
runtime
|
|
|
|
runtime
|
|
|
|
parser-code
|
|
|
|
parser-code
|
|
|
|
src))))
|
|
|
|
src))))
|
|
|
|
|
|
|
|
|