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