More "~n" -> "\n" changes

original commit: 8e0f8dd39c3744472b450021f003f9cbe8cbcb62
tokens
Eli Barzilay 14 years ago
commit d52b3aa1f1

@ -82,7 +82,7 @@
(lambda () (lambda ()
(let ((result (calcp (lambda () (calcl ip))))) (let ((result (calcp (lambda () (calcl ip)))))
(when result (when result
(printf "~a~n" result) (printf "~a\n" result)
(one-line)))))) (one-line))))))
(one-line))) (one-line)))

@ -113,7 +113,7 @@
(let ((next-check (vector-ref next 1))) (let ((next-check (vector-ref next 1)))
(or (>= next-check max-char-num) (or (>= next-check max-char-num)
(loop (add1 next-check) (cdr nexts)))))))))) (loop (add1 next-check) (cdr nexts))))))))))
(printf "Warning: lexer at ~a can accept the empty string.~n" stx))) (printf "Warning: lexer at ~a can accept the empty string.\n" stx)))
(with-syntax ((start-state-stx start) (with-syntax ((start-state-stx start)
(trans-table-stx trans) (trans-table-stx trans)
(no-lookahead-stx no-look) (no-lookahead-stx no-look)
@ -230,7 +230,7 @@
(lambda (ip) (lambda (ip)
(let ((first-pos (get-position ip)) (let ((first-pos (get-position ip))
(first-char (peek-char-or-special ip 0))) (first-char (peek-char-or-special ip 0)))
;(printf "(peek-char-or-special port 0) = ~e~n" first-char) ;(printf "(peek-char-or-special port 0) = ~e\n" first-char)
(cond (cond
((eof-object? first-char) ((eof-object? first-char)
(do-match ip first-pos eof-action (read-char-or-special ip))) (do-match ip first-pos eof-action (read-char-or-special ip)))
@ -279,7 +279,7 @@
(let* ((act (vector-ref actions next-state)) (let* ((act (vector-ref actions next-state))
(next-length-bytes (+ (char-utf-8-length char) length-bytes)) (next-length-bytes (+ (char-utf-8-length char) length-bytes))
(next-char (peek-char-or-special ip next-length-bytes))) (next-char (peek-char-or-special ip next-length-bytes)))
#;(printf "(peek-char-or-special port ~e) = ~e~n" #;(printf "(peek-char-or-special port ~e) = ~e\n"
next-length-bytes next-char) next-length-bytes next-char)
(lexer-loop next-state (lexer-loop next-state
next-char next-char
@ -312,13 +312,13 @@
(position-offset first-pos) (position-offset first-pos)
(- (position-offset end-pos) (position-offset first-pos))))) (- (position-offset end-pos) (position-offset first-pos)))))
(let ((match (read-string longest-match-length lb))) (let ((match (read-string longest-match-length lb)))
;(printf "(read-string ~e port) = ~e~n" longest-match-length match) ;(printf "(read-string ~e port) = ~e\n" longest-match-length match)
(do-match lb first-pos longest-match-action match))) (do-match lb first-pos longest-match-action match)))
(define file-path (make-parameter #f)) (define file-path (make-parameter #f))
(define (do-match ip first-pos action value) (define (do-match ip first-pos action value)
#;(printf "(action ~a ~a ~a ~a)~n" #;(printf "(action ~a ~a ~a ~a)\n"
(position-offset first-pos) (position-offset (get-position ip)) value ip) (position-offset first-pos) (position-offset (get-position ip)) value ip)
(action first-pos (get-position ip) value ip)) (action first-pos (get-position ip) value ip))

@ -281,13 +281,13 @@
(else (loop old-states new-states all-states (cdr cs)))))))))) (else (loop old-states new-states all-states (cdr cs))))))))))
(define (print-dfa x) (define (print-dfa x)
(printf "number of states: ~a~n" (dfa-num-states x)) (printf "number of states: ~a\n" (dfa-num-states x))
(printf "start state: ~a~n" (dfa-start-state x)) (printf "start state: ~a\n" (dfa-start-state x))
(printf "final states: ~a~n" (map car (dfa-final-states/actions x))) (printf "final states: ~a\n" (map car (dfa-final-states/actions x)))
(for-each (lambda (trans) (for-each (lambda (trans)
(printf "state: ~a~n" (car trans)) (printf "state: ~a\n" (car trans))
(for-each (lambda (rule) (for-each (lambda (rule)
(printf " -~a-> ~a~n" (printf " -~a-> ~a\n"
(is:integer-set-contents (car rule)) (is:integer-set-contents (car rule))
(cdr rule))) (cdr rule)))
(cdr trans))) (cdr trans)))

@ -170,7 +170,7 @@
(vector->list x)))) (vector->list x))))
(vector->list table)) (vector->list table))
(length (hash-table-map ht cons))))) (length (hash-table-map ht cons)))))
(printf "~a states, ~aKB~n" (printf "~a states, ~aKB\n"
num-states num-states
(/ (* 4.0 (+ 2 num-states (* 2 num-vectors) num-entries (/ (* 4.0 (+ 2 num-states (* 2 num-vectors) num-entries
(* 5 num-different-entries))) 1024))) (* 5 num-different-entries))) 1024)))

