*** empty log message ***

original commit: 90f5b4a6b959e3279d12afa521b01b5b7075ee71
tokens
Scott Owens 23 years ago
parent 04a0fb7a4f
commit d7837cf5b7

@ -1,6 +1,6 @@
;; This implements the equivalent of mzscheme's read-syntax for R5RS scheme.
;; It has not been thoroughly tested. Also it will read an entire file into a
;; list of syntax objects
;; list of syntax objects, instead of returning one syntax object at a time
;; Everything in this module will be read with case sensitivity.
#cs

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

@ -16,7 +16,7 @@
so
so)))
(define (fix-check-syntax start terms prods)
(define (fix-check-syntax start terms prods precs ends)
(syntax-case prods ()
((_ (bind ((bound ...) x ...) ...) ...)
(let ((binds (syntax->list (syntax (bind ...))))
@ -28,11 +28,14 @@
append
(map syntax->list
(syntax->list (syntax (((bound ...) ...) ...)))))))))
(terms (get-term-list terms)))
(terms (get-term-list terms))
(precs (syntax-case precs ()
((_ (__ term ...) ...)
(apply append (map syntax->list (syntax->list (syntax ((term ...) ...)))))))))
`(if #f (let ,(map (lambda (bind)
`(,(strip bind) void))
(append terms binds))
(void ,@(map strip bounds))))))))
(void ,@(append ends precs (map strip bounds)))))))))
(define (build-parser filename src-pos suppress error-expr input-terms start end assocs prods runtime src)
(let* ((grammar (parse-input start end input-terms assocs prods runtime src-pos))
@ -235,5 +238,5 @@
#f #f #f #f #f)))))))))))
(datum->syntax-object
runtime
`(begin ,(fix-check-syntax start input-terms prods) ,parser-code)
`(begin ,(fix-check-syntax start input-terms prods assocs end) ,parser-code)
src))))

Loading…
Cancel
Save