-
Notifications
You must be signed in to change notification settings - Fork 0
/
Typing_rules.txt
131 lines (77 loc) · 2.58 KB
/
Typing_rules.txt
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
In this plaintext file, letters C, D, etc. stand for Gamma, Delta, etc.
a.k.a. typing contexts.
Remarks:
(1) DFP denotes the set of double-precision floating-point numbers.
(2) STR is the set of strings.
C |- child1 : T1, ..., C |- childN : TN
-----------------------------------------
C |- program child1...childN : Void
C |- param : P C |- ret : R
-------------------------------------
C |- funcDecl param ret : P -> R
C |- param : P C |- ret : R C |- body : Void
--------------------------------------------------------
C |- funcDef param ret body : P -> R
C |- child1 : T1, ..., C |- childN : TN
-----------------------------------------
C |- block child1...childN : Void
-------------------
C |- return: Void
C |- expr : T
----------------------
C |- return expr : T
C |- cond : Bool C |- then : T
----------------------------------
C |- if cond then : Void
C |- cond : Bool C |- then : T C |- else : E
--------------------------------------------------
C |- if cond then else : Void
C |- cond : Bool C |- body : T
-----------------------------------
C |- while cond body : Void
C |- expr : T
-------------------------- (x : T) \elem C
C |- varDecl x expr : T;
------------------
C |- true : Bool
-------------------
C |- false : Bool
-------------- n \elem Z
C |- n : Int
----------------- x \elem DFP (1)
C |- x : Double
----------------- x \elem STR (2)
C |- x : String
------------- (x : T) \elem C
C |- x : T;
C |- a : Int C |- b : Int
------------------------------ (ditto for -, *, /)
C |- a + b : Int
C |- a : Double C |- b : Double
------------------------------------ (ditto for -, *, /)
C |- a + b : Double
C |- a : Double C |- b : Int
--------------------------------- (ditto for -, *, /)
C |- a + b : Double
C |- a : String C |- b : String
------------------------------------
C |- a + b : String
C |- a : Bool C |- b : Bool
------------------------------- (ditto for ||)
C |- a && b : Bool
C |- a : T C |- b : T
------------------------------ T \elem { Bool, Int, String }
C |- a < b : Bool
(ditto for >, <=, >=, ==, !=)
C |- x : T C |- expr : T
------------------------------
C |- x = expr : Void
C |- expr : Bool
-------------------
C |- !expr : Bool
C |- expr : T
------------------- T \elem { Int, Double } (ditto for -)
C |- +expr : T
C |- f : T -> U C |- x : T
--------------------------------
C |- f(x) : U