@ -14,7 +14,7 @@
(let* defs (let* defs
(let ((real-ans code)) (let ((real-ans code))
(unless (equal? real-ans right-ans) (unless (equal? real-ans right-ans)
(printf "Test failed: ~e gave ~e. Expected ~e~n" (printf "Test failed: ~e gave ~e. Expected ~e\n"
'code real-ans 'right-ans))) ...)))) 'code real-ans 'right-ans))) ...))))
(define-syntax test-block (define-syntax test-block

@ -149,14 +149,14 @@
(print-input-st-prod l "LA" a g print-output-terms)) (print-input-st-prod l "LA" a g print-output-terms))
(define (print-input-st-sym f name a g print-output) (define (print-input-st-sym f name a g print-output)
(printf "~a:~n" name) (printf "~a:\n" name)
(send a for-each-state (send a for-each-state
(lambda (state) (lambda (state)
(for-each (for-each
(lambda (non-term) (lambda (non-term)
(let ((res (f (make-trans-key state non-term)))) (let ((res (f (make-trans-key state non-term))))
(if (not (null? res)) (if (not (null? res))
(printf "~a(~a, ~a) = ~a~n" (printf "~a(~a, ~a) = ~a\n"
name name
state state
(gram-sym-symbol non-term) (gram-sym-symbol non-term)
@ -165,7 +165,7 @@
(newline)) (newline))
(define (print-input-st-prod f name a g print-output) (define (print-input-st-prod f name a g print-output)
(printf "~a:~n" name) (printf "~a:\n" name)
(send a for-each-state (send a for-each-state
(lambda (state) (lambda (state)
(for-each (for-each
@ -174,7 +174,7 @@
(lambda (prod) (lambda (prod)
(let ((res (f state prod))) (let ((res (f state prod)))
(if (not (null? res)) (if (not (null? res))
(printf "~a(~a, ~a) = ~a~n" (printf "~a(~a, ~a) = ~a\n"
name name
(kernel-index state) (kernel-index state)
(prod-index prod) (prod-index prod)

@ -167,7 +167,7 @@
;; build-LR0-automaton: grammar -> LR0-automaton ;; build-LR0-automaton: grammar -> LR0-automaton
;; Constructs the kernels of the sets of LR(0) items of g ;; Constructs the kernels of the sets of LR(0) items of g
(define (build-lr0-automaton grammar) (define (build-lr0-automaton grammar)
; (printf "LR(0) automaton:~n") ; (printf "LR(0) automaton:\n")
(letrec ( (letrec (
(epsilons (make-hash-table 'equal)) (epsilons (make-hash-table 'equal))
(grammar-symbols (append (send grammar get-non-terms) (grammar-symbols (append (send grammar get-non-terms)
@ -304,7 +304,7 @@
(set! automaton-non-term (cons (cons (make-trans-key kernel gs) (set! automaton-non-term (cons (cons (make-trans-key kernel gs)
unique-kernel) unique-kernel)
automaton-non-term)))) automaton-non-term))))
#;(printf "~a -> ~a on ~a~n" #;(printf "~a -> ~a on ~a\n"
(kernel->string kernel) (kernel->string kernel)
(kernel->string unique-kernel) (kernel->string unique-kernel)
(gram-sym-symbol gs)) (gram-sym-symbol gs))

@ -91,9 +91,9 @@
(hash-table-put! ht x #t))) (hash-table-put! ht x #t)))
(map cdr (apply append (vector->list table)))) (map cdr (apply append (vector->list table))))
(length (hash-table-map ht void))))) (length (hash-table-map ht void)))))
(printf "~a states, ~a grammar symbols, ~a hash-table entries, ~a reduces~n" (printf "~a states, ~a grammar symbols, ~a hash-table entries, ~a reduces\n"
num-states num-gram-syms num-ht-entries num-reduces) num-states num-gram-syms num-ht-entries num-reduces)
(printf "~a -- ~aKB, previously ~aKB~n" (printf "~a -- ~aKB, previously ~aKB\n"
(/ (+ 2 num-states (/ (+ 2 num-states
(* 4 num-states) (* 2 1.5 num-ht-entries) (* 4 num-states) (* 2 1.5 num-ht-entries)
(* 5 num-reduces)) 256.0) (* 5 num-reduces)) 256.0)

@ -97,16 +97,16 @@
(for-each (for-each
(lambda (prod) (lambda (prod)
(fprintf port (fprintf port
"~a\t~a\t=\t~a~n" "~a\t~a\t=\t~a\n"
(prod-index prod) (prod-index prod)
(gram-sym-symbol (prod-lhs prod)) (gram-sym-symbol (prod-lhs prod))
(map gram-sym-symbol (vector->list (prod-rhs prod))))) (map gram-sym-symbol (vector->list (prod-rhs prod)))))
prods) prods)
(send a for-each-state (send a for-each-state
(lambda (state) (lambda (state)
(fprintf port "State ~a~n" (kernel-index state)) (fprintf port "State ~a\n" (kernel-index state))
(for-each (lambda (item) (for-each (lambda (item)
(fprintf port "\t~a~n" (item->string item))) (fprintf port "\t~a\n" (item->string item)))
(kernel-items state)) (kernel-items state))
(newline port) (newline port)
(for-each (for-each
@ -118,22 +118,22 @@
((null? (cdr act)) ((null? (cdr act))
(print-entry sym (car act) port)) (print-entry sym (car act) port))
(else (else
(fprintf port "begin conflict:~n") (fprintf port "begin conflict:\n")
(when (> (count reduce? act) 1) (when (> (count reduce? act) 1)
(set! RR-conflicts (add1 RR-conflicts))) (set! RR-conflicts (add1 RR-conflicts)))
(when (> (count shift? act) 0) (when (> (count shift? act) 0)
(set! SR-conflicts (add1 SR-conflicts))) (set! SR-conflicts (add1 SR-conflicts)))
(map (lambda (x) (print-entry sym x port)) act) (map (lambda (x) (print-entry sym x port)) act)
(fprintf port "end conflict~n"))))) (fprintf port "end conflict\n")))))
(vector-ref grouped-table (kernel-index state))) (vector-ref grouped-table (kernel-index state)))
(newline port))) (newline port)))
(when (> SR-conflicts 0) (when (> SR-conflicts 0)
(fprintf port "~a shift/reduce conflict~a~n" (fprintf port "~a shift/reduce conflict~a\n"
SR-conflicts SR-conflicts
(if (= SR-conflicts 1) "" "s"))) (if (= SR-conflicts 1) "" "s")))
(when (> RR-conflicts 0) (when (> RR-conflicts 0)
(fprintf port "~a reduce/reduce conflict~a~n" (fprintf port "~a reduce/reduce conflict~a\n"
RR-conflicts RR-conflicts
(if (= RR-conflicts 1) "" "s"))))) (if (= RR-conflicts 1) "" "s")))))
@ -159,7 +159,7 @@
(loop (car rest) (cdr rest))) (loop (car rest) (cdr rest)))
((accept? (car rest)) ((accept? (car rest))
(fprintf (current-error-port) (fprintf (current-error-port)
"accept/reduce or accept/shift conflicts. Check the grammar for useless cycles of productions~n") "accept/reduce or accept/shift conflicts. Check the grammar for useless cycles of productions\n")
(loop current-guess (cdr rest))) (loop current-guess (cdr rest)))
(else (loop current-guess (cdr rest))))))))) (else (loop current-guess (cdr rest)))))))))
@ -180,12 +180,12 @@
(unless suppress (unless suppress
(when (> SR-conflicts 0) (when (> SR-conflicts 0)
(fprintf (current-error-port) (fprintf (current-error-port)
"~a shift/reduce conflict~a~n" "~a shift/reduce conflict~a\n"
SR-conflicts SR-conflicts
(if (= SR-conflicts 1) "" "s"))) (if (= SR-conflicts 1) "" "s")))
(when (> RR-conflicts 0) (when (> RR-conflicts 0)
(fprintf (current-error-port) (fprintf (current-error-port)
"~a reduce/reduce conflict~a~n" "~a reduce/reduce conflict~a\n"
RR-conflicts RR-conflicts
(if (= RR-conflicts 1) "" "s")))) (if (= RR-conflicts 1) "" "s"))))
table)) table))

@ -74,7 +74,7 @@
(car rhs)) (car rhs))
(if (= 3 (length rhs)) (if (= 3 (length rhs))
(p "%prec ~a" (cadadr rhs))) (p "%prec ~a" (cadadr rhs)))
(p "~n")))) (p "\n"))))
(for-each (for-each
(lambda (t) (lambda (t)
(for-each (for-each
@ -86,7 +86,7 @@
(lambda (t) (lambda (t)
(for-each (for-each
(lambda (t) (lambda (t)
(p "%token ~a~n" t) (p "%token ~a\n" t)
(hash-table-put! term-table t (format "~a" t))) (hash-table-put! term-table t (format "~a" t)))
(syntax-object->datum (terminals-def-t t)))) (syntax-object->datum (terminals-def-t t))))
terms) terms)
@ -96,10 +96,10 @@
(for-each (lambda (tok) (for-each (lambda (tok)
(p " ~a" (hash-table-get term-table tok))) (p " ~a" (hash-table-get term-table tok)))
(cdr prec)) (cdr prec))
(p "~n")) (p "\n"))
precs)) precs))
(p "%start ~a~n" start) (p "%start ~a\n" start)
(p "%%~n") (p "%%\n")
(for-each (lambda (prod) (for-each (lambda (prod)
(let ((nt (car prod))) (let ((nt (car prod)))
@ -109,9 +109,9 @@
(p "| ") (p "| ")
(display-rhs rhs)) (display-rhs rhs))
(cddr prod)) (cddr prod))
(p ";~n"))) (p ";\n")))
grammar) grammar)
(p "%%~n")))) (p "%%\n"))))
) )

