aboutsummaryrefslogtreecommitdiff
path: root/hw05_arith_scanner.scm
blob: f15833fa07223986f53883b5abac9b9302aba17f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#lang eopl

;; <arith-expr> ::== <arith-term> { <add-op> <arith-term> }*
;; <arith-term> ::== <arith-factor> { <mult-op> <arith-factor> }*
;; <arith-factor> ::== <number>
;; <arith-factor> ::== ( <arith-expr> )
;; <add-op> ::== + | -
;; <mult-op> ::== * | / 

(define arith-scanner
  '(
    (add-op (or "+" "-") symbol)
    (mult-op (or "*" "/") symbol)
    (number (digit (arbno digit)) number)
  ))

(define arith-grammar
  '(
    (expression (number) arith-factor)
    ;(expression (number add-op number) arith-factor)
    ;(expression (expression add-op expression) arith-factor)
    ))

(sllgen:make-define-datatypes arith-scanner arith-grammar)

(define list-the-datatypes
  (lambda ()
    (sllgen:list-define-datatypes arith-scanner arith-grammar)))

(define just-scan
  (sllgen:make-string-scanner arith-scanner '()))

(define scan&parse
  (sllgen:make-string-parser arith-scanner arith-grammar) )

(define read-eval-print
  (sllgen:make-rep-loop "--> " stmt-evaluator
                        (sllgen:make-stream-parser arith-scanner arith-grammar) ))