|
|
@ -12,12 +12,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(provide/contract
|
|
|
|
(provide/contract
|
|
|
|
(parse-input ((listof syntax?) (listof syntax?) syntax? (union false? syntax?) syntax? any? . -> . (is-a?/c grammar%)))
|
|
|
|
(parse-input ((listof identifier?) (listof identifier?) (listof identifier?)
|
|
|
|
(get-term-list (syntax? . -> . (listof syntax?))))
|
|
|
|
(union false? syntax?) syntax? any? . -> . (is-a?/c grammar%)))
|
|
|
|
|
|
|
|
(get-term-list ((listof identifier?) . -> . (listof identifier?))))
|
|
|
|
|
|
|
|
|
|
|
|
(define stx-for-original-property (read-syntax #f (open-input-string "original")))
|
|
|
|
(define stx-for-original-property (read-syntax #f (open-input-string "original")))
|
|
|
|
|
|
|
|
|
|
|
|
;; get-args: int * syntax-object list * syntax-object -> syntax-object list
|
|
|
|
;; get-args: ???
|
|
|
|
(define (get-args i rhs src-pos term-defs)
|
|
|
|
(define (get-args i rhs src-pos term-defs)
|
|
|
|
(let ((empty-table (make-hash-table)))
|
|
|
|
(let ((empty-table (make-hash-table)))
|
|
|
|
(hash-table-put! empty-table 'error #t)
|
|
|
|
(hash-table-put! empty-table 'error #t)
|
|
|
@ -27,7 +28,7 @@
|
|
|
|
(for-each (lambda (s)
|
|
|
|
(for-each (lambda (s)
|
|
|
|
(hash-table-put! empty-table (syntax-object->datum s) #t))
|
|
|
|
(hash-table-put! empty-table (syntax-object->datum s) #t))
|
|
|
|
(syntax->list (e-terminals-def-t v))))))
|
|
|
|
(syntax->list (e-terminals-def-t v))))))
|
|
|
|
(cdr (syntax->list term-defs)))
|
|
|
|
term-defs)
|
|
|
|
(let get-args ((i i)
|
|
|
|
(let get-args ((i i)
|
|
|
|
(rhs rhs))
|
|
|
|
(rhs rhs))
|
|
|
|
(cond
|
|
|
|
(cond
|
|
|
@ -79,7 +80,7 @@
|
|
|
|
term-list)))
|
|
|
|
term-list)))
|
|
|
|
|
|
|
|
|
|
|
|
;; Retrieves the terminal symbols from a terminals-def (See terminal-syntax.ss)
|
|
|
|
;; Retrieves the terminal symbols from a terminals-def (See terminal-syntax.ss)
|
|
|
|
;; get-terms-from-def: syntax-object -> symbol list
|
|
|
|
;; get-terms-from-def: identifier? -> (listof identifier?)
|
|
|
|
(define (get-terms-from-def term-syn)
|
|
|
|
(define (get-terms-from-def term-syn)
|
|
|
|
(let ((t (syntax-local-value term-syn (lambda () #f))))
|
|
|
|
(let ((t (syntax-local-value term-syn (lambda () #f))))
|
|
|
|
(cond
|
|
|
|
(cond
|
|
|
@ -91,48 +92,34 @@
|
|
|
|
"undefined token group"
|
|
|
|
"undefined token group"
|
|
|
|
term-syn)))))
|
|
|
|
term-syn)))))
|
|
|
|
|
|
|
|
|
|
|
|
;; get-term-list: syntax-object -> syntax-object list
|
|
|
|
(define (get-term-list term-group-names)
|
|
|
|
(define (get-term-list so)
|
|
|
|
|
|
|
|
(syntax-case* so (tokens)
|
|
|
|
|
|
|
|
(lambda (a b)
|
|
|
|
|
|
|
|
(eq? (syntax-object->datum a) (syntax-object->datum b)))
|
|
|
|
|
|
|
|
((tokens term-def ...)
|
|
|
|
|
|
|
|
(andmap identifier? (syntax->list (syntax (term-def ...))))
|
|
|
|
|
|
|
|
(remove-duplicates
|
|
|
|
(remove-duplicates
|
|
|
|
(cons (datum->syntax-object #f 'error)
|
|
|
|
(cons (datum->syntax-object #f 'error)
|
|
|
|
(apply append
|
|
|
|
(apply append
|
|
|
|
(map get-terms-from-def
|
|
|
|
(map get-terms-from-def term-group-names)))))
|
|
|
|
(syntax->list (syntax (term-def ...))))))))
|
|
|
|
|
|
|
|
(_
|
|
|
|
|
|
|
|
(raise-syntax-error
|
|
|
|
|
|
|
|
'parser-tokens
|
|
|
|
|
|
|
|
"Token declaration must be (tokens symbol ...)"
|
|
|
|
|
|
|
|
so))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (parse-input start ends term-defs prec-decls prods src-pos)
|
|
|
|
(define (parse-input term-defs start ends prec-decls prods src-pos)
|
|
|
|
(let* ((start-syms (map syntax-object->datum start))
|
|
|
|
(let* ((start-syms (map syntax-e start))
|
|
|
|
|
|
|
|
|
|
|
|
(list-of-terms (map syntax-object->datum (get-term-list term-defs)))
|
|
|
|
(list-of-terms (map syntax-e (get-term-list term-defs)))
|
|
|
|
|
|
|
|
|
|
|
|
(end-terms
|
|
|
|
(end-terms
|
|
|
|
(map
|
|
|
|
(map
|
|
|
|
(lambda (end)
|
|
|
|
(lambda (end)
|
|
|
|
(if (not (memq (syntax-object->datum end) list-of-terms))
|
|
|
|
(unless (memq (syntax-e end) list-of-terms)
|
|
|
|
(raise-syntax-error
|
|
|
|
(raise-syntax-error
|
|
|
|
'parser-end-tokens
|
|
|
|
'parser-end-tokens
|
|
|
|
(format "End token ~a not defined as a token"
|
|
|
|
(format "End token ~a not defined as a token"
|
|
|
|
(syntax-object->datum end))
|
|
|
|
(syntax-e end))
|
|
|
|
end)
|
|
|
|
end))
|
|
|
|
(syntax-object->datum end)))
|
|
|
|
(syntax-e end))
|
|
|
|
ends))
|
|
|
|
ends))
|
|
|
|
|
|
|
|
|
|
|
|
;; Get the list of terminals out of input-terms
|
|
|
|
;; Get the list of terminals out of input-terms
|
|
|
|
|
|
|
|
|
|
|
|
(list-of-non-terms
|
|
|
|
(list-of-non-terms
|
|
|
|
(syntax-case* prods (grammar)
|
|
|
|
(syntax-case prods ()
|
|
|
|
(lambda (a b)
|
|
|
|
(((non-term production ...) ...)
|
|
|
|
(eq? (syntax-object->datum a) (syntax-object->datum b)))
|
|
|
|
|
|
|
|
((grammar (non-term production ...) ...)
|
|
|
|
|
|
|
|
(begin
|
|
|
|
(begin
|
|
|
|
(for-each
|
|
|
|
(for-each
|
|
|
|
(lambda (nts)
|
|
|
|
(lambda (nts)
|
|
|
@ -162,10 +149,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
;; Check the precedence declarations for errors and turn them into data
|
|
|
|
;; Check the precedence declarations for errors and turn them into data
|
|
|
|
(precs
|
|
|
|
(precs
|
|
|
|
(syntax-case* prec-decls (precs)
|
|
|
|
(syntax-case prec-decls ()
|
|
|
|
(lambda (a b)
|
|
|
|
(((type term ...) ...)
|
|
|
|
(eq? (syntax-object->datum a) (syntax-object->datum b)))
|
|
|
|
|
|
|
|
((precs (type term ...) ...)
|
|
|
|
|
|
|
|
(let ((p-terms
|
|
|
|
(let ((p-terms
|
|
|
|
(apply append (syntax-object->datum
|
|
|
|
(apply append (syntax-object->datum
|
|
|
|
(syntax ((term ...) ...))))))
|
|
|
|
(syntax ((term ...) ...))))))
|
|
|
@ -273,9 +258,7 @@
|
|
|
|
;; parse-prod+action: non-term * syntax-object -> production
|
|
|
|
;; parse-prod+action: non-term * syntax-object -> production
|
|
|
|
(parse-prod+action
|
|
|
|
(parse-prod+action
|
|
|
|
(lambda (nt prod-so)
|
|
|
|
(lambda (nt prod-so)
|
|
|
|
(syntax-case* prod-so (prec)
|
|
|
|
(syntax-case prod-so ()
|
|
|
|
(lambda (a b)
|
|
|
|
|
|
|
|
(eq? (syntax-object->datum a) (syntax-object->datum b)))
|
|
|
|
|
|
|
|
((prod-rhs action)
|
|
|
|
((prod-rhs action)
|
|
|
|
(let ((p (parse-prod (syntax prod-rhs))))
|
|
|
|
(let ((p (parse-prod (syntax prod-rhs))))
|
|
|
|
(make-prod
|
|
|
|
(make-prod
|
|
|
@ -342,7 +325,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
(let* ((starts (map (lambda (x) (make-non-term (gensym) #f)) start-syms))
|
|
|
|
(let* ((starts (map (lambda (x) (make-non-term (gensym) #f)) start-syms))
|
|
|
|
(end-non-terms (map (lambda (x) (make-non-term (gensym) #f)) start-syms))
|
|
|
|
(end-non-terms (map (lambda (x) (make-non-term (gensym) #f)) start-syms))
|
|
|
|
(parsed-prods (map parse-prods-for-nt (cdr (syntax->list prods))))
|
|
|
|
(parsed-prods (map parse-prods-for-nt (syntax->list prods)))
|
|
|
|
(start-prods
|
|
|
|
(start-prods
|
|
|
|
(map (lambda (start end-non-term)
|
|
|
|
(map (lambda (start end-non-term)
|
|
|
|
(list (make-prod start (vector end-non-term) #f #f
|
|
|
|
(list (make-prod start (vector end-non-term) #f #f
|
|
|
|