*** empty log message ***

original commit: 1134ea0926802ae6d41c0138924a4e0c90056665
tokens
Scott Owens 23 years ago
parent 9bf08d698a
commit 0dd2f595ef

@ -7,13 +7,13 @@
(require-for-syntax "private-lex/structs.ss") (require-for-syntax "private-lex/structs.ss")
(require (lib "list.ss") (require (lib "list.ss")
"private-lex/token.ss") "private-lex/token.ss")
(provide lex define-lex-abbrev define-lex-abbrevs (provide lexer define-lex-abbrev define-lex-abbrevs
make-lex-buf make-lex-buf
get-position position-offset position-line position-col position? get-position position-offset position-line position-col position?
define-tokens define-empty-tokens) define-tokens define-empty-tokens)
(define-syntax lex (define-syntax lexer
(let ((code (let ((code
`(letrec ((match `(letrec ((match
(lambda (lb first-pos end-pos longest-match-length longest-match-action length) (lambda (lb first-pos end-pos longest-match-length longest-match-action length)

@ -8,9 +8,9 @@
(provide build-parser) (provide build-parser)
(define (build-parser filename error-expr input-terms start end assocs prods runtime src) (define (build-parser filename suppress error-expr input-terms start end assocs prods runtime src)
(let* ((grammar (parse-input start end input-terms assocs prods runtime)) (let* ((grammar (parse-input start end input-terms assocs prods runtime))
(table (build-table grammar filename)) (table (build-table grammar filename suppress))
(table-code (table-code
`((lambda (table-list) `((lambda (table-list)
(let ((v (list->vector table-list))) (let ((v (list->vector table-list)))
@ -151,7 +151,7 @@
;; (printf "accept~n") ;; (printf "accept~n")
(cadr stack)) (cadr stack))
(else (else
(err) (err ip)
(let ((new-stack (fix-error stack ip get-token))) (let ((new-stack (fix-error stack ip get-token)))
(if new-stack (if new-stack
(parsing-loop new-stack (get-token)) (parsing-loop new-stack (get-token))

@ -107,7 +107,7 @@
(if (> RR-conflicts 0) (if (> RR-conflicts 0)
(fprintf port "~a reduce/reduce conflicts~n" RR-conflicts)))) (fprintf port "~a reduce/reduce conflicts~n" RR-conflicts))))
(define (resolve-conflicts a table num-terms num-non-terms) (define (resolve-conflicts a table num-terms num-non-terms suppress)
(letrec ((SR-conflicts 0) (letrec ((SR-conflicts 0)
(RR-conflicts 0) (RR-conflicts 0)
(get-action (get-action
@ -140,15 +140,16 @@
(+ num-non-terms term)))) (+ num-non-terms term))))
(loop (add1 term)))))) (loop (add1 term))))))
a) a)
(if (not suppress)
(if (> SR-conflicts 0) (begin
(fprintf (current-error-port) (if (> SR-conflicts 0)
"~a shift/reduce conflicts~n" (fprintf (current-error-port)
SR-conflicts)) "~a shift/reduce conflicts~n"
(if (> RR-conflicts 0) SR-conflicts))
(fprintf (current-error-port) (if (> RR-conflicts 0)
"~a reduce/reduce conflicts~n" (fprintf (current-error-port)
RR-conflicts)))) "~a reduce/reduce conflicts~n"
RR-conflicts))))))
@ -202,7 +203,7 @@
;; In the result table the first index is the state and the second is the ;; In the result table the first index is the state and the second is the
;; term/non-term index (with the non-terms coming first) ;; term/non-term index (with the non-terms coming first)
;; buile-table: grammar * string -> action2d-array ;; buile-table: grammar * string -> action2d-array
(define (build-table g file) (define (build-table g file suppress)
(let* ((a (build-lr0-automaton g)) (let* ((a (build-lr0-automaton g))
(terms (grammar-terms g)) (terms (grammar-terms g))
(non-terms (grammar-non-terms g)) (non-terms (grammar-non-terms g))
@ -287,7 +288,7 @@
(lambda (port) (lambda (port)
(display-parser a table get-term get-non-term (grammar-prods g) (display-parser a table get-term get-non-term (grammar-prods g)
port))))) port)))))
(resolve-conflicts a table num-terms num-non-terms) (resolve-conflicts a table num-terms num-non-terms suppress)
table)) table))
) )

@ -20,10 +20,11 @@
(start #f) (start #f)
(end #f) (end #f)
(precs #f) (precs #f)
(suppress #f)
(grammar #f)) (grammar #f))
(for-each (for-each
(lambda (arg) (lambda (arg)
(syntax-case* arg (debug error tokens start end precs grammar) (syntax-case* arg (debug error tokens start end precs grammar suppress)
(lambda (a b) (lambda (a b)
(eq? (syntax-object->datum a) (syntax-object->datum b))) (eq? (syntax-object->datum a) (syntax-object->datum b)))
((debug filename) ((debug filename)
@ -37,6 +38,8 @@
(raise-syntax-error #f "Multiple debug declarations" stx)) (raise-syntax-error #f "Multiple debug declarations" stx))
(else (else
(set! debug (syntax-object->datum (syntax filename)))))) (set! debug (syntax-object->datum (syntax filename))))))
((suppress)
(set! suppress #t))
((error expression) ((error expression)
(if error (if error
(raise-syntax-error #f "Multiple error declarations" stx) (raise-syntax-error #f "Multiple error declarations" stx)
@ -102,6 +105,7 @@
(if (not start) (if (not start)
(raise-syntax-error #f "missing start declaration" stx)) (raise-syntax-error #f "missing start declaration" stx))
(build-parser (if debug debug "") (build-parser (if debug debug "")
suppress
error error
tokens tokens
start start

Loading…
Cancel
Save