-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsymbol-tables.eag
executable file
·239 lines (201 loc) · 7.48 KB
/
symbol-tables.eag
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
// Oberon-0 (d) symbol tables) MK 06.96
OberonO = Decls Stmts.
OberonOd <+ Decls Stmts: OberonO>:
Standard <Tab> Decls <Tab, 'NIL', Decls, Tab1> Stmts <'(' Tab Tab1 ')', Stmts>.
letter =
'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'
| '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'.
letter:
<+ 'a': letter> 'a' | <+ 'b': letter> 'b' | <+ 'c': letter> 'c' | <+ 'd': letter> 'd'
| <+ 'e': letter> 'e' | <+ 'f': letter> 'f' | <+ 'g': letter> 'g' | <+ 'h': letter> 'h'
| <+ 'i': letter> 'i' | <+ 'j': letter> 'j' | <+ 'k': letter> 'k' | <+ 'l': letter> 'l'
| <+ 'm': letter> 'm' | <+ 'n': letter> 'n' | <+ 'o': letter> 'o' | <+ 'p': letter> 'p'
| <+ 'q': letter> 'q' | <+ 'r': letter> 'r' | <+ 's': letter> 's' | <+ 't': letter> 't'
| <+ 'u': letter> 'u' | <+ 'v': letter> 'v' | <+ 'w': letter> 'w' | <+ 'x': letter> 'x'
| <+ 'y': letter> 'y' | <+ 'z': letter> 'z'
| <+ 'A': letter> 'A' | <+ 'B': letter> 'B' | <+ 'C': letter> 'C' | <+ 'D': letter> 'D'
| <+ 'E': letter> 'E' | <+ 'F': letter> 'F' | <+ 'G': letter> 'G' | <+ 'H': letter> 'H'
| <+ 'I': letter> 'I' | <+ 'J': letter> 'J' | <+ 'K': letter> 'K' | <+ 'L': letter> 'L'
| <+ 'M': letter> 'M' | <+ 'N': letter> 'N' | <+ 'O': letter> 'O' | <+ 'P': letter> 'P'
| <+ 'Q': letter> 'Q' | <+ 'R': letter> 'R' | <+ 'S': letter> 'S' | <+ 'T': letter> 'T'
| <+ 'U': letter> 'U' | <+ 'V': letter> 'V' | <+ 'W': letter> 'W' | <+ 'X': letter> 'X'
| <+ 'Y': letter> 'Y' | <+ 'Z': letter> 'Z'.
digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'.
digit:
<+ '0': digit> '0' | <+ '1': digit> '1' | <+ '2': digit> '2' | <+ '3': digit> '3'
| <+ '4': digit> '4' | <+ '5': digit> '5' | <+ '6': digit> '6' | <+ '7': digit> '7'
| <+ '8': digit> '8' | <+ '9': digit> '9'.
letgits = | letter letgits | digit letgits.
id = 'ID' letgits.
letgits:
<+ : letgits>
| <+ letter letgits: letgits>
letter <letter> letgits <letgits>
| <+ digit letgits: letgits>
digit <digit> letgits <letgits>.
id <+ 'ID' letgits: id>:
'ID' letgits <letgits>.
digits = | digit digits.
int = 'INT' digits.
digits:
<+ : digits>
| <+ digit digits: digits>
digit <digit> digits <digits>.
int <+ 'INT' digits: int>:
'INT' digits <digits>.
Sel = | '.' id Sel | '[' Expr ']' Sel.
Sel:
<- Tab: Tab, + : Sel>
| <- Tab: Tab, + '.' id Sel: Sel>
'.' id <id> Sel <Tab, Sel>
| <- Tab: Tab, + '[' Expr ']' Sel: Sel>
'[' Expr <Tab, Expr> ']' Sel <Tab, Sel>.
UnOp = '+' | '-' | 'NOT' | '()'.
Op = '+' | '-' | '*' | 'DIV' | 'MOD' | 'OR' | 'AND' | '=' | '#' | '<' | '<=' | '>' | '>='.
Expr =
IdUse Sel
| int
| UnOp Expr
| '(' Expr Op Expr ')'.
UnOp:
<+ '+': UnOp> '+' | <+ '-': UnOp> '-'
| <+ 'NOT': UnOp> 'NOT'
| <+ '()': UnOp> '()'.
Op:
<+ '+': Op> '+' | <+ '-': Op> '-'
| <+ '*': Op> '*' | <+ 'DIV': Op> 'DIV' | <+ 'MOD': Op> 'MOD'
| <+ 'OR': Op> 'OR' | <+ 'AND': Op> 'AND'
| <+ '=': Op> '=' | <+ '#': Op> '#'
| <+ '<': Op> '<' | <+ '<=': Op> '<=' | <+ '>': Op> '>' | <+ '>=': Op> '>='.
Expr:
<- Tab: Tab, + id Tab Sel: Expr>
id <id> Sel <Tab, Sel>
| <- Tab: Tab, + int: Expr>
int <int>
| <- Tab: Tab, + UnOp Expr: Expr>
UnOp <UnOp> Expr <Tab, Expr>
| <- Tab: Tab, + '(' Expr1 Op Expr2 ')': Expr>
'(' Expr <Tab, Expr1> Op <Op> Expr <Tab, Expr2> ')'.
APList = 'NIL' | Expr APList.
APList:
<- Tab: Tab, + 'NIL': APList>
'NIL'
| <- Tab: Tab, + Expr APList: APList>
Expr <Tab, Expr> APList <Tab, APList>.
Stmts = 'NIL' | '(' Stmts Stmts ')'
| 'ASSIGN' IdUse Sel Expr
| 'CALL' IdUse APList
| 'IF' Expr Stmts Stmts
| 'WHILE' Expr Stmts
| 'REPEAT' Stmts Expr.
Stmts:
<- Tab: Tab, + 'NIL': Stmts>
'NIL'
| <- Tab: Tab, + '(' Stmts1 Stmts2 ')': Stmts>
'(' Stmts <Tab, Stmts1> Stmts <Tab, Stmts2> ')'.
Stmts:
<- Tab: Tab, + 'ASSIGN' id Tab Sel Expr: Stmts>
'ASSIGN' id <id> Sel <Tab, Sel> Expr <Tab, Expr>
| <- Tab: Tab, + 'CALL' id Tab APList: Stmts>
'CALL' id <id> APList <Tab, APList>
| <- Tab: Tab, + 'IF' Expr Stmts1 Stmts2: Stmts>
'IF' Expr <Tab, Expr> Stmts <Tab, Stmts1> Stmts <Tab, Stmts2>
| <- Tab: Tab, + 'WHILE' Expr Stmts: Stmts>
'WHILE' Expr <Tab, Expr> Stmts <Tab, Stmts>
| <- Tab: Tab, + 'REPEAT' Stmts Expr: Stmts>
'REPEAT' Stmts <Tab, Stmts> Expr <Tab, Expr>.
BasicType = 'INT' | 'BOOL'.
N = | '|' N.
Type =
BasicType
| 'STRUCT' N.
BasicType:
<+ 'INT': BasicType> 'INT' | <+ 'BOOL': BasicType> 'BOOL'.
N:
<+ : N>
| <+ '|' N: N>
'|' N <N>.
Type:
<+ BasicType: Type>
BasicType <BasicType>
| <+ 'STRUCT' N: Type>
'STRUCT' N <N>.
Kind = 'VAR' | 'VAL'.
FPList = 'NIL' | Kind Type FPList.
Kind:
<+ 'VAR': Kind> 'VAR' | <+ 'VAL': Kind> 'VAL'.
FPList:
<+ 'NIL': FPList>
'NIL'
| <+ Kind Type FPList: FPList>
Kind <Kind> Type <Type> FPList <FPList>.
Attr =
'UNDEF'
| 'CONST' BasicType
| 'VAR' Type
| 'REF' Type
| 'PROC' FPList.
Tab = 'NIL' | '(' Tab Tab ')'
| id Attr.
IdDef = id Tab.
IdUse = id Tab.
Object =
'CONST' Expr
| 'TYPE' Type
| 'FIELD' Type
| 'VAR' Type
| 'REF' Type
| 'PROC' FPList Decls Stmts.
Struct =
'ARRAY' Expr Type
| 'RECORD' Decls.
Decls = 'NIL' | '(' Decls Decls ')'
| IdDef Object
| 'STRUCT' N Struct.
Object:
<- Tab: Tab, - Tab1: Tab, - id: id,
+ 'CONST' Expr: Object, + 'CONST' 'INT': Attr>
'CONST' Expr <'(' Tab '(' Tab1 id 'UNDEF' ')' ')', Expr>
| <- Tab: Tab, - Tab1: Tab, - id: id,
+ 'TYPE' Type: Object, + 'UNDEF': Attr>
'TYPE' Type <Type>
| <- Tab: Tab, - Tab1: Tab, - id: id,
+ 'FIELD' Type: Object, + 'UNDEF': Attr>
'FIELD' Type <Type>
| <- Tab: Tab, - Tab1: Tab, - id: id,
+ 'VAR' Type: Object, + 'VAR' Type: Attr>
'VAR' Type <Type>
| <- Tab: Tab, - Tab1: Tab, - id: id,
+ 'REF' Type: Object, + 'REF' Type: Attr>
'REF' Type <Type>
| <- Tab: Tab, - Tab1: Tab, - id: id,
+ 'PROC' FPList Decls Stmts: Object, + 'PROC' FPList: Attr>
'PROC' FPList <FPList>
<'(' Tab '(' Tab1 id 'PROC' FPList ')' ')', Decls, Stmts>
( <- Tab: Tab, + Decls: Decls, + Stmts: Stmts>
Decls <Tab, 'NIL', Decls, Tab1> Stmts <'(' Tab Tab1 ')', Stmts>
).
Struct:
<- Tab: Tab, + 'ARRAY' Expr Type: Struct>
'ARRAY' Expr <Tab, Expr> Type <Type>
| <- Tab: Tab, + 'RECORD' Decls: Struct>
'RECORD' Decls <Tab, 'NIL', Decls, Tab>.
Decls:
<- Tab: Tab, - Tab1: Tab, + 'NIL': Decls, + Tab1: Tab>
'NIL'
| <- Tab: Tab, - Tab1: Tab, + '(' Decls1 Decls2 ')': Decls, + Tab3: Tab>
'(' Decls <Tab, Tab1, Decls1, Tab2> Decls <Tab, Tab2, Decls2, Tab3> ')'.
Decls:
<- Tab: Tab, - Tab1: Tab, + id Tab1 Object: Decls, + '(' Tab1 id Attr ')': Tab>
id <id> Object <Tab, Tab1, id, Object, Attr>
| <- Tab: Tab, - Tab1: Tab, + 'STRUCT' N Struct: Decls, + Tab1: Tab>
'STRUCT' N <N> Struct <'(' Tab Tab1 ')', Struct>.
Standard <+ '(' 'ID' 'F' 'A' 'L' 'S' 'E' 'CONST' 'BOOL'
'(' 'ID' 'T' 'R' 'U' 'E' 'CONST' 'BOOL'
'(' 'ID' 'R' 'e' 'a' 'd' 'PROC' 'VAR' 'INT' 'NIL'
'(' 'ID' 'W' 'r' 'i' 't' 'e' 'PROC' 'VAL' 'INT' 'NIL'
'(' 'ID' 'W' 'r' 'i' 't' 'e' 'H' 'e' 'x' 'PROC' 'VAL' 'INT' 'NIL'
'(' 'ID' 'W' 'r' 'i' 't' 'e' 'L' 'n' 'PROC' 'NIL'
'NIL' ')' ')' ')' ')' ')' ')': Tab>: .