-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.ref
executable file
·421 lines (303 loc) · 12 KB
/
project.ref
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
entry go
extrn prout
extrn add, sub, p1, m1
extrn numb, card, opnget, libget, libput, clsget, opnput, clsput
extrn functab, ftochar, chartof, printm, proutm
extrn br, dg, cp, dgall
empty error
go = <opnget <card 'enter file name\n'> > <opnput 'output.c'> <out <program <getFile () <libget>>> (<dg /error/>)> <clsget> <clsput>
getFile
(e1) v2 = <getFile(e1 v2 '\n') <libget>>
(e1) = <deleter e1>
deleter
e1 '\n' e2 = <deleter e1 ' ' e2>
e1 ' ' e2 = <deleter e1 ' ' e2>
e1 = <begEnd e1>
begEnd
e1 'end;' e2 = <begEnd <pairEnd e1 'end;'> e2>
e1 = <begRepeat e1>
pairEnd
R e1 'begin ' e2 'end;' = e1 ( e2 )
e1 = <br /error/ '=' (<printm 'error - "unpaired end!"' e1>)>
begRepeat
e1 'until ' e2 ';' e3 = <begRepeat <pairUntil e1 'until '> e2 ';' <white /1/> e3>
e1 = <begCase e1>
pairUntil
R e1 'repeat ' e2 'until ' e3 = e1 'rpt' ( e2 ) 'untl ' e3
e1 = <br /error/ '=' (<printm 'error - unpaired "until!"' e1>)>
begCase
e1 'endcase;' e2 = <begCase <pairCase e1 'endcs;' > e2 >
e1 = <begIf e1> <prout '\n\n\n'>
pairCase
R e1 'case ' e2 'of ' e3 'endcs;' = e1 'cs ' e2 'of' ( e3 ) 'endcs;'
e1 = <br /error/ '=' (<printm 'error = unpaired "endcase"'>)>
begIf
e1 'else ' e2 = <begIf <pairIf e1 'else '> e2>
e1 = <PPcut e1>
pairIf
R e1 'if ' e2 'else ' = <helpIf e1 'iff ' e2 'els '>
e1 = <br /error/ '=' (<printm 'error = unpaired "else"'>)>
helpIf
e1 'iff ' e2 'then ' e3 'els ' = e1 'iff ' e2 'then ' ( e3 ) 'els '
PPcut
e1 'function ' e2 ';' e3 ( e4 ) e5 = 'function ' e2 ';' e3 ( e4 ) <PPcut e1 e5>
e1 'procedure ' e2 ';' e3 ( e4 ) e5 = 'procedure ' e2 ';' e3 ( e4 ) <PPcut e1 e5>
e1 = e1
program
e0 'program ' e1 ';' e2 = <subPr e0> '\n' 'int main() { \n'<const e2>
e1 = </error/ '=' (<printm 'error - "progam" label missing'>)>
subPr
e(' ')9 'function ' e2 '(' e6 ')' e7';' e3 ( e4 ) e5 = <funcHead e2 '(' e6 ')' e7';'> <PPBody e3 (e4)> <subPr e5>
e(' ')9 'procedure ' e2 '(' e6 ')' e(' ')8 ';' e3 ( e4 ) e5 = <procHead e2 '(' e6 ');'> <PPBody e3 (e4)> <subPr e5>
e1 = e1
procHead
e1 '(' e2 ')' e(' ')8';' = 'void ' e1 '(' <argList (<unspace e1>) e2> ')\n' +
<br 'status' '=' <unspace e1>> <br 'proc'e1 '=' <typeList <argList (<unspace e1>) e2>>>
funcHead
e1 '(' e2 ')' e(' ')8 ':' e(' ')7 e3 ';' = <reNameType e3> ' ' e1 '(' <argList (<unspace e1>) e2> ')\n' +
<br 'status' '=' <unspace e1>> <br 'func'e1 '=' <reNameType e3>',' <typeList <argList (<unspace e1>) e2>>>
argList
(en) e(' ')9 'var ' e1 ':' e2 ';' e3 = <oneTypeList (en) ('var') e1 (e2)> ', ' <argList (en) e3>
(en) e(' ')9 'var ' e1 ':' e2 = <oneTypeList (en) ('var') e1 (e2)>
(en) e1 ':' e2 ';' e3 = <oneTypeList (en) e1 (e2)> ', ' <argList (en) e3>
(en) e1 ':' e2 = <oneTypeList (en) e1 (e2)>
(en) e1 = <br /error/ '=' (<printm 'error - parsing argument list!'>)>
oneTypeList
(en) ('var') e1 ',' e2 (e3) = <oneVar (en) ('var') <unspace e1> (<reNameType e3>)> ', ' <oneTypeList (en) ('var') e2 (e3)>
(en) e1 ',' e2 (e3) = <oneVar (en) <unspace e1> (<reNameType e3>)> ', ' <oneTypeList (en) e2 (e3)>
(en) e1 (e3) = <oneVar (en) <unspace e1> (<reNameType e3>)>
oneVar
(en) ('var') e1 (e2) = e2 '* ' e1 <br 'var'e1 '=' e2'*'>
(en) e1 (e2) = e2 ' ' e1 <br 'var'e1 '=' e2>
typeList
e1 ' ' e2 ', ' e3 = e1 ',' <typeList e3>
e1 ' ' e2 = e1
PPBody
e1 = '{\n' <const e1> <delVar <dgall>>
delVar
('func' e1) e2 = <br 'func' e1> <delVar e2>
('proc' e1) e2 = <br 'proc' e1> <delVar e2>
(e1) e2 = <delVar e2>
e1 =
const
e(' ')9 'const ' e1 '=' e2 ';' e3 = <white /1/> 'const ' <typeConst e2> ' ' e1 '='e2 <br 'var'<unspace e1> '=' 'const '<typeConst e2>> ';\n' <const /0/ e3>
/0/ e(' ')9 'var' e1 = <var 'var' e1>
/0/ e1 '=' e2 ';' e3 = <white /1/> 'const ' <typeConst e2> ' ' e1 '=' e2 <br 'var'<unspace e1> '=' 'const '<typeConst e2>> ';\n' <const /0/ e3>
e1 = <var e1>
typeConst
/0/ v(D)1 = 'int'
/0/ v(D)1 '.' v(D)2 = 'double'
/0/ '"' v1 '"' = 'char*'
/0/ 'true' = 'bool'
/0/ 'false' = 'bool'
/0/ e1 = <br /error/ '=' (<printm 'error - const type error' e1>)>
/1/ v(D)1 = 'int'
/1/ v(D)1 '.' v(D)2 = 'double'
/1/ '"' v1 '"' = 'char*'
/1/ 'true' = 'bool'
/1/ 'false' = 'bool'
/1/ e1 = /error/
e1 = <typeConst /0/ <unspace e1>>
var
e(' ')9 'var ' e1 ';' e2 = <white /1/> <section e1> <var e2>
e(' ')9 'begin ' e2 = '\n'<body 'begin ' e2>
e(' ')9 (e2) = '\n'<body (e2)>
e(' ')9 e1 '; ' e2 = <white /1/> <section e1> <var e2>
e1 = <br /error/ '=' (<printm 'error - "var" or "begin" expected'>)>
section
e1 ',' e2 ':' e3 = <variable (e3) e1> <white /1/> <section e2 ' : ' e3>
e1 ':' e2 = <variable (e2) e1>
e1 = <br /error/ '=' (<printm 'error - unexpected sequence in "var" section'>)>
variable
(e1) e2 = <br 'var' <unspace e2>'='<reNameType <unspace e1>>> <reNameType <unspace e1>> ' ' <unspace e2> ';\n'
body
'begin ' e1 'end.' e(' ')9 = <processBody /1/ e1> '};\n'
( e1 ) = <processBody /1/ e1> '};\n\n'
e1 = <br /error/ '=' (<printm 'error = cannot recognize program body'>)>
processBody
s(N)w e(' ')9 'cs ' e2 'of' ( e3 ) 'endcs;' e4 = <white sw> <switch sw (e2) e3> <processBody sw e4>
s(N)w e(' ')9 ( v8 ) e2 = <white sw> '{\n' <processBody <p1 sw> v8> <white sw> '}\n' <processBody sw e2>
s(N)w e(' ')9 'for ' e1 'do ' e2 = <white sw> <operator 'for ' e1 'do ' > <processBody sw <white /1/> e2>
s(N)w e(' ')9 'rpt' ( e1 ) 'untl ' e2 ';' e3 = <white sw> 'do\n' <processBody <p1 sw> e1> <white sw> 'while ( ! ('<expression e2>'));\n' <processBody sw e3>
s(N)w e(' ')9 'iff ' e1 'then '(e2) e3 = <white sw> <operator 'if ' e1 'then'> <processBody sw <white /1/> e2> <processBody sw e3>
s(N)w e(' ')9 'if ' e1 'then ' e2 = <white sw> <operator 'if ' e1 'then'> <processBody sw <white /1/> e2>
s(N)w e(' ')9 'while ' e1 'do ' e2 = <white sw> <operator 'while ' e1 'do'> <processBody <printm sw <white /1/> e2>>
s(N)w e(' ')9 'els ' e1 = <white sw> 'else \n' <processBody sw <white /1/> e1>
s(N)w e(' ')9 'else ' e1 = <white sw> 'else \n' <processBody sw <white /1/> e1>
s(N)w ' ' s((' '))0 e1 ';' e2 = <white <p1 sw>> <operator <unspace s0 e1>> <processBody sw e2>
s(N)w e1 ';' e2 = <white sw> <operator <unspace <printm e1>>> <processBody sw e2>
s(N)w e(' ')1 =
s(N)w '\n' =
s(N)w e1 = <br /error/ '=' (<printm 'error - unexpected operator or sequence"'>)>
white
/0/ =
s(N)a = ' '<white <m1 sa>>
switch
s(N)w (e2) e3 = 'switch(' <unspace e2> ')\n' <white sw> '{\n' <switchList <p1 sw> e3 (<cp 'var'<unspace e2>>)> <white sw> '}\n'
switchList
s(N)w e1 ':' e(' ')9 ( e2 ) sa e3 (e4) = <white sw> 'case ' <eql e1 (e4)> ': { \n' <processBody <p1 sw> e2> <white sw> '}\n' <switchList sw e3 (e4)>
s(N)w e1 ':' e(' ')9 e2 ';' e3 (e4) = <white sw> 'case ' <eql e1 (e4)> ' : ' <processBody /0/ e2 ';\n'> <switchList sw e3 (e4)>
s(N)w e1 (e4) = <unspace e1>
eq
/0/ e1 (e1) =
/0/ e1 (e2) = /error/
e1 (e2) = <eq /0/ <unspace e1> (<unspace e2>)>
e1 = <br /error/ '=' (<printm 'error - system error "eq"'>)>
eql
e1 (e2) = <unspace e1> <eq <typeConst <unspace e1>> (<unspace e2>)>
e1 = <br /error/ '=' (<printm 'error - system error "eql"'>)>
operator
'for ' e1 ':=' e2 'downto ' e3 'do ' = <for <unspace e1> (<unspace e2>) <unspace e3>>
'for ' e1 ':=' e2 'to ' e3 'do ' = <for ( <unspace e1> ) <unspace e2> (<unspace e3>)>
'if ' e1 'then' = 'if (' <expression e1> ')\n'
'while ' e1 'do' = 'while (' <expression e1> ')\n'
e1 ':=' e2 = <assignment ( <unspace e1> ) <unspace e2>> ';\n'
'write' e(' ')8 '(' e1 ')' = <print <unspace e1>> ';\n'
'writeln' e(' ')8 '(' e1 ')' = <print <unspace e1>> ';\n'
v1 '(' e2 ')' = <procCall v1 (e2)>
e1 = <br /error/ '=' (<printm 'error - "unrecognized operator - ' e1>)>
procCall
e1 (e2) = <checkProc e1> '('<procList e2 (<cp 'proc'e1>)> ');\n'
checkProc
e1 = <checkname (<cp 'proc'<unspace e1>>) e1>
procList
e1 ',' e2 (e3 ',' e4) = <checkPair <unspace e1> (e3)> ', ' <procList e2 (e4)>
e1 ',' e2 (e3) = /error/ (<printm 'error - parameters count mismatch'>)
e1 (e2 ',' e3) = /error/ (<printm 'error - parameters count mismatch'>)
e1 (e2) = <checkPair <unspace e1> (e2)>
checkPair
() e1 (e2) = e1
(v0) e1 (e2) = <isBad (<eq <getType e1>'*' (e2)>) '&'<isName e1> (e1) (e2)>
e1 (e2) = <checkPair (<eq <getType e1> (e2)>) e1 (e2)>
isName
() e1 = /error/
(e1) e2 = e2
e1 = <isName (<cp 'var'<unspace e1>>) e1>
isBad
() '&'e1 (e1) (e2) = '&'e1
() '&'e1 (e2) (e3) = <prout 'pointer error' e1 ' ' e3>
(v0) e1 (e2) ('int') = <expression <unspace e2>>
(v0) e1 (e2) ('bool') = <expression <unspace e2>>
e1 = <br /error/ '=' (<printm 'error - invalid argument - ' e1>)>
getType
() e1 = <typeConst /1/ e1>
(e1) e2 = e1
e1 = <getType (<cp 'var' e1>) e1 >
for
(e1) e2 (e3) = 'for('<name e1> ' = ' <expression e2> '; ' e1 ' < ' <expression e3> '; ' e1 '++)\n'
e1 (e2) e3 = 'for('<name e1> ' = ' <expression e2> '; ' e1 ' > ' <expression e3> '; ' e1 '--)\n'
name
e1 = <checkName /1/ (<cp 'var' <unspace e1>>) <unspace e1>>
assignment
(e1) e2 = <better <softName <name <unspace e1>> (<unspace e1>)> <expression e2>>
e1 = <br /error/ '=' (<printm 'error - assignment - ' e1>)>
softName
e1 (e1) = e1 ' = '
e2 (e1) = <isReturn e1 (<cp 'status'>)>
better
e1 ' = ' e1 ' + 1' = e1 '++'
e1 ' = ' e1 ' - 1' = e1 '--'
e1 ' = ' e1 ' + ' e2 = e1 ' += ' e2
e1 ' = ' e1 ' - ' e2 = e1 ' -= ' e2
e1 = e1
isReturn
e1 (e1) = 'return '
e1 (e2) = <br /error/ '=' (<printm 'error - assignment error' e1 ' ' e2>)>
expression
e1 = <expr<deBrace e1>>
deBrace
e1 ')' e2 = <deBrace <Brace e1 ')'> e2>
e1 = e1
Brace
e1 '(' e2 ')' = e1 (e2)
e1 = <br /error/ '=' (<printm 'error - unmatching braces in expression - ' e1>)>
expr
e(' ')9 'not' e(' ')8 (e1) = <factor 'not' (e1)>
e(' ')9 s(L)1 v(LD)2 ( e3 ) = <funCall <unspace s1 v2> (<unspace e3>)>
e1 s('><')a s('><=')b e2 = <simpleExpr <unspace e1>> ' ' sa sb ' ' <simpleExpr <unspace e2>>
e1 s('><')a e2 = <simpleExpr <unspace e1>> ' ' sa ' ' <simpleExpr <unspace e2>>
e1 '=' e2 = <simpleExpr <unspace e1>> ' == ' <simpleExpr <unspace e2>>
e1 = <simpleExpr <unspace e1>>
funCall
e1 (e2) = <checkFunc e1> '('<funcList e2 (<cp 'func'e1>)> ')'
checkFunc
e1 = <checkname (<cp 'func' e1>) e1>
funcList
e1 (e2 ',' e3) = <procList e1 (e3)>
simpleExpr
e1 '+' e2 = <summand e1> ' + ' <simpleExpr e2>
e1 '-' e2 = <summand e1> ' - ' <simpleExpr e2>
e1 = <summand e1>
summand
e1 '*' e2 = <factor e1> ' * ' <summand e2>
e1 'div' e2 = <factor e1> ' / ' <summand e2>
e1 'mod' e2 = <factor e1> ' % ' <summand e2>
e1 'and' e2 = <factor e1> ' && ' <summand e2>
e1 = <factor e1>
factor
e(' ')0 v(D)1 = v1
e(' ')0 ( e1 ) e(' ')9 = '(' <expression e1> ')'
e(' ')0 'not' e1 = '!' <factor e1>
e1 = <nameOrConst e1>
nameOrConst
e(' ')0 v(D)1 e(' ')9 = v1
e(' ')0 'true' e(' ')9 = 'True'
e(' ')0 'false' e(' ')9 = 'False'
e1 = <checkName /0/ (<cp 'var' <unspace e1>>) e1>
checkName
/0/ (v1 '*') e2 = '*'<unspace e2>
/0/ (v1) e2 = <unspace e2>
/0/ () e1 = /error/ (<printm 'error - name error - ' e1>)
/1/ (v1 '*') e2 = '*'<unspace e2>
/1/ (v1) e2 = <unspace e2>
/1/ () e1 = /error/
(v1) e2 = <unspace e2>
() e1 = <br /error/ '=' (<printm 'error - name error - ' e1>)>
print
e1 = 'printf("' <printTypesList e1> '"' <printVarList e1> ')'
print1
e1 = 'printf("' <printTypesList e1> '\n"' <printVarList e1> ')'
printTypesList
e1 ', ' e2 = <what e1> ', ' <printTypesList e2>
e1 = <what e1>
what
v(D)1 = v1
'"' v1 '"' = v1
e1 = <typeID<typeToPrint <cp 'var'e1>>>
typeToPrint
v1 = v1
= 'int'
printVarList
R e1 ', ' e2 = <printVarList e1> <isExpr e2>
e1 = <isExpr e1>
isExpr
v(D)1 =
'"' v1 '"' =
''' v1 ''' =
v1 = ',' <expression v1>
e1 = e1
typeID
'const ' e1 = <typeID e1>
'int' = '%d'
'double' = '%f'
'float' = '%f'
'char*' = '%s'
reNameType
' ' e1 = <reNameType e1>
'integer' = 'int'
'boolean' = 'bool'
'shortint' = 'short'
'longint' = 'long'
'real' = 'float'
'single' = 'float'
'double' = 'double'
e1 = <br /error/ '=' (<printm 'error - type error -' e1>)>
unspace
' ' e1 = <unspace e1>
e1 ' ' = <unspace e1>
e1 = e1
out
e1 () = <libput e1> <null <dgall>>
e1 (e2) = <prout '\n\n\nprogram incorrect \n\n\n' e1>
null
e1 =