*** empty log message ***

original commit: 3b458b09b300f1a46ef5eaa0103303dc12e52492
tokens
Scott Owens 23 years ago
parent 4ab8d1c1b5
commit edc6b1891e

@ -10,7 +10,7 @@
(define (build-parser start input-terms assocs prods filename runtime src) (define (build-parser start input-terms assocs prods filename runtime src)
(let* ((grammar (parse-input start input-terms assocs prods)) (let* ((grammar (parse-input start input-terms assocs prods))
(table (build-table grammar "")) (table (build-table grammar filename))
(table-code (table-code
(cons 'vector (cons 'vector
(map (lambda (action) (map (lambda (action)
@ -41,29 +41,34 @@
(parser-code (parser-code
`(letrec ((term-sym->index ,token-code) `(letrec ((term-sym->index ,token-code)
(table ,table-code) (table ,table-code)
(pop-2x (pop-x
(lambda (s n) (lambda (s n)
(if (> n 0) (if (> n 0)
(pop-2x (cdr (cdr s)) (sub1 n)) (pop-x (cdr s) (sub1 n))
s)))) s))))
(lambda (get-token) (lambda (get-token)
(let loop ((stack (list 0)) (let loop ((stack (list 0))
(next (get-token))) (ip (get-token)))
(display stack)
(newline)
(display (if (token? ip) (token-name ip) ip))
(newline)
(let* ((s (car stack)) (let* ((s (car stack))
(a (hash-table-get term-sym->index (a (hash-table-get term-sym->index
(if (token? next) (if (token? ip)
(token-name next) (token-name ip)
next))) ip)))
(action (array2d-ref table s a))) (action (array2d-ref table s a)))
(cond (cond
((shift? action) ((shift? action)
(loop (cons (shift-state action) (cons a stack)) (get-token))) (printf "shift:~a~n" (shift-state action))
(loop (cons (shift-state action) 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* ((A (reduce-lhs-num action))
(new-stack (pop-2x stack (reduce-rhs-length 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 (cons A new-stack)) next))) (loop (cons goto new-stack) ip)))
((accept? action) ((accept? action)
(printf "accept~n")) (printf "accept~n"))
(else (error 'parser))))))))) (else (error 'parser)))))))))

Loading…
Cancel
Save