*** empty log message ***

original commit: fd6994ff1f843f794b3491d338db4bfc8afb6329
tokens
Scott Owens 23 years ago
parent 584ff1ccfb
commit 28a7fc60c9

@ -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-values (((new-stack args)
(reduce-stack stack
(reduce-rhs-length action)
null)))
(let* ((A (reduce-lhs-num action)) (let* ((A (reduce-lhs-num action))
(new-stack (pop-x stack (reduce-rhs-length action)))
(goto (array2d-ref table (car new-stack) A))) (goto (array2d-ref table (car new-stack) A)))
(loop (cons goto new-stack) ip))) (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)))))))))

Loading…
Cancel
Save