-
Notifications
You must be signed in to change notification settings - Fork 0
/
Compiler.scm
executable file
·48 lines (46 loc) · 1.22 KB
/
Compiler.scm
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
(define debug.scan #f)
(define debug.parse #f)
(define debug.semantic #f)
(define debug.generate #f)
(load "Util.scm")
(load "Scanner.scm")
(load "Parser.scm")
(load "Semantic.scm")
(load "Generator.scm")
;;; engage triangle mode
; compile : string,string,symbol->(file)
(define (compile filename outname lang)
(display "\n")
(let ((input (read-file filename)))
(let ((tokens (scan input)))
(if (eq? tokens '!scan-error)
#f
(begin
(if (or debug.scan debug.parse) (begin (fmt "=> tokens =" (map token.unpack tokens))))
(let ((syntax (parse tokens)))
(if (eq? syntax '!syntax-error)
#f
(begin
(if (or debug.parse debug.semantic) (fmt "=> syntax =" (map node.unpack syntax)))
(let ((table (semantic syntax)))
(if (eq? table '!semantic-error)
#f
(begin
(if (or debug.semantic debug.generate) (fmt "=> table =" (map entry.unpack table)))
(let ((output (generate table lang)))
(if debug.generate (fmt "=> code =" output))
(write-file outname output)
(fmt "the output has been written to" outname)
#t
)
)
)
)
)
)
)
)
)
)
)
)