|
|
@ -45,11 +45,11 @@
|
|
|
|
`(letrec ((term-sym->index ,token-code)
|
|
|
|
`(letrec ((term-sym->index ,token-code)
|
|
|
|
(table ,table-code)
|
|
|
|
(table ,table-code)
|
|
|
|
(actions ,actions-code)
|
|
|
|
(actions ,actions-code)
|
|
|
|
(pop-x
|
|
|
|
(reduce-stack
|
|
|
|
(lambda (s n)
|
|
|
|
(lambda (s n v)
|
|
|
|
(if (> n 0)
|
|
|
|
(if (> n 0)
|
|
|
|
(pop-x (cdr s) (sub1 n))
|
|
|
|
(reduce-stack (cdr (cdr s)) (sub1 n) (cons (cadr s) v))
|
|
|
|
s))))
|
|
|
|
(values s v)))))
|
|
|
|
(lambda (get-token)
|
|
|
|
(lambda (get-token)
|
|
|
|
(let loop ((stack (list 0))
|
|
|
|
(let loop ((stack (list 0))
|
|
|
|
(ip (get-token)))
|
|
|
|
(ip (get-token)))
|
|
|
@ -66,13 +66,26 @@
|
|
|
|
(cond
|
|
|
|
(cond
|
|
|
|
((shift? action)
|
|
|
|
((shift? action)
|
|
|
|
(printf "shift:~a~n" (shift-state action))
|
|
|
|
(printf "shift:~a~n" (shift-state action))
|
|
|
|
(loop (cons (shift-state action) stack) (get-token)))
|
|
|
|
(let ((val (if (token? ip)
|
|
|
|
|
|
|
|
(token-value ip)
|
|
|
|
|
|
|
|
#f)))
|
|
|
|
|
|
|
|
(loop (cons (shift-state action) (cons val stack))
|
|
|
|
|
|
|
|
(get-token))))
|
|
|
|
((reduce? action)
|
|
|
|
((reduce? action)
|
|
|
|
(printf "reduce:~a~n" (reduce-prod-num action))
|
|
|
|
(printf "reduce:~a~n" (reduce-prod-num action))
|
|
|
|
(let* ((A (reduce-lhs-num action))
|
|
|
|
(let-values (((new-stack args)
|
|
|
|
(new-stack (pop-x stack (reduce-rhs-length action)))
|
|
|
|
(reduce-stack stack
|
|
|
|
(goto (array2d-ref table (car new-stack) A)))
|
|
|
|
(reduce-rhs-length action)
|
|
|
|
(loop (cons goto new-stack) ip)))
|
|
|
|
null)))
|
|
|
|
|
|
|
|
(let* ((A (reduce-lhs-num action))
|
|
|
|
|
|
|
|
(goto (array2d-ref table (car new-stack) A)))
|
|
|
|
|
|
|
|
(loop (cons goto
|
|
|
|
|
|
|
|
(cons (apply
|
|
|
|
|
|
|
|
(vector-ref actions
|
|
|
|
|
|
|
|
(reduce-prod-num action))
|
|
|
|
|
|
|
|
args)
|
|
|
|
|
|
|
|
new-stack))
|
|
|
|
|
|
|
|
ip))))
|
|
|
|
((accept? action)
|
|
|
|
((accept? action)
|
|
|
|
(printf "accept~n"))
|
|
|
|
(printf "accept~n"))
|
|
|
|
(else (error 'parser)))))))))
|
|
|
|
(else (error 'parser)))))))))
|
|
|
|