|
|
|
@ -78,14 +78,14 @@
|
|
|
|
|
(for ([sym (in-list symbols)]
|
|
|
|
|
#:unless (identifier? sym))
|
|
|
|
|
(raise-syntax-error #f "End token must be a symbol" stx sym))
|
|
|
|
|
(let ([d (duplicate-list? (map syntax-e symbols))])
|
|
|
|
|
(define d (duplicate-list? (map syntax-e symbols)))
|
|
|
|
|
(when d
|
|
|
|
|
(raise-syntax-error #f (format "Duplicate end token definition for ~a" d) stx arg))
|
|
|
|
|
(when (null? symbols)
|
|
|
|
|
(raise-syntax-error #f "end declaration must contain at least 1 token" stx arg))
|
|
|
|
|
(when end
|
|
|
|
|
(raise-syntax-error #f "Multiple end declarations" stx))
|
|
|
|
|
(set! end symbols)))]
|
|
|
|
|
(set! end symbols))]
|
|
|
|
|
[(precs DECLS ...)
|
|
|
|
|
(if precs
|
|
|
|
|
(raise-syntax-error #f "Multiple precs declarations" stx)
|
|
|
|
@ -113,7 +113,7 @@
|
|
|
|
|
(raise-syntax-error #f "missing end declaration" stx))
|
|
|
|
|
(unless start
|
|
|
|
|
(raise-syntax-error #f "missing start declaration" stx))
|
|
|
|
|
(let-values ([(table all-term-syms actions check-syntax-fix)
|
|
|
|
|
(define-values (table all-term-syms actions check-syntax-fix)
|
|
|
|
|
(build-parser (if debug debug "")
|
|
|
|
|
src-pos
|
|
|
|
|
suppress
|
|
|
|
@ -121,7 +121,7 @@
|
|
|
|
|
start
|
|
|
|
|
end
|
|
|
|
|
precs
|
|
|
|
|
grammar)])
|
|
|
|
|
grammar))
|
|
|
|
|
(when (and yacc-output (not (string=? yacc-output "")))
|
|
|
|
|
(with-handlers [(exn:fail:filesystem?
|
|
|
|
|
(λ (e) (eprintf "Cannot write yacc-output to file \"~a\"\n" yacc-output)))]
|
|
|
|
@ -144,7 +144,7 @@
|
|
|
|
|
[src-pos src-pos])
|
|
|
|
|
#'(begin
|
|
|
|
|
check-syntax-fix
|
|
|
|
|
(parser-body debug err (quote starts) (quote ends) table all-term-syms actions src-pos)))))]
|
|
|
|
|
(parser-body debug err (quote starts) (quote ends) table all-term-syms actions src-pos))))]
|
|
|
|
|
[_ (raise-syntax-error #f "parser must have the form (parser args ...)" stx)]))
|
|
|
|
|
|
|
|
|
|
(define (reduce-stack stack num ret-vals src-pos)
|
|
|
|
@ -237,11 +237,9 @@
|
|
|
|
|
stack)]
|
|
|
|
|
[else
|
|
|
|
|
;; (printf "discard input:~a\n" tok)
|
|
|
|
|
(let-values ([(tok val start-pos end-pos)
|
|
|
|
|
(extract (get-token))])
|
|
|
|
|
(remove-input tok val start-pos end-pos))])))))
|
|
|
|
|
(call-with-values (λ () (extract (get-token))) remove-input)])))))
|
|
|
|
|
(let remove-states ()
|
|
|
|
|
(let ([a (find-action stack 'error #f start-pos end-pos)])
|
|
|
|
|
(define a (find-action stack 'error #f start-pos end-pos))
|
|
|
|
|
(cond
|
|
|
|
|
[(runtime-shift? a)
|
|
|
|
|
;; (printf "shift:~a\n" (runtime-shift-state a))
|
|
|
|
@ -261,7 +259,7 @@
|
|
|
|
|
#f #f #f #f #f)]
|
|
|
|
|
[else
|
|
|
|
|
(set! stack (cdr stack))
|
|
|
|
|
(remove-states)])])))))
|
|
|
|
|
(remove-states)])]))))
|
|
|
|
|
|
|
|
|
|
(define (find-action stack tok val start-pos end-pos)
|
|
|
|
|
(unless (hash-ref all-term-syms tok #f)
|
|
|
|
@ -278,8 +276,8 @@
|
|
|
|
|
(error 'get-token "expected a nullary procedure, got ~e" get-token))
|
|
|
|
|
(let parsing-loop ([stack (make-empty-stack start-number)]
|
|
|
|
|
[ip (get-token)])
|
|
|
|
|
(let-values ([(tok val start-pos end-pos) (extract ip)])
|
|
|
|
|
(let ([action (find-action stack tok val start-pos end-pos)])
|
|
|
|
|
(define-values (tok val start-pos end-pos) (extract ip))
|
|
|
|
|
(define action (find-action stack tok val start-pos end-pos))
|
|
|
|
|
(cond
|
|
|
|
|
[(runtime-shift? action)
|
|
|
|
|
;; (printf "shift:~a\n" (runtime-shift-state action))
|
|
|
|
@ -296,11 +294,11 @@
|
|
|
|
|
(runtime-reduce-rhs-length action)
|
|
|
|
|
null
|
|
|
|
|
src-pos)])
|
|
|
|
|
(let ([goto
|
|
|
|
|
(define goto
|
|
|
|
|
(runtime-goto-state
|
|
|
|
|
(hash-ref
|
|
|
|
|
(vector-ref table (stack-frame-state (car new-stack)))
|
|
|
|
|
(runtime-reduce-lhs action)))])
|
|
|
|
|
(runtime-reduce-lhs action))))
|
|
|
|
|
(parsing-loop
|
|
|
|
|
(cons
|
|
|
|
|
(if src-pos
|
|
|
|
@ -317,7 +315,7 @@
|
|
|
|
|
#f
|
|
|
|
|
#f))
|
|
|
|
|
new-stack)
|
|
|
|
|
ip)))]
|
|
|
|
|
ip))]
|
|
|
|
|
[(runtime-accept? action)
|
|
|
|
|
;; (printf "accept\n")
|
|
|
|
|
(stack-frame-value (car stack))]
|
|
|
|
@ -326,7 +324,7 @@
|
|
|
|
|
(err #t tok val start-pos end-pos)
|
|
|
|
|
(err #t tok val))
|
|
|
|
|
(parsing-loop (fix-error stack tok val start-pos end-pos get-token)
|
|
|
|
|
(get-token))]))))))
|
|
|
|
|
(get-token))]))))
|
|
|
|
|
(cond
|
|
|
|
|
[(null? (cdr starts)) (make-parser 0)]
|
|
|
|
|
[else
|
|
|
|
|