; COSC 152 ; Fall 2005 ; Dennis Brylow ; ; Lecture 25 Demo ; Interactive interpreter fragments. ; read-eval-print loop as in EoPL. Doesn't take well to EOF. (define read-eval-print (sllgen:make-rep-loop "--> " evaluate (sllgen:make-stream-parser scanner-hw8 grammar-hw8))) ; A little Scheme I/O work to read in text strings with matched parens. (define (read-string) (letrec ([read-helper (lambda (lst depth) (let ([c (read-char)]) (cond ((eof-object? c) c) ((eq? c #\newline ) (if (zero? depth) (reverse lst) (read-helper lst depth))) ((eq? c #\( ) (read-helper (cons c lst) (+ 1 depth))) ((eq? c #\) ) (read-helper (cons c lst) (- depth 1))) (else (read-helper (cons c lst) depth)) )))] [str (read-helper '() 0)]) (if (eof-object? str) str (list->string str)))) ; A read-eval-print loop using the string parser and our own string input ; routine. (define interpreter (lambda () (begin (display "--> ") (let ([ in (read-string)]) (if (eof-object? in) 'eof (begin (write (evaluate (parse in))) (newline) (interpreter)) )))))