|
|
@ -6,7 +6,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
(require "yacc-helper.ss" "../private-lex/token-syntax.ss" "grammar.ss" (lib "list.ss"))
|
|
|
|
(require "yacc-helper.ss" "../private-lex/token-syntax.ss" "grammar.ss" (lib "list.ss"))
|
|
|
|
|
|
|
|
|
|
|
|
(provide parse-input)
|
|
|
|
(provide parse-input get-term-list)
|
|
|
|
|
|
|
|
|
|
|
|
;; get-args: num * syntax-object -> syntax-object list
|
|
|
|
;; get-args: num * syntax-object -> syntax-object list
|
|
|
|
(define (get-args x act src-pos)
|
|
|
|
(define (get-args x act src-pos)
|
|
|
@ -110,28 +110,22 @@
|
|
|
|
(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
|
|
|
|
((terminals-def? t) (terminals-def-t t))
|
|
|
|
((terminals-def? t) (syntax->list (terminals-def-t t)))
|
|
|
|
(else
|
|
|
|
(else
|
|
|
|
(raise-syntax-error
|
|
|
|
(raise-syntax-error
|
|
|
|
'parser-tokens
|
|
|
|
'parser-tokens
|
|
|
|
"undefined token group"
|
|
|
|
"undefined token group"
|
|
|
|
term-syn)))))
|
|
|
|
term-syn)))))
|
|
|
|
|
|
|
|
|
|
|
|
;; parse-input: syntax-object * syntax-object list * syntax-object^4 * boolean-> grammar
|
|
|
|
;; get-term-list: syntax-object -> syntax-object list
|
|
|
|
(define (parse-input start ends term-defs prec-decls prods runtime src-pos)
|
|
|
|
(define (get-term-list so)
|
|
|
|
(let* ((counter 0)
|
|
|
|
(syntax-case* so (tokens)
|
|
|
|
|
|
|
|
|
|
|
|
(start-sym (syntax-object->datum start))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(list-of-terms
|
|
|
|
|
|
|
|
(syntax-case* term-defs (tokens)
|
|
|
|
|
|
|
|
(lambda (a b)
|
|
|
|
(lambda (a b)
|
|
|
|
(eq? (syntax-object->datum a) (syntax-object->datum b)))
|
|
|
|
(eq? (syntax-object->datum a) (syntax-object->datum b)))
|
|
|
|
((tokens term-def ...)
|
|
|
|
((tokens term-def ...)
|
|
|
|
(andmap identifier? (syntax->list (syntax (term-def ...))))
|
|
|
|
(andmap identifier? (syntax->list (syntax (term-def ...))))
|
|
|
|
(remove-duplicates
|
|
|
|
(remove-duplicates
|
|
|
|
(cons 'error
|
|
|
|
(cons (datum->syntax-object #f 'error)
|
|
|
|
(apply append
|
|
|
|
(apply append
|
|
|
|
(map get-terms-from-def
|
|
|
|
(map get-terms-from-def
|
|
|
|
(syntax->list (syntax (term-def ...))))))))
|
|
|
|
(syntax->list (syntax (term-def ...))))))))
|
|
|
@ -139,7 +133,15 @@
|
|
|
|
(raise-syntax-error
|
|
|
|
(raise-syntax-error
|
|
|
|
'parser-tokens
|
|
|
|
'parser-tokens
|
|
|
|
"Token declaration must be (tokens symbol ...)"
|
|
|
|
"Token declaration must be (tokens symbol ...)"
|
|
|
|
term-defs))))
|
|
|
|
so))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; parse-input: syntax-object * syntax-object list * syntax-object^4 * boolean-> grammar
|
|
|
|
|
|
|
|
(define (parse-input start ends term-defs prec-decls prods runtime src-pos)
|
|
|
|
|
|
|
|
(let* ((counter 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(start-sym (syntax-object->datum start))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(list-of-terms (map syntax-object->datum (get-term-list term-defs)))
|
|
|
|
|
|
|
|
|
|
|
|
(end-terms
|
|
|
|
(end-terms
|
|
|
|
(map
|
|
|
|
(map
|
|
|
|