|
|
@ -8,19 +8,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
(provide parse-input get-term-list)
|
|
|
|
(provide parse-input get-term-list)
|
|
|
|
|
|
|
|
|
|
|
|
;; get-args: num * syntax-object -> syntax-object list
|
|
|
|
(define stx-for-original-property (read-syntax #f (open-input-string "original")))
|
|
|
|
(define (get-args x act src-pos)
|
|
|
|
|
|
|
|
(let loop ((i 1))
|
|
|
|
;; get-args: int * syntax-object list * syntax-object -> syntax-object list
|
|
|
|
|
|
|
|
(define (get-args i rhs act src-pos)
|
|
|
|
|
|
|
|
(cond
|
|
|
|
|
|
|
|
((null? rhs) null)
|
|
|
|
|
|
|
|
(else
|
|
|
|
|
|
|
|
(let ((b (syntax-local-introduce (car rhs))))
|
|
|
|
(cond
|
|
|
|
(cond
|
|
|
|
((> i x) null)
|
|
|
|
|
|
|
|
(src-pos
|
|
|
|
(src-pos
|
|
|
|
`(,(datum->syntax-object act (string->symbol (format "$~a" i)))
|
|
|
|
`(,(datum->syntax-object act (string->symbol (format "$~a" i)) b stx-for-original-property)
|
|
|
|
,(datum->syntax-object act (string->symbol (format "$~a-start-pos" i)))
|
|
|
|
,(datum->syntax-object act (string->symbol (format "$~a-start-pos" i)) b stx-for-original-property)
|
|
|
|
,(datum->syntax-object act (string->symbol (format "$~a-end-pos" i)))
|
|
|
|
,(datum->syntax-object act (string->symbol (format "$~a-end-pos" i)) b stx-for-original-property)
|
|
|
|
,@(loop (add1 i))))
|
|
|
|
,@(get-args (add1 i) (cdr rhs) act src-pos)))
|
|
|
|
(else
|
|
|
|
(else
|
|
|
|
`(,(datum->syntax-object act (string->symbol (format "$~a" i)))
|
|
|
|
`(,(datum->syntax-object act (string->symbol (format "$~a" i)) b stx-for-original-property)
|
|
|
|
,@(loop (add1 i)))))))
|
|
|
|
,@(get-args (add1 i) (cdr rhs) act src-pos))))))))
|
|
|
|
|
|
|
|
|
|
|
|
;; nullable: production list * int -> non-term set
|
|
|
|
;; nullable: production list * int -> non-term set
|
|
|
|
;; determines which non-terminals can derive epsilon
|
|
|
|
;; determines which non-terminals can derive epsilon
|
|
|
@ -297,12 +301,12 @@
|
|
|
|
"production right-hand-side must have form (symbol ...)"
|
|
|
|
"production right-hand-side must have form (symbol ...)"
|
|
|
|
prod-so)))))
|
|
|
|
prod-so)))))
|
|
|
|
|
|
|
|
|
|
|
|
;; parse-action: gram-sym vector * syntax-object -> syntax-object
|
|
|
|
;; parse-action: syntax-object * syntax-object -> syntax-object
|
|
|
|
(parse-action
|
|
|
|
(parse-action
|
|
|
|
(lambda (prod act)
|
|
|
|
(lambda (rhs act)
|
|
|
|
(datum->syntax-object
|
|
|
|
(datum->syntax-object
|
|
|
|
runtime
|
|
|
|
runtime
|
|
|
|
`(lambda ,(get-args (vector-length prod) act src-pos)
|
|
|
|
`(lambda ,(get-args 1 (syntax->list rhs) act src-pos)
|
|
|
|
,act)
|
|
|
|
,act)
|
|
|
|
act)))
|
|
|
|
act)))
|
|
|
|
|
|
|
|
|
|
|
@ -326,7 +330,7 @@
|
|
|
|
(term-prec gs)
|
|
|
|
(term-prec gs)
|
|
|
|
(loop (sub1 i))))
|
|
|
|
(loop (sub1 i))))
|
|
|
|
#f))
|
|
|
|
#f))
|
|
|
|
(parse-action p (syntax action)))))
|
|
|
|
(parse-action (syntax prod-rhs) (syntax action)))))
|
|
|
|
((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))))
|
|
|
@ -346,7 +350,7 @@
|
|
|
|
"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 (syntax prod-rhs) (syntax action)))))
|
|
|
|
(_
|
|
|
|
(_
|
|
|
|
(raise-syntax-error
|
|
|
|
(raise-syntax-error
|
|
|
|
'parser-production-rhs
|
|
|
|
'parser-production-rhs
|
|
|
|