forked from ParkerTewell/Typed-Iniquity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ast.rkt
65 lines (56 loc) · 2.03 KB
/
ast.rkt
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
#lang racket
(provide (all-defined-out))
;; type Prog = (Prog (Listof TypeDefn) Expr)
(struct Prog (tds e) #:prefab)
;; type UnparsedProg = (UnparsedProg (Listof UntypedDefn) (Listof TypeAnno) Expr)
(struct UnparsedProg (utds tas e))
;; type UntypedDefn = (UntypedDefn Id (Listof Id) Expr)
(struct UntypedDefn (f xs e) #:prefab)
;; type TypedDefn = (TypedDefn Id (Listof Id) Expr (Listof Type) Type)
(struct TypedDefn (f xs e xts et) #:prefab)
;; type TypeAnno = (TypeAnno Id (Listof Type) Type)
(struct TypeAnno (f xts et) #:prefab)
;; type Expr = (Eof)
;; | (Empty)
;; | (Int Integer)
;; | (Bool Boolean)
;; | (Char Character)
;; | (Str String)
;; | (Prim0 Op0)
;; | (Prim1 Op1 Expr)
;; | (Prim2 Op2 Expr Expr)
;; | (Prim3 Op3 Expr Expr Expr)
;; | (If Expr Expr Expr)
;; | (Begin Expr Expr)
;; | (Let Id Expr Expr)
;; | (Var Id)
;; | (App Id (Listof Expr))
;; type Id = Symbol
;; type Op0 = 'read-byte
;; type Op1 = 'add1 | 'sub1 | 'zero?
;; | 'char? | 'integer->char | 'char->integer
;; | 'write-byte | 'eof-object?
;; | 'box | 'car | 'cdr | 'unbox
;; | 'empty? | 'cons? | 'box?
;; | 'vector? | vector-length
;; | 'string? | string-length
;; type Op2 = '+ | '- | '< | '=
;; | 'cons
;; | 'make-vector | 'vector-ref
;; | 'make-string | 'string-ref
;; type Op3 = 'vector-set!
(struct Eof () #:prefab)
(struct Empty () #:prefab)
(struct Int (i) #:prefab)
(struct Bool (b) #:prefab)
(struct Char (c) #:prefab)
(struct Str (s) #:prefab)
(struct Prim0 (p) #:prefab)
(struct Prim1 (p e) #:prefab)
(struct Prim2 (p e1 e2) #:prefab)
(struct Prim3 (p e1 e2 e3) #:prefab)
(struct If (e1 e2 e3) #:prefab)
(struct Begin (e1 e2) #:prefab)
(struct Let (x e1 e2) #:prefab)
(struct Var (x) #:prefab)
(struct App (f es) #:prefab)