-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ss
120 lines (106 loc) · 4.08 KB
/
main.ss
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
(load "chez-init.ss")
(load "interpreter.ss")
(load "env.ss")
(load "parser.ss")
(load "cont.ss")
(define (rl) (load "main.ss"))
(define (rep)
(begin
(display "--> ")
(write (top-level-eval (read)))
(newline)
(rep)))
;BNF definition
;---------------
; <program> ::= <form>*
; <form> <definition> | <expression>
; <definition> ::= <variable definition> | (begin <definition>*)
; <variable definition> ::= (define <variable> <expression>)
; <expression> ::= <constant>
; | <variable>
; | (quote <datum>)
; | (lambda <list> <list>)
; | (informal-lambda <symbol> <expressions>)
; | (application <expression> <list>)
; | (lit <constant>)
; | (if <expression> <expression> <expression>)
; | (if2 <expression> <expression>)
; | (set! <variable> <expression>)
; | (let <symbols> <expressions> <expressions>)
; | (let* <symbols> <expressions> <expressions>)
; | (letrec <symbols> <expressions> <expressions>)
; | (set! <symbols> <expressions> <expressions>)
; | (begin <expressions>)
; | (dotted--lambda <pair> <expressions>)
; | (cond <lists>)
; | (and <expressions>)
; | (or <expressions>)
; | (case <constant> <lists>)
; | (while <expression> <expressions>)
; | (set <symbol> <expression>)
; <constant> ::= <number> | <string> | <pair> | <vector> | <boolean> | <symbol> | <null>
; <formals> ::= <variable>
; | (<variable>*)
; | (<variable> <variable>* . <variable>)
; <application> ::= (<expression> <expression>*)
; <boolean> ::= #t|#f
; <character> ::= "A" | "B" | "C" | "D" | "E" | "F" | "G"
; | "H" | "I" | "J" | "K" | "L" | "M" | "N"
; | "O" | "P" | "Q" | "R" | "S" | "T" | "U"
; | "V" | "W" | "X" | "Y" | "Z"
; <string> ::= "<character>" | "<string><character>"
; <list> ::= (<expression>*)
; <pair> ::= (<expression> . <expression>)
; <vector> ::= #(<datum>*)
; <datum> ::= <boolean>
; |<symbol>
; |<string>
; |<number>
; |<list>
; |<vector>
; <Number> ::= <PositiveNumber>|<NegativeNumber>
; <NegativeNumber> ::= <NegativeDigit>|<NonZeroNegativeDigit><Digits>
; <PositiveNumber> ::= <Digit>|<NonZeroDigit><Digits>
; <Digits> ::= <Digit>|<Digits><Digits>
; <Digit> ::= 0|<NonZeroDigit>
; <NonZeroDigit> ::= 1|2|3|4|5|6|7|8|9
; <NonZeroNegativeDigit> ::= -1|-2|-3|-4|-5|-6|-7|-8|-9
; <AllNonZeroDigits> ::= <NonZeroDigit>|<NonZeroNegativeDigit>
; <void> ::= <void>
; <set-car!> ::= (set-car! <pair> <expression>)
; <set-cdr!> ::= (set-cdr! <pair> <expression>)
; <+> ::= (+ <number> <number>)
; <-> ::= (- <number> <number>)
; <*> ::= (* <number> <number>)
; <add1> ::= (+ <number> 1)
; <sub1> ::= (- <number> 1)
; <cons> ::= (cons <list> <list>)
; <car> ::= (car <list>)
; <=> ::= (= <number> <number>)
; </> ::= (/ <number> <number>)
; <zero?> ::= (zero? <number>)
; <not> ::= (not <expression>)
; <and> ::= (and <expression>)
; < <, <=, >, >= > ::= (<, <=, >, >= <number> <number>)
; <cdr> ::= (cdr <list>)
; <list> ::= (list <expression>)
; <null?> ::= (null? <list>)
; <eq?> ::= (eq? <expression> <expression>)
; <equal?> ::= (equal? <expression> <expression>)
; <atom?> ::= (atom? <expression>)
; <length> ::= (length <list>)
; <list->vector> ::= (list->vector <list>)
; <list?> ::= (list? <expression>)
; <pair?> ::= (pair? <expression>)
; <procedure?> ::= (procedure? <expression>)
; <vector->list> ::= (vector->list <vector>)
; <vector> ::= (vector <expression>)
; <make-vector> ::= (make-vector <expression>)
; <vector-ref> ::= (vector-ref <expression>)
; <vector?> ::= (vector? <expression>)
; <number?> ::= (number? <expression>)
; <symbol?> ::= (symbol? <expression>)
; <vector-set!> ::= (vector-set! <vector> <expression>)
; <c**r> ::= (c**r <list>)
; <c***r> ::= (c***r <list>)
; <max> :: (max <number> <number>)