@ -8,14 +8,14 @@
(define match-double-string (define match-double-string
(lexer (lexer
((:* (:~ #\" #\\)) (append (string->list lexeme) ((:+ (:~ #\" #\\)) (append (string->list lexeme)
(match-double-string input-port))) (match-double-string input-port)))
((:: #\\ any-char) (cons (string-ref lexeme 1) (match-double-string input-port))) ((:: #\\ any-char) (cons (string-ref lexeme 1) (match-double-string input-port)))
(#\" null))) (#\" null)))
(define match-single-string (define match-single-string
(lexer (lexer
((:* (:~ #\' #\\)) (append (string->list lexeme) ((:+ (:~ #\' #\\)) (append (string->list lexeme)
(match-single-string input-port))) (match-single-string input-port)))
((:: #\\ any-char) (cons (string-ref lexeme 1) (match-single-string input-port))) ((:: #\\ any-char) (cons (string-ref lexeme 1) (match-single-string input-port)))
(#\' null))) (#\' null)))

@ -174,7 +174,7 @@
(lambda (e) (lambda (e)
(fprintf (fprintf
(current-error-port) (current-error-port)
"Cannot write yacc-output to file \"~a\"~n" "Cannot write yacc-output to file \"~a\"\n"
yacc-output)))] yacc-output)))]
(call-with-output-file yacc-output (call-with-output-file yacc-output
(lambda (port) (lambda (port)
@ -271,14 +271,14 @@
(let ((a (find-action stack tok val start-pos end-pos))) (let ((a (find-action stack tok val start-pos end-pos)))
(cond (cond
((runtime-shift? a) ((runtime-shift? a)
;; (printf "shift:~a~n" (runtime-shift-state a)) ;; (printf "shift:~a\n" (runtime-shift-state a))
(cons (make-stack-frame (runtime-shift-state a) (cons (make-stack-frame (runtime-shift-state a)
val val
start-pos start-pos
end-pos) end-pos)
stack)) stack))
(else (else
;; (printf "discard input:~a~n" tok) ;; (printf "discard input:~a\n" tok)
(let-values (((tok val start-pos end-pos) (let-values (((tok val start-pos end-pos)
(extract (get-token)))) (extract (get-token))))
(remove-input tok val start-pos end-pos)))))))) (remove-input tok val start-pos end-pos))))))))
@ -286,7 +286,7 @@
(let ((a (find-action stack 'error #f start-pos end-pos))) (let ((a (find-action stack 'error #f start-pos end-pos)))
(cond (cond
((runtime-shift? a) ((runtime-shift? a)
;; (printf "shift:~a~n" (runtime-shift-state a)) ;; (printf "shift:~a\n" (runtime-shift-state a))
(set! stack (set! stack
(cons (cons
(make-stack-frame (runtime-shift-state a) (make-stack-frame (runtime-shift-state a)
@ -296,7 +296,7 @@
stack)) stack))
(remove-input tok val start-pos end-pos)) (remove-input tok val start-pos end-pos))
(else (else
;; (printf "discard state:~a~n" (car stack)) ;; (printf "discard state:~a\n" (car stack))
(cond (cond
((< (length stack) 2) ((< (length stack) 2)
(raise-read-error "parser: Cannot continue after error" (raise-read-error "parser: Cannot continue after error"
@ -330,7 +330,7 @@
(let ((action (find-action stack tok val start-pos end-pos))) (let ((action (find-action stack tok val start-pos end-pos)))
(cond (cond
((runtime-shift? action) ((runtime-shift? action)
;; (printf "shift:~a~n" (runtime-shift-state action)) ;; (printf "shift:~a\n" (runtime-shift-state action))
(parsing-loop (cons (make-stack-frame (runtime-shift-state action) (parsing-loop (cons (make-stack-frame (runtime-shift-state action)
val val
start-pos start-pos
@ -338,7 +338,7 @@
stack) stack)
(get-token))) (get-token)))
((runtime-reduce? action) ((runtime-reduce? action)
;; (printf "reduce:~a~n" (runtime-reduce-prod-num action)) ;; (printf "reduce:~a\n" (runtime-reduce-prod-num action))
(let-values (((new-stack args) (let-values (((new-stack args)
(reduce-stack stack (reduce-stack stack
(runtime-reduce-rhs-length action) (runtime-reduce-rhs-length action)
@ -367,7 +367,7 @@
new-stack) new-stack)
ip)))) ip))))
((runtime-accept? action) ((runtime-accept? action)
;; (printf "accept~n") ;; (printf "accept\n")
(stack-frame-value (car stack))) (stack-frame-value (car stack)))
(else (else
(if src-pos (if src-pos

Loading…
Cancel
Save