|
|
@ -235,7 +235,7 @@
|
|
|
|
(terms (build-terms list-of-terms precs))
|
|
|
|
(terms (build-terms list-of-terms precs))
|
|
|
|
|
|
|
|
|
|
|
|
(non-terms (begin
|
|
|
|
(non-terms (begin
|
|
|
|
(set! counter 1)
|
|
|
|
(set! counter 2)
|
|
|
|
(map (lambda (non-term)
|
|
|
|
(map (lambda (non-term)
|
|
|
|
(begin0
|
|
|
|
(begin0
|
|
|
|
(make-non-term non-term counter)
|
|
|
|
(make-non-term non-term counter)
|
|
|
@ -252,8 +252,6 @@
|
|
|
|
(hash-table-put! non-term-table (gram-sym-symbol nt) nt))
|
|
|
|
(hash-table-put! non-term-table (gram-sym-symbol nt) nt))
|
|
|
|
non-terms)
|
|
|
|
non-terms)
|
|
|
|
|
|
|
|
|
|
|
|
(set! counter 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(let* (
|
|
|
|
(let* (
|
|
|
|
;; parse-prod: syntax-object -> gram-sym vector
|
|
|
|
;; parse-prod: syntax-object -> gram-sym vector
|
|
|
|
(parse-prod
|
|
|
|
(parse-prod
|
|
|
@ -299,41 +297,39 @@
|
|
|
|
(syntax-case prod-so (prec)
|
|
|
|
(syntax-case prod-so (prec)
|
|
|
|
((prod-rhs action)
|
|
|
|
((prod-rhs action)
|
|
|
|
(let ((p (parse-prod (syntax prod-rhs))))
|
|
|
|
(let ((p (parse-prod (syntax prod-rhs))))
|
|
|
|
(begin0
|
|
|
|
(set! counter (add1 counter))
|
|
|
|
(make-prod
|
|
|
|
(make-prod
|
|
|
|
nt
|
|
|
|
nt
|
|
|
|
p
|
|
|
|
p
|
|
|
|
counter
|
|
|
|
counter
|
|
|
|
(let loop ((i (sub1 (vector-length p))))
|
|
|
|
(let loop ((i (sub1 (vector-length p))))
|
|
|
|
(if (>= i 0)
|
|
|
|
(if (>= i 0)
|
|
|
|
(let ((gs (vector-ref p i)))
|
|
|
|
(let ((gs (vector-ref p i)))
|
|
|
|
(if (term? gs)
|
|
|
|
(if (term? gs)
|
|
|
|
(term-prec gs)
|
|
|
|
(term-prec gs)
|
|
|
|
(loop (sub1 i))))
|
|
|
|
(loop (sub1 i))))
|
|
|
|
#f))
|
|
|
|
#f))
|
|
|
|
(parse-action p (syntax action)))
|
|
|
|
(parse-action p (syntax action)))))
|
|
|
|
(set! counter (add1 counter)))))
|
|
|
|
|
|
|
|
((prod-rhs (prec term) action)
|
|
|
|
((prod-rhs (prec term) action)
|
|
|
|
(identifier? (syntax term))
|
|
|
|
(identifier? (syntax term))
|
|
|
|
(let ((p (parse-prod (syntax prod-rhs))))
|
|
|
|
(let ((p (parse-prod (syntax prod-rhs))))
|
|
|
|
(begin0
|
|
|
|
(set! counter (add1 counter))
|
|
|
|
(make-prod
|
|
|
|
(make-prod
|
|
|
|
nt
|
|
|
|
nt
|
|
|
|
p
|
|
|
|
p
|
|
|
|
counter
|
|
|
|
counter
|
|
|
|
(term-prec
|
|
|
|
(term-prec
|
|
|
|
(hash-table-get
|
|
|
|
(hash-table-get
|
|
|
|
term-table
|
|
|
|
term-table
|
|
|
|
(syntax-object->datum (syntax term))
|
|
|
|
(syntax-object->datum (syntax term))
|
|
|
|
(lambda ()
|
|
|
|
(lambda ()
|
|
|
|
(raise-syntax-error
|
|
|
|
(raise-syntax-error
|
|
|
|
'parser-production-rhs
|
|
|
|
'parser-production-rhs
|
|
|
|
(format
|
|
|
|
(format
|
|
|
|
"unrecognized terminal ~a in precedence declaration"
|
|
|
|
"unrecognized terminal ~a in precedence declaration"
|
|
|
|
(syntax-object->datum (syntax term)))
|
|
|
|
(syntax-object->datum (syntax term)))
|
|
|
|
(syntax term)))))
|
|
|
|
(syntax term)))))
|
|
|
|
(parse-action p (syntax action)))
|
|
|
|
(parse-action p (syntax action)))))
|
|
|
|
(set! counter (add1 counter)))))
|
|
|
|
|
|
|
|
(_
|
|
|
|
(_
|
|
|
|
(raise-syntax-error
|
|
|
|
(raise-syntax-error
|
|
|
|
'parser-production-rhs
|
|
|
|
'parser-production-rhs
|
|
|
@ -357,20 +353,27 @@
|
|
|
|
"A production for a non-terminal must be (non-term right-hand-side ...) with at least 1 right hand side"
|
|
|
|
"A production for a non-terminal must be (non-term right-hand-side ...) with at least 1 right hand side"
|
|
|
|
prods-so))))))
|
|
|
|
prods-so))))))
|
|
|
|
|
|
|
|
|
|
|
|
(let* ((start (make-non-term 'Start 0))
|
|
|
|
(set! counter 0)
|
|
|
|
|
|
|
|
(let* ((start (make-non-term (gensym) 0))
|
|
|
|
|
|
|
|
(end-non-term (make-non-term (gensym) 1))
|
|
|
|
(prods
|
|
|
|
(prods
|
|
|
|
(cons
|
|
|
|
`((,(make-prod start (vector end-non-term) 0 #f #f))
|
|
|
|
(list (make-prod start
|
|
|
|
,(map
|
|
|
|
(vector (hash-table-get non-term-table start-sym)
|
|
|
|
(lambda (end)
|
|
|
|
(hash-table-get term-table (car end-terms)))
|
|
|
|
(set! counter (add1 counter))
|
|
|
|
0
|
|
|
|
(make-prod end-non-term
|
|
|
|
#f
|
|
|
|
(vector
|
|
|
|
(datum->syntax-object
|
|
|
|
(hash-table-get non-term-table start-sym)
|
|
|
|
runtime
|
|
|
|
(hash-table-get term-table end))
|
|
|
|
`(lambda (x) x))))
|
|
|
|
counter
|
|
|
|
(map parse-prods-for-nt (cdr (syntax->list prods)))))
|
|
|
|
#f
|
|
|
|
|
|
|
|
(datum->syntax-object
|
|
|
|
|
|
|
|
runtime
|
|
|
|
|
|
|
|
`(lambda (x) x))))
|
|
|
|
|
|
|
|
end-terms)
|
|
|
|
|
|
|
|
,@(map parse-prods-for-nt (cdr (syntax->list prods)))))
|
|
|
|
(nulls (nullable (apply append prods)
|
|
|
|
(nulls (nullable (apply append prods)
|
|
|
|
(add1 (length non-terms)))))
|
|
|
|
(+ 2 (length non-terms)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; (printf "nullable: {~a}~n~n"
|
|
|
|
; (printf "nullable: {~a}~n~n"
|
|
|
@ -389,7 +392,7 @@
|
|
|
|
(list->vector prods)
|
|
|
|
(list->vector prods)
|
|
|
|
(apply append prods)
|
|
|
|
(apply append prods)
|
|
|
|
nulls
|
|
|
|
nulls
|
|
|
|
(cons start non-terms)
|
|
|
|
(cons start (cons end-non-term non-terms))
|
|
|
|
terms
|
|
|
|
terms
|
|
|
|
counter
|
|
|
|
(add1 counter)
|
|
|
|
end-terms))))))
|
|
|
|
end-terms))))))
|
|
|
|