Bigloo homepage -- IOs Example





 1: (module roman
 2:    (import roman
 3:            arabic)
 4:    (main   main))
 5: 
 6: (define (main argv)
 7:    (let ((prompt ":-) "))
 8:       (display prompt)
 9:       (let loop ((exp (read/rp grammar-roman (current-input-port))))
10:          (if (eof-object? exp)
11:              'done
12:              (begin
13:                 (display* (eval exp) #\Newline prompt)
14:                 (loop (read/rp grammar-roman (current-input-port))))))))
15: 
16: (define grammar-roman
17:    (let ((par-open 0))
18:       (regular-grammar ((arabic (in "09"))
19:                         (roman  (uncase "ivxlcdm")))
20:          ((+ (in #\space #\newline #\tab))
21:           (ignore))
22:          ((+ arabic)
23:           (string->integer (the-string)))
24:          ((+ roman)
25:           (roman->arabic (the-string)))
26:          (#\(
27:           (let ((open-key par-open))
28:              (set! par-open (+ 1 par-open))
29:              (rgc-context 'pair)
30:              (let loop-pair ((walk (ignore))) 
31:                 (cond
32:                    ((= open-key par-open)
33:                     '())
34:                    (else
35:                     (cons walk (loop-pair (ignore))))))))
36:          (#\)
37:           (set! par-open (- par-open 1))
38:           (if (< par-open 0)
39:               (begin
40:                  (set! par-open 0)
41:                  (ignore))
42:               #f))
43:          ((in "+-*\\")
44:           (string->symbol (the-string)))
45:          (else
46:           (let ((char (the-failure)))
47:              (if (eof-object? char)
48:                  char
49:                  (error "grammar-roman" "Illegal char" char)))))))

This Html page has been produced by Skribe.
Last update Thu Feb 27 08:01:21 2020.