├── 01_源代码阅读
├── README.txt
└── 源代码阅读.doc
├── 02_文法解读文档
├── README.txt
├── 文法解读.docx
├── 示例程序t.txt
└── 示例程序运行结果.txt
├── 03_词法分析程序
├── README.txt
├── test.txt
├── test.txt_result.txt
├── 词法分析程序源码
│ ├── GrammarAnalyzer.cpp
│ ├── GrammarAnalyzer.h
│ ├── LexicalAnalyzer.cpp
│ ├── LexicalAnalyzer.h
│ └── main.cpp
└── 词法分析结果.docx
├── 04_设计文档
├── README.txt
├── 四元式.xlsx
└── 设计文档.docx
├── 05_语法分析程序
├── README.txt
├── result.txt
├── test.txt
└── 语法分析程序源码
│ ├── ErrorHandler.cpp
│ ├── ErrorHandler.h
│ ├── GrammarAnalyzer.cpp
│ ├── GrammarAnalyzer.h
│ ├── LexicalAnalyzer.cpp
│ ├── LexicalAnalyzer.h
│ ├── SymbolTableManager.cpp
│ ├── SymbolTableManager.h
│ ├── main.cpp
│ ├── test.cpp
│ └── type.h
├── 06_代码生成程序
├── README.txt
├── test.txt
├── 代码生成程序源码
│ ├── ErrorHandler.cpp
│ ├── ErrorHandler.h
│ ├── GrammarAnalyzer.cpp
│ ├── GrammarAnalyzer.h
│ ├── LexicalAnalyzer.cpp
│ ├── LexicalAnalyzer.h
│ ├── Quadruples.cpp
│ ├── Quadruples.h
│ ├── SemanticAnalyzer.cpp
│ ├── SemanticAnalyzer.h
│ ├── SymbolTableManager.cpp
│ ├── SymbolTableManager.h
│ ├── TargetCodeGenerator.h
│ ├── main.cpp
│ ├── test.cpp
│ └── type.h
└── 测试结果说明.docx
├── 07_目标代码生成
├── README.txt
├── assemble.asm
├── test.txt
└── 目标代码生成程序源码
│ ├── ErrorHandler.cpp
│ ├── ErrorHandler.h
│ ├── GrammarAnalyzer.cpp
│ ├── GrammarAnalyzer.h
│ ├── LexicalAnalyzer.cpp
│ ├── LexicalAnalyzer.h
│ ├── Quadruples.cpp
│ ├── Quadruples.h
│ ├── RegisterPool.cpp
│ ├── RegisterPool.h
│ ├── SemanticAnalyzer.cpp
│ ├── SemanticAnalyzer.h
│ ├── StackManager.cpp
│ ├── StackManager.h
│ ├── SymbolTableManager.cpp
│ ├── SymbolTableManager.h
│ ├── TargetCodeGenerator.cpp
│ ├── TargetCodeGenerator.h
│ ├── main.cpp
│ ├── type.h
│ └── x86_instruction.h
├── 08_最终结果
├── README.txt
├── 文档
│ ├── 编译课设文档.docx
│ └── 编译课设申优文档.docx
├── 测试程序
│ ├── 测试程序.txt
│ ├── 目标代码运行结果.txt
│ └── 编译结果.asm
└── 源代码
│ ├── ErrorHandler.cpp
│ ├── ErrorHandler.h
│ ├── GrammarAnalyzer.cpp
│ ├── GrammarAnalyzer.h
│ ├── LexicalAnalyzer.cpp
│ ├── LexicalAnalyzer.h
│ ├── Quadruples.cpp
│ ├── Quadruples.h
│ ├── RegisterPool.cpp
│ ├── RegisterPool.h
│ ├── SemanticAnalyzer.cpp
│ ├── SemanticAnalyzer.h
│ ├── StackManager.cpp
│ ├── StackManager.h
│ ├── SymbolTableManager.cpp
│ ├── SymbolTableManager.h
│ ├── TargetCodeGenerator.cpp
│ ├── TargetCodeGenerator.h
│ ├── main.cpp
│ ├── type.h
│ └── x86_instruction.h
├── LICENSE
├── README.md
├── 扩充PL_0文法.txt
└── 测试程序.txt
/01_源代码阅读/README.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/01_源代码阅读/README.txt
--------------------------------------------------------------------------------
/01_源代码阅读/源代码阅读.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/01_源代码阅读/源代码阅读.doc
--------------------------------------------------------------------------------
/02_文法解读文档/README.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/02_文法解读文档/README.txt
--------------------------------------------------------------------------------
/02_文法解读文档/文法解读.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/02_文法解读文档/文法解读.docx
--------------------------------------------------------------------------------
/02_文法解读文档/示例程序t.txt:
--------------------------------------------------------------------------------
1 | const TEN = 0010,
2 | NINE = +9,
3 | EIGHT1 = -8,
4 | A = 'A',
5 | ZERO = '0';
6 | var int1, int2: integer;
7 | ch1, ch2: char;
8 | intArray: array[3] of integer;
9 | chArray: array[1] of char;
10 | procedure proc1;
11 | begin
12 | write("proc1 start...");
13 | int1 := -(TEN + NINE) * EIGHT1 + 1024;
14 | ch1 := A;
15 | ch2 := ZERO;
16 | write("int1: ", int1);
17 | write("ch1: ", ch1);
18 | write("ch2: ", ch2);
19 | write("chArray:");
20 | for int2 := 0 downto 0 do
21 | begin
22 | chArray[int2] := ZERO;
23 | write(chArray[int2]);
24 | end;
25 | write("intArray:");
26 | for int2 := 0 to 2 do
27 | begin
28 | intArray[int2] := int2;
29 | write(intArray[int2])
30 | end;
31 | begin
32 | write("proc1 end.");
33 | end
34 | end;
35 | function func1(num: integer): integer;
36 | var steps: integer;
37 | procedure mov(tstart, tend, tmid, num: integer; var count: integer);
38 | begin
39 | if num > 0
40 | begin
41 | mov(tstart, tmid, tend, num-1, count);
42 | count := count + 1;
43 | write("step ", count);
44 | write("from: ", tstart);
45 | write("to: ", tend);
46 | mov(tmid, tend, tstart, num-1, count);
47 | end
48 | end;
49 | begin
50 | write("func1 start...");
51 | write("argument is num: integer");
52 | write(num);
53 | write("Hanoi Tower with levels: ", num);
54 | steps := 0;
55 | steps := mov(1, 3, 2, num, steps);
56 | write("The total number of steps is: ", steps);
57 | write("func1 end with: ", steps);
58 | func1 := steps;
59 | end;
60 | function func2: char;
61 | begin
62 | write("func2 start...");
63 | write("Please input ch1, ch2, int1...");
64 | read(ch1, ch2);
65 | read(int1);
66 | if ch1 <= ch2 then
67 | if ch1 < ch2 then
68 | if int1 = 0 then
69 | write("<=")
70 | else
71 | write("<")
72 | else if int1 >= 0 then
73 | if int1 > 0 then
74 | write("<>")
75 | else
76 | write("=")
77 | else
78 | write("<>")
79 | else
80 | if int1 <> 0 then
81 | write(">")
82 | else
83 | write(">=");
84 | write("func2 end with: ", ZERO);
85 | func2 := ZERO;
86 | end;
87 | procedure proc2(int1, int2: integer; var int3: integer);
88 | begin
89 | write("proc2 start...");
90 | write("arguments are int1, int2: integer; var int3: integer");
91 | write(int1);
92 | write(int2);
93 | write(int3);
94 | int3 := 0;
95 | do
96 | begin
97 | int3 := int3 + int2;
98 | int1 := int1 + 1;
99 | end
100 | while int1 < int2;
101 | write("int3 now is :", int3);
102 | write("proc2 end.");
103 | end;
104 | begin
105 | proc1;
106 | proc2(int1, int2, intArray[3 * 3 - 2 * 5 + 1]);
107 | int1 := func1(4);
108 | ch1 := func2;
109 | end.
--------------------------------------------------------------------------------
/02_文法解读文档/示例程序运行结果.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/02_文法解读文档/示例程序运行结果.txt
--------------------------------------------------------------------------------
/03_词法分析程序/README.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/03_词法分析程序/README.txt
--------------------------------------------------------------------------------
/03_词法分析程序/test.txt:
--------------------------------------------------------------------------------
1 | const TEN = 0010,
2 | NINE = +9,
3 | EIGHT1 = -8,
4 | A = 'A',
5 | ZERO = '0';
6 | var int1, int2: integer;
7 | ch1, ch2: char;
8 | intArray: array[3] of integer;
9 | chArray: array[1] of char;
10 | procedure proc1;
11 | begin
12 | write("proc1 start...");
13 | int1 := -(TEN + NINE) * EIGHT1 + 1024;
14 | ch1 := A;
15 | ch2 := ZERO;
16 | write("int1: ", int1);
17 | write("ch1: ", ch1);
18 | write("ch2: ", ch2);
19 | write("chArray:");
20 | for int2 := 0 downto 0 do
21 | begin
22 | chArray[int2] := ZERO;
23 | write(chArray[int2]);
24 | end;
25 | write("intArray:");
26 | for int2 := 0 to 2 do
27 | begin
28 | intArray[int2] := int2;
29 | write(intArray[int2])
30 | end;
31 | begin
32 | write("proc1 end.");
33 | end
34 | end;
35 | function func1(num: integer): integer;
36 | var steps: integer;
37 | procedure mov(tstart, tend, tmid, num: integer; var count: integer);
38 | begin
39 | if num > 0
40 | begin
41 | mov(tstart, tmid, tend, num-1, count);
42 | count := count + 1;
43 | write("step ", count);
44 | write("from: ", tstart);
45 | write("to: ", tend);
46 | mov(tmid, tend, tstart, num-1, count);
47 | end
48 | end;
49 | begin
50 | write("func1 start...");
51 | write("argument is num: integer");
52 | write(num);
53 | write("Hanoi Tower with levels: ", num);
54 | steps := 0;
55 | steps := mov(1, 3, 2, num, steps);
56 | write("The total number of steps is: ", steps);
57 | write("func1 end with: ", steps);
58 | func1 := steps;
59 | end;
60 | function func2: char;
61 | begin
62 | write("func2 start...");
63 | write("Please input ch1, ch2, int1...");
64 | read(ch1, ch2);
65 | read(int1);
66 | if ch1 <= ch2 then
67 | if ch1 < ch2 then
68 | if int1 = 0 then
69 | write("<=")
70 | else
71 | write("<")
72 | else if int1 >= 0 then
73 | if int1 > 0 then
74 | write("<>")
75 | else
76 | write("=")
77 | else
78 | write("<>")
79 | else
80 | if int1 <> 0 then
81 | write(">")
82 | else
83 | write(">=");
84 | write("func2 end with: ", ZERO);
85 | func2 := ZERO;
86 | end;
87 | procedure proc2(int1, int2: integer; var int3: integer);
88 | begin
89 | write("proc2 start...");
90 | write("arguments are int1, int2: integer; var int3: integer");
91 | write(int1);
92 | write(int2);
93 | write(int3);
94 | int3 := 0;
95 | do
96 | begin
97 | int3 := int3 + int2;
98 | int1 := int1 + 1;
99 | end
100 | while int1 < int2;
101 | write("int3 now is :", int3);
102 | write("proc2 end.");
103 | end;
104 | begin
105 | proc1;
106 | proc2(int1, int2, intArray[3 * 3 - 2 * 5 + 1]);
107 | int1 := func1(4);
108 | ch1 := func2;
109 | end.
--------------------------------------------------------------------------------
/03_词法分析程序/test.txt_result.txt:
--------------------------------------------------------------------------------
1 | 1 CONST const
2 | 2 IDENTIFIER TEN
3 | 3 EQUAL =
4 | 4 NUMBER 10
5 | 5 COMMA ,
6 | 6 IDENTIFIER NINE
7 | 7 EQUAL =
8 | 8 PLUS +
9 | 9 NUMBER 9
10 | 10 COMMA ,
11 | 11 IDENTIFIER EIGHT1
12 | 12 EQUAL =
13 | 13 MINUS -
14 | 14 NUMBER 8
15 | 15 COMMA ,
16 | 16 IDENTIFIER A
17 | 17 EQUAL =
18 | 18 SINGLE_QUOTE '
19 | 19 CHARATER A
20 | 20 SINGLE_QUOTE '
21 | 21 COMMA ,
22 | 22 IDENTIFIER ZERO
23 | 23 EQUAL =
24 | 24 SINGLE_QUOTE '
25 | 25 CHARATER 0
26 | 26 SINGLE_QUOTE '
27 | 27 SEMICOLON ;
28 | 28 VAR var
29 | 29 IDENTIFIER int1
30 | 30 COMMA ,
31 | 31 IDENTIFIER int2
32 | 32 COLON :
33 | 33 INTEGER integer
34 | 34 SEMICOLON ;
35 | 35 IDENTIFIER ch1
36 | 36 COMMA ,
37 | 37 IDENTIFIER ch2
38 | 38 COLON :
39 | 39 CHAR char
40 | 40 SEMICOLON ;
41 | 41 IDENTIFIER intArray
42 | 42 COLON :
43 | 43 ARRAY array
44 | 44 LEFT_SQUARE [
45 | 45 NUMBER 3
46 | 46 RIGHT_SQUARE ]
47 | 47 OF of
48 | 48 INTEGER integer
49 | 49 SEMICOLON ;
50 | 50 IDENTIFIER chArray
51 | 51 COLON :
52 | 52 ARRAY array
53 | 53 LEFT_SQUARE [
54 | 54 NUMBER 1
55 | 55 RIGHT_SQUARE ]
56 | 56 OF of
57 | 57 CHAR char
58 | 58 SEMICOLON ;
59 | 59 PROCEDURE procedure
60 | 60 IDENTIFIER proc1
61 | 61 SEMICOLON ;
62 | 62 BEGIN begin
63 | 63 WRITE write
64 | 64 LEFT_BRACKET (
65 | 65 DOUBLE_QUOTE "
66 | 66 STRING proc1 start...
67 | 67 DOUBLE_QUOTE "
68 | 68 RIGHT_BRACKET )
69 | 69 SEMICOLON ;
70 | 70 IDENTIFIER int1
71 | 71 ASSIGN :=
72 | 72 MINUS -
73 | 73 LEFT_BRACKET (
74 | 74 IDENTIFIER TEN
75 | 75 PLUS +
76 | 76 IDENTIFIER NINE
77 | 77 RIGHT_BRACKET )
78 | 78 ASTERISK *
79 | 79 IDENTIFIER EIGHT1
80 | 80 PLUS +
81 | 81 NUMBER 1024
82 | 82 SEMICOLON ;
83 | 83 IDENTIFIER ch1
84 | 84 ASSIGN :=
85 | 85 IDENTIFIER A
86 | 86 SEMICOLON ;
87 | 87 IDENTIFIER ch2
88 | 88 ASSIGN :=
89 | 89 IDENTIFIER ZERO
90 | 90 SEMICOLON ;
91 | 91 WRITE write
92 | 92 LEFT_BRACKET (
93 | 93 DOUBLE_QUOTE "
94 | 94 STRING int1:
95 | 95 DOUBLE_QUOTE "
96 | 96 COMMA ,
97 | 97 IDENTIFIER int1
98 | 98 RIGHT_BRACKET )
99 | 99 SEMICOLON ;
100 | 100 WRITE write
101 | 101 LEFT_BRACKET (
102 | 102 DOUBLE_QUOTE "
103 | 103 STRING ch1:
104 | 104 DOUBLE_QUOTE "
105 | 105 COMMA ,
106 | 106 IDENTIFIER ch1
107 | 107 RIGHT_BRACKET )
108 | 108 SEMICOLON ;
109 | 109 WRITE write
110 | 110 LEFT_BRACKET (
111 | 111 DOUBLE_QUOTE "
112 | 112 STRING ch2:
113 | 113 DOUBLE_QUOTE "
114 | 114 COMMA ,
115 | 115 IDENTIFIER ch2
116 | 116 RIGHT_BRACKET )
117 | 117 SEMICOLON ;
118 | 118 WRITE write
119 | 119 LEFT_BRACKET (
120 | 120 DOUBLE_QUOTE "
121 | 121 STRING chArray:
122 | 122 DOUBLE_QUOTE "
123 | 123 RIGHT_BRACKET )
124 | 124 SEMICOLON ;
125 | 125 FOR for
126 | 126 IDENTIFIER int2
127 | 127 ASSIGN :=
128 | 128 NUMBER 0
129 | 129 IDENTIFIER downto
130 | 130 NUMBER 0
131 | 131 DO do
132 | 132 BEGIN begin
133 | 133 IDENTIFIER chArray
134 | 134 LEFT_SQUARE [
135 | 135 IDENTIFIER int2
136 | 136 RIGHT_SQUARE ]
137 | 137 ASSIGN :=
138 | 138 IDENTIFIER ZERO
139 | 139 SEMICOLON ;
140 | 140 WRITE write
141 | 141 LEFT_BRACKET (
142 | 142 IDENTIFIER chArray
143 | 143 LEFT_SQUARE [
144 | 144 IDENTIFIER int2
145 | 145 RIGHT_SQUARE ]
146 | 146 RIGHT_BRACKET )
147 | 147 SEMICOLON ;
148 | 148 END end
149 | 149 SEMICOLON ;
150 | 150 WRITE write
151 | 151 LEFT_BRACKET (
152 | 152 DOUBLE_QUOTE "
153 | 153 STRING intArray:
154 | 154 DOUBLE_QUOTE "
155 | 155 RIGHT_BRACKET )
156 | 156 SEMICOLON ;
157 | 157 FOR for
158 | 158 IDENTIFIER int2
159 | 159 ASSIGN :=
160 | 160 NUMBER 0
161 | 161 IDENTIFIER to
162 | 162 NUMBER 2
163 | 163 DO do
164 | 164 BEGIN begin
165 | 165 IDENTIFIER intArray
166 | 166 LEFT_SQUARE [
167 | 167 IDENTIFIER int2
168 | 168 RIGHT_SQUARE ]
169 | 169 ASSIGN :=
170 | 170 IDENTIFIER int2
171 | 171 SEMICOLON ;
172 | 172 WRITE write
173 | 173 LEFT_BRACKET (
174 | 174 IDENTIFIER intArray
175 | 175 LEFT_SQUARE [
176 | 176 IDENTIFIER int2
177 | 177 RIGHT_SQUARE ]
178 | 178 RIGHT_BRACKET )
179 | 179 END end
180 | 180 SEMICOLON ;
181 | 181 BEGIN begin
182 | 182 WRITE write
183 | 183 LEFT_BRACKET (
184 | 184 DOUBLE_QUOTE "
185 | 185 STRING proc1 end.
186 | 186 DOUBLE_QUOTE "
187 | 187 RIGHT_BRACKET )
188 | 188 SEMICOLON ;
189 | 189 END end
190 | 190 END end
191 | 191 SEMICOLON ;
192 | 192 FUNCTION function
193 | 193 IDENTIFIER func1
194 | 194 LEFT_BRACKET (
195 | 195 IDENTIFIER num
196 | 196 COLON :
197 | 197 INTEGER integer
198 | 198 RIGHT_BRACKET )
199 | 199 COLON :
200 | 200 INTEGER integer
201 | 201 SEMICOLON ;
202 | 202 VAR var
203 | 203 IDENTIFIER steps
204 | 204 COLON :
205 | 205 INTEGER integer
206 | 206 SEMICOLON ;
207 | 207 PROCEDURE procedure
208 | 208 IDENTIFIER mov
209 | 209 LEFT_BRACKET (
210 | 210 IDENTIFIER tstart
211 | 211 COMMA ,
212 | 212 IDENTIFIER tend
213 | 213 COMMA ,
214 | 214 IDENTIFIER tmid
215 | 215 COMMA ,
216 | 216 IDENTIFIER num
217 | 217 COLON :
218 | 218 INTEGER integer
219 | 219 SEMICOLON ;
220 | 220 VAR var
221 | 221 IDENTIFIER count
222 | 222 COLON :
223 | 223 INTEGER integer
224 | 224 RIGHT_BRACKET )
225 | 225 SEMICOLON ;
226 | 226 BEGIN begin
227 | 227 IF if
228 | 228 IDENTIFIER num
229 | 229 GREATER >
230 | 230 NUMBER 0
231 | 231 BEGIN begin
232 | 232 IDENTIFIER mov
233 | 233 LEFT_BRACKET (
234 | 234 IDENTIFIER tstart
235 | 235 COMMA ,
236 | 236 IDENTIFIER tmid
237 | 237 COMMA ,
238 | 238 IDENTIFIER tend
239 | 239 COMMA ,
240 | 240 IDENTIFIER num
241 | 241 MINUS -
242 | 242 NUMBER 1
243 | 243 COMMA ,
244 | 244 IDENTIFIER count
245 | 245 RIGHT_BRACKET )
246 | 246 SEMICOLON ;
247 | 247 IDENTIFIER count
248 | 248 ASSIGN :=
249 | 249 IDENTIFIER count
250 | 250 PLUS +
251 | 251 NUMBER 1
252 | 252 SEMICOLON ;
253 | 253 WRITE write
254 | 254 LEFT_BRACKET (
255 | 255 DOUBLE_QUOTE "
256 | 256 STRING step
257 | 257 DOUBLE_QUOTE "
258 | 258 COMMA ,
259 | 259 IDENTIFIER count
260 | 260 RIGHT_BRACKET )
261 | 261 SEMICOLON ;
262 | 262 WRITE write
263 | 263 LEFT_BRACKET (
264 | 264 DOUBLE_QUOTE "
265 | 265 STRING from:
266 | 266 DOUBLE_QUOTE "
267 | 267 COMMA ,
268 | 268 IDENTIFIER tstart
269 | 269 RIGHT_BRACKET )
270 | 270 SEMICOLON ;
271 | 271 WRITE write
272 | 272 LEFT_BRACKET (
273 | 273 DOUBLE_QUOTE "
274 | 274 STRING to:
275 | 275 DOUBLE_QUOTE "
276 | 276 COMMA ,
277 | 277 IDENTIFIER tend
278 | 278 RIGHT_BRACKET )
279 | 279 SEMICOLON ;
280 | 280 IDENTIFIER mov
281 | 281 LEFT_BRACKET (
282 | 282 IDENTIFIER tmid
283 | 283 COMMA ,
284 | 284 IDENTIFIER tend
285 | 285 COMMA ,
286 | 286 IDENTIFIER tstart
287 | 287 COMMA ,
288 | 288 IDENTIFIER num
289 | 289 MINUS -
290 | 290 NUMBER 1
291 | 291 COMMA ,
292 | 292 IDENTIFIER count
293 | 293 RIGHT_BRACKET )
294 | 294 SEMICOLON ;
295 | 295 END end
296 | 296 END end
297 | 297 SEMICOLON ;
298 | 298 BEGIN begin
299 | 299 WRITE write
300 | 300 LEFT_BRACKET (
301 | 301 DOUBLE_QUOTE "
302 | 302 STRING func1 start...
303 | 303 DOUBLE_QUOTE "
304 | 304 RIGHT_BRACKET )
305 | 305 SEMICOLON ;
306 | 306 WRITE write
307 | 307 LEFT_BRACKET (
308 | 308 DOUBLE_QUOTE "
309 | 309 STRING argument is num: integer
310 | 310 DOUBLE_QUOTE "
311 | 311 RIGHT_BRACKET )
312 | 312 SEMICOLON ;
313 | 313 WRITE write
314 | 314 LEFT_BRACKET (
315 | 315 IDENTIFIER num
316 | 316 RIGHT_BRACKET )
317 | 317 SEMICOLON ;
318 | 318 WRITE write
319 | 319 LEFT_BRACKET (
320 | 320 DOUBLE_QUOTE "
321 | 321 STRING Hanoi Tower with levels:
322 | 322 DOUBLE_QUOTE "
323 | 323 COMMA ,
324 | 324 IDENTIFIER num
325 | 325 RIGHT_BRACKET )
326 | 326 SEMICOLON ;
327 | 327 IDENTIFIER steps
328 | 328 ASSIGN :=
329 | 329 NUMBER 0
330 | 330 SEMICOLON ;
331 | 331 IDENTIFIER steps
332 | 332 ASSIGN :=
333 | 333 IDENTIFIER mov
334 | 334 LEFT_BRACKET (
335 | 335 NUMBER 1
336 | 336 COMMA ,
337 | 337 NUMBER 3
338 | 338 COMMA ,
339 | 339 NUMBER 2
340 | 340 COMMA ,
341 | 341 IDENTIFIER num
342 | 342 COMMA ,
343 | 343 IDENTIFIER steps
344 | 344 RIGHT_BRACKET )
345 | 345 SEMICOLON ;
346 | 346 WRITE write
347 | 347 LEFT_BRACKET (
348 | 348 DOUBLE_QUOTE "
349 | 349 STRING The total number of steps is:
350 | 350 DOUBLE_QUOTE "
351 | 351 COMMA ,
352 | 352 IDENTIFIER steps
353 | 353 RIGHT_BRACKET )
354 | 354 SEMICOLON ;
355 | 355 WRITE write
356 | 356 LEFT_BRACKET (
357 | 357 DOUBLE_QUOTE "
358 | 358 STRING func1 end with:
359 | 359 DOUBLE_QUOTE "
360 | 360 COMMA ,
361 | 361 IDENTIFIER steps
362 | 362 RIGHT_BRACKET )
363 | 363 SEMICOLON ;
364 | 364 IDENTIFIER func1
365 | 365 ASSIGN :=
366 | 366 IDENTIFIER steps
367 | 367 SEMICOLON ;
368 | 368 END end
369 | 369 SEMICOLON ;
370 | 370 FUNCTION function
371 | 371 IDENTIFIER func2
372 | 372 COLON :
373 | 373 CHAR char
374 | 374 SEMICOLON ;
375 | 375 BEGIN begin
376 | 376 WRITE write
377 | 377 LEFT_BRACKET (
378 | 378 DOUBLE_QUOTE "
379 | 379 STRING func2 start...
380 | 380 DOUBLE_QUOTE "
381 | 381 RIGHT_BRACKET )
382 | 382 SEMICOLON ;
383 | 383 WRITE write
384 | 384 LEFT_BRACKET (
385 | 385 DOUBLE_QUOTE "
386 | 386 STRING Please input ch1, ch2, int1...
387 | 387 DOUBLE_QUOTE "
388 | 388 RIGHT_BRACKET )
389 | 389 SEMICOLON ;
390 | 390 READ read
391 | 391 LEFT_BRACKET (
392 | 392 IDENTIFIER ch1
393 | 393 COMMA ,
394 | 394 IDENTIFIER ch2
395 | 395 RIGHT_BRACKET )
396 | 396 SEMICOLON ;
397 | 397 READ read
398 | 398 LEFT_BRACKET (
399 | 399 IDENTIFIER int1
400 | 400 RIGHT_BRACKET )
401 | 401 SEMICOLON ;
402 | 402 IF if
403 | 403 IDENTIFIER ch1
404 | 404 LESS_EQUAL <=
405 | 405 IDENTIFIER ch2
406 | 406 THEN then
407 | 407 IF if
408 | 408 IDENTIFIER ch1
409 | 409 LESS <
410 | 410 IDENTIFIER ch2
411 | 411 THEN then
412 | 412 IF if
413 | 413 IDENTIFIER int1
414 | 414 EQUAL =
415 | 415 NUMBER 0
416 | 416 THEN then
417 | 417 WRITE write
418 | 418 LEFT_BRACKET (
419 | 419 DOUBLE_QUOTE "
420 | 420 STRING <=
421 | 421 DOUBLE_QUOTE "
422 | 422 RIGHT_BRACKET )
423 | 423 ELSE else
424 | 424 WRITE write
425 | 425 LEFT_BRACKET (
426 | 426 DOUBLE_QUOTE "
427 | 427 STRING <
428 | 428 DOUBLE_QUOTE "
429 | 429 RIGHT_BRACKET )
430 | 430 ELSE else
431 | 431 IF if
432 | 432 IDENTIFIER int1
433 | 433 GREATER_EQUAL >=
434 | 434 NUMBER 0
435 | 435 THEN then
436 | 436 IF if
437 | 437 IDENTIFIER int1
438 | 438 GREATER >
439 | 439 NUMBER 0
440 | 440 THEN then
441 | 441 WRITE write
442 | 442 LEFT_BRACKET (
443 | 443 DOUBLE_QUOTE "
444 | 444 STRING <>
445 | 445 DOUBLE_QUOTE "
446 | 446 RIGHT_BRACKET )
447 | 447 ELSE else
448 | 448 WRITE write
449 | 449 LEFT_BRACKET (
450 | 450 DOUBLE_QUOTE "
451 | 451 STRING =
452 | 452 DOUBLE_QUOTE "
453 | 453 RIGHT_BRACKET )
454 | 454 ELSE else
455 | 455 WRITE write
456 | 456 LEFT_BRACKET (
457 | 457 DOUBLE_QUOTE "
458 | 458 STRING <>
459 | 459 DOUBLE_QUOTE "
460 | 460 RIGHT_BRACKET )
461 | 461 ELSE else
462 | 462 IF if
463 | 463 IDENTIFIER int1
464 | 464 INEQUAL <>
465 | 465 NUMBER 0
466 | 466 THEN then
467 | 467 WRITE write
468 | 468 LEFT_BRACKET (
469 | 469 DOUBLE_QUOTE "
470 | 470 STRING >
471 | 471 DOUBLE_QUOTE "
472 | 472 RIGHT_BRACKET )
473 | 473 ELSE else
474 | 474 WRITE write
475 | 475 LEFT_BRACKET (
476 | 476 DOUBLE_QUOTE "
477 | 477 STRING >=
478 | 478 DOUBLE_QUOTE "
479 | 479 RIGHT_BRACKET )
480 | 480 SEMICOLON ;
481 | 481 WRITE write
482 | 482 LEFT_BRACKET (
483 | 483 DOUBLE_QUOTE "
484 | 484 STRING func2 end with:
485 | 485 DOUBLE_QUOTE "
486 | 486 COMMA ,
487 | 487 IDENTIFIER ZERO
488 | 488 RIGHT_BRACKET )
489 | 489 SEMICOLON ;
490 | 490 IDENTIFIER func2
491 | 491 ASSIGN :=
492 | 492 IDENTIFIER ZERO
493 | 493 SEMICOLON ;
494 | 494 END end
495 | 495 SEMICOLON ;
496 | 496 PROCEDURE procedure
497 | 497 IDENTIFIER proc2
498 | 498 LEFT_BRACKET (
499 | 499 IDENTIFIER int1
500 | 500 COMMA ,
501 | 501 IDENTIFIER int2
502 | 502 COLON :
503 | 503 INTEGER integer
504 | 504 SEMICOLON ;
505 | 505 VAR var
506 | 506 IDENTIFIER int3
507 | 507 COLON :
508 | 508 INTEGER integer
509 | 509 RIGHT_BRACKET )
510 | 510 SEMICOLON ;
511 | 511 BEGIN begin
512 | 512 WRITE write
513 | 513 LEFT_BRACKET (
514 | 514 DOUBLE_QUOTE "
515 | 515 STRING proc2 start...
516 | 516 DOUBLE_QUOTE "
517 | 517 RIGHT_BRACKET )
518 | 518 SEMICOLON ;
519 | 519 WRITE write
520 | 520 LEFT_BRACKET (
521 | 521 DOUBLE_QUOTE "
522 | 522 STRING arguments are int1, int2: integer; var int3: integer
523 | 523 DOUBLE_QUOTE "
524 | 524 RIGHT_BRACKET )
525 | 525 SEMICOLON ;
526 | 526 WRITE write
527 | 527 LEFT_BRACKET (
528 | 528 IDENTIFIER int1
529 | 529 RIGHT_BRACKET )
530 | 530 SEMICOLON ;
531 | 531 WRITE write
532 | 532 LEFT_BRACKET (
533 | 533 IDENTIFIER int2
534 | 534 RIGHT_BRACKET )
535 | 535 SEMICOLON ;
536 | 536 WRITE write
537 | 537 LEFT_BRACKET (
538 | 538 IDENTIFIER int3
539 | 539 RIGHT_BRACKET )
540 | 540 SEMICOLON ;
541 | 541 IDENTIFIER int3
542 | 542 ASSIGN :=
543 | 543 NUMBER 0
544 | 544 SEMICOLON ;
545 | 545 DO do
546 | 546 BEGIN begin
547 | 547 IDENTIFIER int3
548 | 548 ASSIGN :=
549 | 549 IDENTIFIER int3
550 | 550 PLUS +
551 | 551 IDENTIFIER int2
552 | 552 SEMICOLON ;
553 | 553 IDENTIFIER int1
554 | 554 ASSIGN :=
555 | 555 IDENTIFIER int1
556 | 556 PLUS +
557 | 557 NUMBER 1
558 | 558 SEMICOLON ;
559 | 559 END end
560 | 560 WHILE while
561 | 561 IDENTIFIER int1
562 | 562 LESS <
563 | 563 IDENTIFIER int2
564 | 564 SEMICOLON ;
565 | 565 WRITE write
566 | 566 LEFT_BRACKET (
567 | 567 DOUBLE_QUOTE "
568 | 568 STRING int3 now is :
569 | 569 DOUBLE_QUOTE "
570 | 570 COMMA ,
571 | 571 IDENTIFIER int3
572 | 572 RIGHT_BRACKET )
573 | 573 SEMICOLON ;
574 | 574 WRITE write
575 | 575 LEFT_BRACKET (
576 | 576 DOUBLE_QUOTE "
577 | 577 STRING proc2 end.
578 | 578 DOUBLE_QUOTE "
579 | 579 RIGHT_BRACKET )
580 | 580 SEMICOLON ;
581 | 581 END end
582 | 582 SEMICOLON ;
583 | 583 BEGIN begin
584 | 584 IDENTIFIER proc1
585 | 585 SEMICOLON ;
586 | 586 IDENTIFIER proc2
587 | 587 LEFT_BRACKET (
588 | 588 IDENTIFIER int1
589 | 589 COMMA ,
590 | 590 IDENTIFIER int2
591 | 591 COMMA ,
592 | 592 IDENTIFIER intArray
593 | 593 LEFT_SQUARE [
594 | 594 NUMBER 3
595 | 595 ASTERISK *
596 | 596 NUMBER 3
597 | 597 MINUS -
598 | 598 NUMBER 2
599 | 599 ASTERISK *
600 | 600 NUMBER 5
601 | 601 PLUS +
602 | 602 NUMBER 1
603 | 603 RIGHT_SQUARE ]
604 | 604 RIGHT_BRACKET )
605 | 605 SEMICOLON ;
606 | 606 IDENTIFIER int1
607 | 607 ASSIGN :=
608 | 608 IDENTIFIER func1
609 | 609 LEFT_BRACKET (
610 | 610 NUMBER 4
611 | 611 RIGHT_BRACKET )
612 | 612 SEMICOLON ;
613 | 613 IDENTIFIER ch1
614 | 614 ASSIGN :=
615 | 615 IDENTIFIER func2
616 | 616 SEMICOLON ;
617 | 617 END end
618 | 618 PERIOD .
619 |
--------------------------------------------------------------------------------
/03_词法分析程序/词法分析程序源码/GrammarAnalyzer.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/03_词法分析程序/词法分析程序源码/GrammarAnalyzer.cpp
--------------------------------------------------------------------------------
/03_词法分析程序/词法分析程序源码/GrammarAnalyzer.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/03_词法分析程序/词法分析程序源码/GrammarAnalyzer.h
--------------------------------------------------------------------------------
/03_词法分析程序/词法分析程序源码/LexicalAnalyzer.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/03_词法分析程序/词法分析程序源码/LexicalAnalyzer.cpp
--------------------------------------------------------------------------------
/03_词法分析程序/词法分析程序源码/LexicalAnalyzer.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/03_词法分析程序/词法分析程序源码/LexicalAnalyzer.h
--------------------------------------------------------------------------------
/03_词法分析程序/词法分析程序源码/main.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/03_词法分析程序/词法分析程序源码/main.cpp
--------------------------------------------------------------------------------
/03_词法分析程序/词法分析结果.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/03_词法分析程序/词法分析结果.docx
--------------------------------------------------------------------------------
/04_设计文档/README.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/04_设计文档/README.txt
--------------------------------------------------------------------------------
/04_设计文档/四元式.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/04_设计文档/四元式.xlsx
--------------------------------------------------------------------------------
/04_设计文档/设计文档.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/04_设计文档/设计文档.docx
--------------------------------------------------------------------------------
/05_语法分析程序/README.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/05_语法分析程序/README.txt
--------------------------------------------------------------------------------
/05_语法分析程序/result.txt:
--------------------------------------------------------------------------------
1 | This is a unsigned integer!
2 | This is a constant!
3 | This is a const defination!
4 | This is a unsigned integer!
5 | This is a constant!
6 | This is a const defination!
7 | This is a unsigned integer!
8 | This is a constant!
9 | This is a const defination!
10 | This is a charactor!
11 | This is a constant!
12 | This is a const defination!
13 | This is a charactor!
14 | This is a constant!
15 | This is a const defination!
16 | This is a const declaration section!
17 | This is a basic type!
18 | This is a type!
19 | This is a variable defination!
20 | This is a basic type!
21 | This is a type!
22 | This is a variable defination!
23 | This is a unsigned integer!
24 | This is a basic type!
25 | This is a type!
26 | This is a variable defination!
27 | This is a unsigned integer!
28 | This is a basic type!
29 | This is a type!
30 | This is a variable defination!
31 | This is a variable declaration section!
32 | This is a procedure head!
33 | This is a string!
34 | This is a write statement!
35 | This is a statement!
36 | This is a factor!
37 | This is a term!
38 | This is a factor!
39 | This is a term!
40 | This is a expression!
41 | This is a factor!
42 | This is a factor!
43 | This is a term!
44 | This is a unsigned integer!
45 | This is a factor!
46 | This is a term!
47 | This is a expression!
48 | This is a assign statement!
49 | This is a statement!
50 | This is a factor!
51 | This is a term!
52 | This is a expression!
53 | This is a assign statement!
54 | This is a statement!
55 | This is a factor!
56 | This is a term!
57 | This is a expression!
58 | This is a assign statement!
59 | This is a statement!
60 | This is a string!
61 | This is a factor!
62 | This is a term!
63 | This is a expression!
64 | This is a write statement!
65 | This is a statement!
66 | This is a string!
67 | This is a factor!
68 | This is a term!
69 | This is a expression!
70 | This is a write statement!
71 | This is a statement!
72 | This is a string!
73 | This is a factor!
74 | This is a term!
75 | This is a expression!
76 | This is a write statement!
77 | This is a statement!
78 | This is a string!
79 | This is a write statement!
80 | This is a statement!
81 | This is a unsigned integer!
82 | This is a factor!
83 | This is a term!
84 | This is a expression!
85 | This is a unsigned integer!
86 | This is a factor!
87 | This is a term!
88 | This is a expression!
89 | This is a factor!
90 | This is a term!
91 | This is a expression!
92 | This is a factor!
93 | This is a term!
94 | This is a expression!
95 | This is a assign statement!
96 | This is a statement!
97 | This is a factor!
98 | This is a term!
99 | This is a expression!
100 | This is a factor!
101 | This is a term!
102 | This is a expression!
103 | This is a write statement!
104 | This is a statement!
105 | This is a statement!
106 | This is a compound statement!
107 | This is a statement!
108 | This is a for statement!
109 | This is a statement!
110 | This is a string!
111 | This is a write statement!
112 | This is a statement!
113 | This is a unsigned integer!
114 | This is a factor!
115 | This is a term!
116 | This is a expression!
117 | This is a unsigned integer!
118 | This is a factor!
119 | This is a term!
120 | This is a expression!
121 | This is a factor!
122 | This is a term!
123 | This is a expression!
124 | This is a factor!
125 | This is a term!
126 | This is a expression!
127 | This is a assign statement!
128 | This is a statement!
129 | This is a factor!
130 | This is a term!
131 | This is a expression!
132 | This is a factor!
133 | This is a term!
134 | This is a expression!
135 | This is a write statement!
136 | This is a statement!
137 | This is a compound statement!
138 | This is a statement!
139 | This is a for statement!
140 | This is a statement!
141 | This is a string!
142 | This is a write statement!
143 | This is a statement!
144 | This is a statement!
145 | This is a compound statement!
146 | This is a statement!
147 | This is a compound statement!
148 | This is a block!
149 | This is a procedure declaration section!
150 | This is a basic type!
151 | This is a formal parameter section!
152 | This is a formal parameter list!
153 | This is a basic type!
154 | This is a function head!
155 | This is a basic type!
156 | This is a type!
157 | This is a variable defination!
158 | This is a variable declaration section!
159 | This is a basic type!
160 | This is a formal parameter section!
161 | This is a basic type!
162 | This is a formal parameter section!
163 | This is a formal parameter list!
164 | This is a procedure head!
165 | This is a factor!
166 | This is a term!
167 | This is a expression!
168 | This is a relation operator!
169 | This is a unsigned integer!
170 | This is a factor!
171 | This is a term!
172 | This is a expression!
173 | This is a condition!
174 | This is a factor!
175 | This is a term!
176 | This is a expression!
177 | This is a factor!
178 | This is a term!
179 | This is a expression!
180 | This is a factor!
181 | This is a term!
182 | This is a expression!
183 | This is a factor!
184 | This is a term!
185 | This is a unsigned integer!
186 | This is a factor!
187 | This is a term!
188 | This is a expression!
189 | This is a factor!
190 | This is a term!
191 | This is a expression!
192 | This is a real parameter list!
193 | This is a call statement!
194 | This is a statement!
195 | This is a factor!
196 | This is a term!
197 | This is a unsigned integer!
198 | This is a factor!
199 | This is a term!
200 | This is a expression!
201 | This is a assign statement!
202 | This is a statement!
203 | This is a string!
204 | This is a factor!
205 | This is a term!
206 | This is a expression!
207 | This is a write statement!
208 | This is a statement!
209 | This is a string!
210 | This is a factor!
211 | This is a term!
212 | This is a expression!
213 | This is a write statement!
214 | This is a statement!
215 | This is a string!
216 | This is a factor!
217 | This is a term!
218 | This is a expression!
219 | This is a write statement!
220 | This is a statement!
221 | This is a factor!
222 | This is a term!
223 | This is a expression!
224 | This is a factor!
225 | This is a term!
226 | This is a expression!
227 | This is a factor!
228 | This is a term!
229 | This is a expression!
230 | This is a factor!
231 | This is a term!
232 | This is a unsigned integer!
233 | This is a factor!
234 | This is a term!
235 | This is a expression!
236 | This is a factor!
237 | This is a term!
238 | This is a expression!
239 | This is a real parameter list!
240 | This is a call statement!
241 | This is a statement!
242 | This is a statement!
243 | This is a compound statement!
244 | This is a statement!
245 | This is a condition statement!
246 | This is a statement!
247 | This is a compound statement!
248 | This is a block!
249 | This is a procedure declaration section!
250 | This is a string!
251 | This is a write statement!
252 | This is a statement!
253 | This is a string!
254 | This is a write statement!
255 | This is a statement!
256 | This is a factor!
257 | This is a term!
258 | This is a expression!
259 | This is a write statement!
260 | This is a statement!
261 | This is a string!
262 | This is a factor!
263 | This is a term!
264 | This is a expression!
265 | This is a write statement!
266 | This is a statement!
267 | This is a unsigned integer!
268 | This is a factor!
269 | This is a term!
270 | This is a expression!
271 | This is a assign statement!
272 | This is a statement!
273 | This is a unsigned integer!
274 | This is a factor!
275 | This is a term!
276 | This is a expression!
277 | This is a unsigned integer!
278 | This is a factor!
279 | This is a term!
280 | This is a expression!
281 | This is a unsigned integer!
282 | This is a factor!
283 | This is a term!
284 | This is a expression!
285 | This is a factor!
286 | This is a term!
287 | This is a expression!
288 | This is a factor!
289 | This is a term!
290 | This is a expression!
291 | This is a real parameter list!
292 | This is a call statement!
293 | This is a factor!
294 | This is a term!
295 | This is a expression!
296 | This is a assign statement!
297 | This is a statement!
298 | This is a string!
299 | This is a factor!
300 | This is a term!
301 | This is a expression!
302 | This is a write statement!
303 | This is a statement!
304 | This is a string!
305 | This is a factor!
306 | This is a term!
307 | This is a expression!
308 | This is a write statement!
309 | This is a statement!
310 | This is a factor!
311 | This is a term!
312 | This is a expression!
313 | This is a assign statement!
314 | This is a statement!
315 | This is a statement!
316 | This is a compound statement!
317 | This is a block!
318 | This is a function declaration section!
319 | This is a basic type!
320 | This is a function head!
321 | This is a string!
322 | This is a write statement!
323 | This is a statement!
324 | This is a string!
325 | This is a write statement!
326 | This is a statement!
327 | This is a read statement!
328 | This is a statement!
329 | This is a read statement!
330 | This is a statement!
331 | This is a factor!
332 | This is a term!
333 | This is a expression!
334 | This is a relation operator!
335 | This is a factor!
336 | This is a term!
337 | This is a expression!
338 | This is a condition!
339 | This is a factor!
340 | This is a term!
341 | This is a expression!
342 | This is a relation operator!
343 | This is a factor!
344 | This is a term!
345 | This is a expression!
346 | This is a condition!
347 | This is a factor!
348 | This is a term!
349 | This is a expression!
350 | This is a relation operator!
351 | This is a unsigned integer!
352 | This is a factor!
353 | This is a term!
354 | This is a expression!
355 | This is a condition!
356 | This is a string!
357 | This is a write statement!
358 | This is a statement!
359 | This is a string!
360 | This is a write statement!
361 | This is a statement!
362 | This is a condition statement!
363 | This is a statement!
364 | This is a factor!
365 | This is a term!
366 | This is a expression!
367 | This is a relation operator!
368 | This is a unsigned integer!
369 | This is a factor!
370 | This is a term!
371 | This is a expression!
372 | This is a condition!
373 | This is a factor!
374 | This is a term!
375 | This is a expression!
376 | This is a relation operator!
377 | This is a unsigned integer!
378 | This is a factor!
379 | This is a term!
380 | This is a expression!
381 | This is a condition!
382 | This is a string!
383 | This is a write statement!
384 | This is a statement!
385 | This is a string!
386 | This is a write statement!
387 | This is a statement!
388 | This is a condition statement!
389 | This is a statement!
390 | This is a string!
391 | This is a write statement!
392 | This is a statement!
393 | This is a condition statement!
394 | This is a statement!
395 | This is a condition statement!
396 | This is a statement!
397 | This is a factor!
398 | This is a term!
399 | This is a expression!
400 | This is a relation operator!
401 | This is a unsigned integer!
402 | This is a factor!
403 | This is a term!
404 | This is a expression!
405 | This is a condition!
406 | This is a string!
407 | This is a write statement!
408 | This is a statement!
409 | This is a string!
410 | This is a write statement!
411 | This is a statement!
412 | This is a condition statement!
413 | This is a statement!
414 | This is a condition statement!
415 | This is a statement!
416 | This is a string!
417 | This is a factor!
418 | This is a term!
419 | This is a expression!
420 | This is a write statement!
421 | This is a statement!
422 | This is a factor!
423 | This is a term!
424 | This is a expression!
425 | This is a assign statement!
426 | This is a statement!
427 | This is a statement!
428 | This is a compound statement!
429 | This is a block!
430 | This is a function declaration section!
431 | This is a basic type!
432 | This is a formal parameter section!
433 | This is a basic type!
434 | This is a formal parameter section!
435 | This is a formal parameter list!
436 | This is a procedure head!
437 | This is a string!
438 | This is a write statement!
439 | This is a statement!
440 | This is a string!
441 | This is a write statement!
442 | This is a statement!
443 | This is a factor!
444 | This is a term!
445 | This is a expression!
446 | This is a write statement!
447 | This is a statement!
448 | This is a factor!
449 | This is a term!
450 | This is a expression!
451 | This is a write statement!
452 | This is a statement!
453 | This is a factor!
454 | This is a term!
455 | This is a expression!
456 | This is a write statement!
457 | This is a statement!
458 | This is a unsigned integer!
459 | This is a factor!
460 | This is a term!
461 | This is a expression!
462 | This is a assign statement!
463 | This is a statement!
464 | This is a factor!
465 | This is a term!
466 | This is a factor!
467 | This is a term!
468 | This is a expression!
469 | This is a assign statement!
470 | This is a statement!
471 | This is a factor!
472 | This is a term!
473 | This is a unsigned integer!
474 | This is a factor!
475 | This is a term!
476 | This is a expression!
477 | This is a assign statement!
478 | This is a statement!
479 | This is a statement!
480 | This is a compound statement!
481 | This is a statement!
482 | This is a factor!
483 | This is a term!
484 | This is a expression!
485 | This is a relation operator!
486 | This is a factor!
487 | This is a term!
488 | This is a expression!
489 | This is a condition!
490 | This is a do-while statement!
491 | This is a statement!
492 | This is a string!
493 | This is a factor!
494 | This is a term!
495 | This is a expression!
496 | This is a write statement!
497 | This is a statement!
498 | This is a string!
499 | This is a write statement!
500 | This is a statement!
501 | This is a statement!
502 | This is a compound statement!
503 | This is a block!
504 | This is a procedure declaration section!
505 | This is a call statement!
506 | This is a statement!
507 | This is a factor!
508 | This is a term!
509 | This is a expression!
510 | This is a factor!
511 | This is a term!
512 | This is a expression!
513 | This is a unsigned integer!
514 | This is a factor!
515 | This is a unsigned integer!
516 | This is a factor!
517 | This is a term!
518 | This is a unsigned integer!
519 | This is a factor!
520 | This is a unsigned integer!
521 | This is a factor!
522 | This is a term!
523 | This is a unsigned integer!
524 | This is a factor!
525 | This is a term!
526 | This is a expression!
527 | This is a factor!
528 | This is a term!
529 | This is a expression!
530 | This is a real parameter list!
531 | This is a call statement!
532 | This is a statement!
533 | This is a unsigned integer!
534 | This is a factor!
535 | This is a term!
536 | This is a expression!
537 | This is a real parameter list!
538 | This is a call statement!
539 | This is a factor!
540 | This is a term!
541 | This is a expression!
542 | This is a assign statement!
543 | This is a statement!
544 | This is a factor!
545 | This is a term!
546 | This is a expression!
547 | This is a assign statement!
548 | This is a statement!
549 | This is a statement!
550 | This is a compound statement!
551 | This is a block!
552 | This is a program!
553 |
--------------------------------------------------------------------------------
/05_语法分析程序/test.txt:
--------------------------------------------------------------------------------
1 | const TEN = 0010,
2 | NINE = +9,
3 | EIGHT1 = -8,
4 | A = 'A',
5 | ZERO = '0';
6 | var int1, int2: integer;
7 | ch1, ch2: char;
8 | intArray: array[3] of integer;
9 | chArray: array[1] of char;
10 | procedure proc1;
11 | begin
12 | write("proc1 start...");
13 | int1 := -(TEN + NINE) * EIGHT1 + 1024;
14 | ch1 := A;
15 | ch2 := ZERO;
16 | write("int1: ", int1);
17 | write("ch1: ", ch1);
18 | write("ch2: ", ch2);
19 | write("chArray:");
20 | for int2 := 0 downto 0 do
21 | begin
22 | chArray[int2] := ZERO;
23 | write(chArray[int2]);
24 | end;
25 | write("intArray:");
26 | for int2 := 0 to 2 do
27 | begin
28 | intArray[int2] := int2;
29 | write(intArray[int2])
30 | end;
31 | begin
32 | write("proc1 end.");
33 | end
34 | end;
35 | function func1(num: integer): integer;
36 | var steps: integer;
37 | procedure mov(tstart, tend, tmid, num: integer; var count: integer);
38 | begin
39 | if num > 0 then
40 | begin
41 | mov(tstart, tmid, tend, num-1, count);
42 | count := count + 1;
43 | write("step ", count);
44 | write("from: ", tstart);
45 | write("to: ", tend);
46 | mov(tmid, tend, tstart, num-1, count);
47 | end
48 | end;
49 | begin
50 | write("func1 start...");
51 | write("argument is num: integer");
52 | write(num);
53 | write("Hanoi Tower with levels: ", num);
54 | steps := 0;
55 | steps := mov(1, 3, 2, num, steps);
56 | write("The total number of steps is: ", steps);
57 | write("func1 end with: ", steps);
58 | func1 := steps;
59 | end;
60 | function func2: char;
61 | begin
62 | write("func2 start...");
63 | write("Please input ch1, ch2, int1...");
64 | read(ch1, ch2);
65 | read(int1);
66 | if ch1 <= ch2 then
67 | if ch1 < ch2 then
68 | if int1 = 0 then
69 | write("<=")
70 | else
71 | write("<")
72 | else if int1 >= 0 then
73 | if int1 > 0 then
74 | write("<>")
75 | else
76 | write("=")
77 | else
78 | write("<>")
79 | else
80 | if int1 <> 0 then
81 | write(">")
82 | else
83 | write(">=");
84 | write("func2 end with: ", ZERO);
85 | func2 := ZERO;
86 | end;
87 | procedure proc2(int1, int2: integer; var int3: integer);
88 | begin
89 | write("proc2 start...");
90 | write("arguments are int1, int2: integer; var int3: integer");
91 | write(int1);
92 | write(int2);
93 | write(int3);
94 | int3 := 0;
95 | do
96 | begin
97 | int3 := int3 + int2;
98 | int1 := int1 + 1;
99 | end
100 | while int1 < int2;
101 | write("int3 now is :", int3);
102 | write("proc2 end.");
103 | end;
104 | begin
105 | proc1;
106 | proc2(int1, int2, intArray[3 * 3 - 2 * 5 + 1]);
107 | int1 := func1(4);
108 | ch1 := func2;
109 | end.
--------------------------------------------------------------------------------
/05_语法分析程序/语法分析程序源码/ErrorHandler.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/05_语法分析程序/语法分析程序源码/ErrorHandler.cpp
--------------------------------------------------------------------------------
/05_语法分析程序/语法分析程序源码/ErrorHandler.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/05_语法分析程序/语法分析程序源码/ErrorHandler.h
--------------------------------------------------------------------------------
/05_语法分析程序/语法分析程序源码/GrammarAnalyzer.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/05_语法分析程序/语法分析程序源码/GrammarAnalyzer.cpp
--------------------------------------------------------------------------------
/05_语法分析程序/语法分析程序源码/GrammarAnalyzer.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/05_语法分析程序/语法分析程序源码/GrammarAnalyzer.h
--------------------------------------------------------------------------------
/05_语法分析程序/语法分析程序源码/LexicalAnalyzer.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/05_语法分析程序/语法分析程序源码/LexicalAnalyzer.cpp
--------------------------------------------------------------------------------
/05_语法分析程序/语法分析程序源码/LexicalAnalyzer.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/05_语法分析程序/语法分析程序源码/LexicalAnalyzer.h
--------------------------------------------------------------------------------
/05_语法分析程序/语法分析程序源码/SymbolTableManager.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/05_语法分析程序/语法分析程序源码/SymbolTableManager.cpp
--------------------------------------------------------------------------------
/05_语法分析程序/语法分析程序源码/SymbolTableManager.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/05_语法分析程序/语法分析程序源码/SymbolTableManager.h
--------------------------------------------------------------------------------
/05_语法分析程序/语法分析程序源码/main.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/05_语法分析程序/语法分析程序源码/main.cpp
--------------------------------------------------------------------------------
/05_语法分析程序/语法分析程序源码/test.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/05_语法分析程序/语法分析程序源码/test.cpp
--------------------------------------------------------------------------------
/05_语法分析程序/语法分析程序源码/type.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/05_语法分析程序/语法分析程序源码/type.h
--------------------------------------------------------------------------------
/06_代码生成程序/README.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/06_代码生成程序/README.txt
--------------------------------------------------------------------------------
/06_代码生成程序/test.txt:
--------------------------------------------------------------------------------
1 | const TEN = 0010,
2 | NINE = +9,
3 | EIGHT1 = -8,
4 | A = 'A',
5 | ZERO = '0';
6 | var int1, int2: integer;
7 | ch1, ch2: char;
8 | intArray: array[3] of integer;
9 | chArray: array[1] of char;
10 | procedure proc1;
11 | begin
12 | write("proc1 start...");
13 | int1 := -(TEN + NINE) * EIGHT1 + 1024;
14 | ch1 := A;
15 | ch2 := ZERO;
16 | write("int1: ", int1);
17 | write("ch1: ", ch1);
18 | write("ch2: ", ch2);
19 | write("chArray:");
20 | for int2 := 0 downto 0 do
21 | begin
22 | chArray[int2] := ZERO;
23 | write(chArray[int2]);
24 | end;
25 | write("intArray:");
26 | for int2 := 0 to 2 do
27 | begin
28 | intArray[int2] := int2;
29 | write(intArray[int2])
30 | end;
31 | begin
32 | write("proc1 end.");
33 | end
34 | end;
35 | function func1(num: integer): integer;
36 | var steps: integer;
37 | procedure mov(tstart, tend, tmid, num: integer; var count: integer);
38 | begin
39 | if num > 0 then
40 | begin
41 | mov(tstart, tmid, tend, num-1, count);
42 | count := count + 1;
43 | write("step ", count);
44 | write("from: ", tstart);
45 | write("to: ", tend);
46 | mov(tmid, tend, tstart, num-1, count);
47 | end
48 | end;
49 | begin
50 | write("func1 start...");
51 | write("argument is num: integer");
52 | write(num);
53 | write("Hanoi Tower with levels: ", num);
54 | steps := 0;
55 | mov(1, 3, 2, num, steps);
56 | write("The total number of steps is: ", steps);
57 | write("func1 end with: ", steps);
58 | func1 := steps;
59 | end;
60 | function func2: char;
61 | begin
62 | write("func2 start...");
63 | write("Please input ch1, ch2, int1...");
64 | read(ch1, ch2);
65 | read(int1);
66 | if ch1 <= ch2 then
67 | if ch1 < ch2 then
68 | if int1 = 0 then
69 | write("<=")
70 | else
71 | write("<")
72 | else if int1 >= 0 then
73 | if int1 > 0 then
74 | write("<>")
75 | else
76 | write("=")
77 | else
78 | write("<>")
79 | else
80 | if int1 <> 0 then
81 | write(">")
82 | else
83 | write(">=");
84 | write("func2 end with: ", ZERO);
85 | func2 := ZERO;
86 | end;
87 | procedure proc2(int1, int2: integer; var int3: integer);
88 | begin
89 | write("proc2 start...");
90 | write("arguments are int1, int2: integer; var int3: integer");
91 | write(int1);
92 | write(int2);
93 | write(int3);
94 | int3 := 0;
95 | do
96 | begin
97 | int3 := int3 + int2;
98 | int1 := int1 + 1;
99 | end
100 | while int1 < int2;
101 | write("int3 now is :", int3);
102 | write("proc2 end.");
103 | end;
104 | begin
105 | proc1;
106 | proc2(int1, int2, intArray[3 * 3 - 2 * 5 + 1]);
107 | int1 := func1(4);
108 | ch1 := func2;
109 | end.
--------------------------------------------------------------------------------
/06_代码生成程序/代码生成程序源码/ErrorHandler.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/06_代码生成程序/代码生成程序源码/ErrorHandler.cpp
--------------------------------------------------------------------------------
/06_代码生成程序/代码生成程序源码/ErrorHandler.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/06_代码生成程序/代码生成程序源码/ErrorHandler.h
--------------------------------------------------------------------------------
/06_代码生成程序/代码生成程序源码/GrammarAnalyzer.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/06_代码生成程序/代码生成程序源码/GrammarAnalyzer.cpp
--------------------------------------------------------------------------------
/06_代码生成程序/代码生成程序源码/GrammarAnalyzer.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/06_代码生成程序/代码生成程序源码/GrammarAnalyzer.h
--------------------------------------------------------------------------------
/06_代码生成程序/代码生成程序源码/LexicalAnalyzer.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/06_代码生成程序/代码生成程序源码/LexicalAnalyzer.cpp
--------------------------------------------------------------------------------
/06_代码生成程序/代码生成程序源码/LexicalAnalyzer.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/06_代码生成程序/代码生成程序源码/LexicalAnalyzer.h
--------------------------------------------------------------------------------
/06_代码生成程序/代码生成程序源码/Quadruples.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/06_代码生成程序/代码生成程序源码/Quadruples.cpp
--------------------------------------------------------------------------------
/06_代码生成程序/代码生成程序源码/Quadruples.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/06_代码生成程序/代码生成程序源码/Quadruples.h
--------------------------------------------------------------------------------
/06_代码生成程序/代码生成程序源码/SemanticAnalyzer.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/06_代码生成程序/代码生成程序源码/SemanticAnalyzer.cpp
--------------------------------------------------------------------------------
/06_代码生成程序/代码生成程序源码/SemanticAnalyzer.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/06_代码生成程序/代码生成程序源码/SemanticAnalyzer.h
--------------------------------------------------------------------------------
/06_代码生成程序/代码生成程序源码/SymbolTableManager.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/06_代码生成程序/代码生成程序源码/SymbolTableManager.cpp
--------------------------------------------------------------------------------
/06_代码生成程序/代码生成程序源码/SymbolTableManager.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/06_代码生成程序/代码生成程序源码/SymbolTableManager.h
--------------------------------------------------------------------------------
/06_代码生成程序/代码生成程序源码/TargetCodeGenerator.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/06_代码生成程序/代码生成程序源码/TargetCodeGenerator.h
--------------------------------------------------------------------------------
/06_代码生成程序/代码生成程序源码/main.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/06_代码生成程序/代码生成程序源码/main.cpp
--------------------------------------------------------------------------------
/06_代码生成程序/代码生成程序源码/test.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/06_代码生成程序/代码生成程序源码/test.cpp
--------------------------------------------------------------------------------
/06_代码生成程序/代码生成程序源码/type.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/06_代码生成程序/代码生成程序源码/type.h
--------------------------------------------------------------------------------
/06_代码生成程序/测试结果说明.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/06_代码生成程序/测试结果说明.docx
--------------------------------------------------------------------------------
/07_目标代码生成/README.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/README.txt
--------------------------------------------------------------------------------
/07_目标代码生成/assemble.asm:
--------------------------------------------------------------------------------
1 | .386
2 | .model flat, c
3 | option casemap: none
4 |
5 | includelib masm32\lib\kernel32.lib
6 | includelib masm32\lib\msvcrt.lib
7 | include masm32\include\msvcrt.inc
8 | include masm32\include\kernel32.inc
9 |
10 | .data
11 | format_printf_char db "%c", 0
12 | format_printf_int db "%d", 0
13 | format_printf_string db "%s", 0
14 | format_scanf_char db " %c", 0
15 | format_scanf_int db " %d", 0
16 | string_1 db "proc1 start...", 0
17 | string_10 db "to: ", 0
18 | string_11 db "func1 start...", 0
19 | string_12 db "argument is num: integer", 0
20 | string_13 db "Hanoi Tower with levels: ", 0
21 | string_14 db "The total number of steps is: ", 0
22 | string_15 db "func1 end with: ", 0
23 | string_16 db "func2 start...", 0
24 | string_17 db "Please input ch1, ch2, int1...", 0
25 | string_18 db "<=", 0
26 | string_19 db "<", 0
27 | string_2 db "int1: ", 0
28 | string_20 db "<>", 0
29 | string_21 db "=", 0
30 | string_22 db "<>", 0
31 | string_23 db ">", 0
32 | string_24 db ">=", 0
33 | string_25 db "func2 end with: ", 0
34 | string_26 db "proc2 start...", 0
35 | string_27 db "arguments are int1, int2: integer; var int3: integer", 0
36 | string_28 db "int3 now is :", 0
37 | string_29 db "proc2 end.", 0
38 | string_3 db "ch1: ", 0
39 | string_4 db "ch2: ", 0
40 | string_5 db "chArray:", 0
41 | string_6 db "intArray:", 0
42 | string_7 db "proc1 end.", 0
43 | string_8 db "step ", 0
44 | string_9 db "from: ", 0
45 |
46 | .code
47 |
48 | p_proc1_005A5D38 proc
49 | push ebp
50 | mov ebp, esp
51 | sub esp, 48
52 | push offset string_1
53 | push offset format_printf_string
54 | call crt_printf
55 | add esp, 8
56 | push 10
57 | push offset format_printf_char
58 | call crt_printf
59 | add esp, 8
60 | mov eax, 10
61 | add eax, 9
62 | mov ebx, eax
63 | imul ebx, 8
64 | mov ecx, ebx
65 | neg ecx
66 | mov edi, ecx
67 | add edi, 1024
68 | mov edx, [ebp+8]
69 | mov [edx-4], edi
70 | mov edx, [ebp+8]
71 | mov esi, 65
72 | mov [edx-12], esi
73 | mov edx, [ebp+8]
74 | mov esi, 48
75 | mov [edx-16], esi
76 | push offset string_2
77 | push offset format_printf_string
78 | mov [ebp-4], eax
79 | mov [ebp-8], ebx
80 | mov [ebp-12], ecx
81 | mov [ebp-16], edi
82 | call crt_printf
83 | add esp, 8
84 | mov eax, [ebp+8]
85 | push [eax-4]
86 | push offset format_printf_int
87 | call crt_printf
88 | add esp, 8
89 | push 10
90 | push offset format_printf_char
91 | call crt_printf
92 | add esp, 8
93 | push offset string_3
94 | push offset format_printf_string
95 | call crt_printf
96 | add esp, 8
97 | mov eax, [ebp+8]
98 | push [eax-12]
99 | push offset format_printf_char
100 | call crt_printf
101 | add esp, 8
102 | push 10
103 | push offset format_printf_char
104 | call crt_printf
105 | add esp, 8
106 | push offset string_4
107 | push offset format_printf_string
108 | call crt_printf
109 | add esp, 8
110 | mov eax, [ebp+8]
111 | push [eax-16]
112 | push offset format_printf_char
113 | call crt_printf
114 | add esp, 8
115 | push 10
116 | push offset format_printf_char
117 | call crt_printf
118 | add esp, 8
119 | push offset string_5
120 | push offset format_printf_string
121 | call crt_printf
122 | add esp, 8
123 | push 10
124 | push offset format_printf_char
125 | call crt_printf
126 | add esp, 8
127 | mov eax, [ebp+8]
128 | mov ebx, 0
129 | mov [eax-8], ebx
130 | loop_for_start_label_1:
131 | mov eax, [ebp+8]
132 | mov eax, [eax-8]
133 | cmp eax, 0
134 | jl loop_for_end_label_2
135 | mov eax, [ebp+8]
136 | sub eax, 32
137 | mov ecx, [ebp+8]
138 | mov ebx, [ecx-8]
139 | shl ebx, 2
140 | sub eax, ebx
141 | mov ebx, 48
142 | mov [eax], ebx
143 | mov ebx, [ebp+8]
144 | sub ebx, 32
145 | mov edi, [ebp+8]
146 | mov ecx, [edi-8]
147 | shl ecx, 2
148 | sub ebx, ecx
149 | mov edx, [ebx]
150 | push edx
151 | push offset format_printf_char
152 | mov [ebp-20], eax
153 | mov [ebp-24], ebx
154 | mov [ebp-28], edx
155 | call crt_printf
156 | add esp, 8
157 | push 10
158 | push offset format_printf_char
159 | call crt_printf
160 | add esp, 8
161 | mov ebx, [ebp+8]
162 | mov eax, [ebx-8]
163 | add eax, -1
164 | mov ebx, [ebp+8]
165 | mov [ebx-8], eax
166 | mov [ebp-32], eax
167 | jmp loop_for_start_label_1
168 | loop_for_end_label_2:
169 | push offset string_6
170 | push offset format_printf_string
171 | call crt_printf
172 | add esp, 8
173 | push 10
174 | push offset format_printf_char
175 | call crt_printf
176 | add esp, 8
177 | mov eax, [ebp+8]
178 | mov ebx, 0
179 | mov [eax-8], ebx
180 | loop_for_start_label_3:
181 | mov eax, [ebp+8]
182 | mov eax, [eax-8]
183 | cmp eax, 2
184 | jg loop_for_end_label_4
185 | mov eax, [ebp+8]
186 | sub eax, 20
187 | mov ecx, [ebp+8]
188 | mov ebx, [ecx-8]
189 | shl ebx, 2
190 | sub eax, ebx
191 | mov ebx, [ebp+8]
192 | mov ebx, [ebx-8]
193 | mov [eax], ebx
194 | mov ecx, [ebp+8]
195 | sub ecx, 20
196 | mov edi, ebx
197 | shl edi, 2
198 | sub ecx, edi
199 | mov edx, [ecx]
200 | push edx
201 | push offset format_printf_int
202 | mov [ebp-36], eax
203 | mov eax, [ebp+8]
204 | mov [eax-8], ebx
205 | mov [ebp-40], ecx
206 | mov [ebp-44], edx
207 | call crt_printf
208 | add esp, 8
209 | push 10
210 | push offset format_printf_char
211 | call crt_printf
212 | add esp, 8
213 | mov ebx, [ebp+8]
214 | mov eax, [ebx-8]
215 | add eax, 1
216 | mov ebx, [ebp+8]
217 | mov [ebx-8], eax
218 | mov [ebp-48], eax
219 | jmp loop_for_start_label_3
220 | loop_for_end_label_4:
221 | push offset string_7
222 | push offset format_printf_string
223 | call crt_printf
224 | add esp, 8
225 | push 10
226 | push offset format_printf_char
227 | call crt_printf
228 | add esp, 8
229 | leave
230 | ret
231 | p_proc1_005A5D38 endp
232 |
233 | p_mov_005AB338 proc
234 | push ebp
235 | mov ebp, esp
236 | sub esp, 20
237 | mov eax, [ebp+20]
238 | cmp eax, 0
239 | jle condition_else_label_5
240 | mov eax, [ebp+20]
241 | sub eax, 1
242 | push [ebp+32]
243 | push [ebp+28]
244 | push [ebp+24]
245 | push eax
246 | push [ebp+12]
247 | push [ebp+16]
248 | push [ebp+8]
249 | mov [ebp-4], eax
250 | call p_mov_005AB338
251 | add esp, 28
252 | mov eax, [ebp+24]
253 | mov ebx, [eax]
254 | mov ecx, ebx
255 | add ecx, 1
256 | mov [eax], ecx
257 | push offset string_8
258 | push offset format_printf_string
259 | mov [ebp+24], eax
260 | mov [ebp-8], ebx
261 | mov [ebp-12], ecx
262 | call crt_printf
263 | add esp, 8
264 | mov eax, [ebp+24]
265 | mov ebx, [eax]
266 | push ebx
267 | push offset format_printf_int
268 | mov [ebp+24], eax
269 | mov [ebp-16], ebx
270 | call crt_printf
271 | add esp, 8
272 | push 10
273 | push offset format_printf_char
274 | call crt_printf
275 | add esp, 8
276 | push offset string_9
277 | push offset format_printf_string
278 | call crt_printf
279 | add esp, 8
280 | push [ebp+8]
281 | push offset format_printf_int
282 | call crt_printf
283 | add esp, 8
284 | push 10
285 | push offset format_printf_char
286 | call crt_printf
287 | add esp, 8
288 | push offset string_10
289 | push offset format_printf_string
290 | call crt_printf
291 | add esp, 8
292 | push [ebp+12]
293 | push offset format_printf_int
294 | call crt_printf
295 | add esp, 8
296 | push 10
297 | push offset format_printf_char
298 | call crt_printf
299 | add esp, 8
300 | mov eax, [ebp+20]
301 | sub eax, 1
302 | push [ebp+32]
303 | push [ebp+28]
304 | push [ebp+24]
305 | push eax
306 | push [ebp+8]
307 | push [ebp+12]
308 | push [ebp+16]
309 | mov [ebp-20], eax
310 | call p_mov_005AB338
311 | add esp, 28
312 | jmp condition_end_label_6
313 | condition_else_label_5:
314 | condition_end_label_6:
315 | leave
316 | ret
317 | p_mov_005AB338 endp
318 |
319 | f_func1_005AB200 proc
320 | push ebp
321 | mov ebp, esp
322 | sub esp, 4
323 | sub esp, 4
324 | sub esp, 4
325 | push offset string_11
326 | push offset format_printf_string
327 | call crt_printf
328 | add esp, 8
329 | push 10
330 | push offset format_printf_char
331 | call crt_printf
332 | add esp, 8
333 | push offset string_12
334 | push offset format_printf_string
335 | call crt_printf
336 | add esp, 8
337 | push 10
338 | push offset format_printf_char
339 | call crt_printf
340 | add esp, 8
341 | push [ebp+8]
342 | push offset format_printf_int
343 | call crt_printf
344 | add esp, 8
345 | push 10
346 | push offset format_printf_char
347 | call crt_printf
348 | add esp, 8
349 | push offset string_13
350 | push offset format_printf_string
351 | call crt_printf
352 | add esp, 8
353 | push [ebp+8]
354 | push offset format_printf_int
355 | call crt_printf
356 | add esp, 8
357 | push 10
358 | push offset format_printf_char
359 | call crt_printf
360 | add esp, 8
361 | mov ebx, 0
362 | mov [ebp-8], ebx
363 | mov eax, ebp
364 | sub eax, 8
365 | push [ebp+12]
366 | push ebp
367 | push eax
368 | push [ebp+8]
369 | push 2
370 | push 3
371 | push 1
372 | mov [ebp-12], eax
373 | call p_mov_005AB338
374 | add esp, 28
375 | push offset string_14
376 | push offset format_printf_string
377 | call crt_printf
378 | add esp, 8
379 | push [ebp-8]
380 | push offset format_printf_int
381 | call crt_printf
382 | add esp, 8
383 | push 10
384 | push offset format_printf_char
385 | call crt_printf
386 | add esp, 8
387 | push offset string_15
388 | push offset format_printf_string
389 | call crt_printf
390 | add esp, 8
391 | push [ebp-8]
392 | push offset format_printf_int
393 | call crt_printf
394 | add esp, 8
395 | push 10
396 | push offset format_printf_char
397 | call crt_printf
398 | add esp, 8
399 | mov eax, [ebp-8]
400 | mov [ebp-4], eax
401 | mov eax, [ebp-4]
402 | leave
403 | ret
404 | f_func1_005AB200 endp
405 |
406 | f_func2_005AB5A8 proc
407 | push ebp
408 | mov ebp, esp
409 | sub esp, 4
410 | sub esp, 0
411 | push offset string_16
412 | push offset format_printf_string
413 | call crt_printf
414 | add esp, 8
415 | push 10
416 | push offset format_printf_char
417 | call crt_printf
418 | add esp, 8
419 | push offset string_17
420 | push offset format_printf_string
421 | call crt_printf
422 | add esp, 8
423 | push 10
424 | push offset format_printf_char
425 | call crt_printf
426 | add esp, 8
427 | mov eax, [ebp+8]
428 | sub eax, 12
429 | push eax
430 | push offset format_scanf_char
431 | call crt_scanf
432 | add esp, 8
433 | mov eax, [ebp+8]
434 | sub eax, 16
435 | push eax
436 | push offset format_scanf_char
437 | call crt_scanf
438 | add esp, 8
439 | mov eax, [ebp+8]
440 | sub eax, 4
441 | push eax
442 | push offset format_scanf_int
443 | call crt_scanf
444 | add esp, 8
445 | mov eax, [ebp+8]
446 | mov eax, [eax-12]
447 | mov ebx, [ebp+8]
448 | cmp eax, [ebx-16]
449 | jg condition_else_label_7
450 | mov eax, [ebp+8]
451 | mov eax, [eax-12]
452 | mov ebx, [ebp+8]
453 | cmp eax, [ebx-16]
454 | jge condition_else_label_9
455 | mov eax, 0
456 | mov ebx, [ebp+8]
457 | cmp eax, [ebx-4]
458 | jne condition_else_label_11
459 | push offset string_18
460 | push offset format_printf_string
461 | call crt_printf
462 | add esp, 8
463 | push 10
464 | push offset format_printf_char
465 | call crt_printf
466 | add esp, 8
467 | jmp condition_end_label_12
468 | condition_else_label_11:
469 | push offset string_19
470 | push offset format_printf_string
471 | call crt_printf
472 | add esp, 8
473 | push 10
474 | push offset format_printf_char
475 | call crt_printf
476 | add esp, 8
477 | condition_end_label_12:
478 | jmp condition_end_label_10
479 | condition_else_label_9:
480 | mov eax, [ebp+8]
481 | mov eax, [eax-4]
482 | cmp eax, 0
483 | jl condition_else_label_13
484 | mov eax, [ebp+8]
485 | mov eax, [eax-4]
486 | cmp eax, 0
487 | jle condition_else_label_15
488 | push offset string_20
489 | push offset format_printf_string
490 | call crt_printf
491 | add esp, 8
492 | push 10
493 | push offset format_printf_char
494 | call crt_printf
495 | add esp, 8
496 | jmp condition_end_label_16
497 | condition_else_label_15:
498 | push offset string_21
499 | push offset format_printf_string
500 | call crt_printf
501 | add esp, 8
502 | push 10
503 | push offset format_printf_char
504 | call crt_printf
505 | add esp, 8
506 | condition_end_label_16:
507 | jmp condition_end_label_14
508 | condition_else_label_13:
509 | push offset string_22
510 | push offset format_printf_string
511 | call crt_printf
512 | add esp, 8
513 | push 10
514 | push offset format_printf_char
515 | call crt_printf
516 | add esp, 8
517 | condition_end_label_14:
518 | condition_end_label_10:
519 | jmp condition_end_label_8
520 | condition_else_label_7:
521 | mov eax, 0
522 | mov ebx, [ebp+8]
523 | cmp eax, [ebx-4]
524 | je condition_else_label_17
525 | push offset string_23
526 | push offset format_printf_string
527 | call crt_printf
528 | add esp, 8
529 | push 10
530 | push offset format_printf_char
531 | call crt_printf
532 | add esp, 8
533 | jmp condition_end_label_18
534 | condition_else_label_17:
535 | push offset string_24
536 | push offset format_printf_string
537 | call crt_printf
538 | add esp, 8
539 | push 10
540 | push offset format_printf_char
541 | call crt_printf
542 | add esp, 8
543 | condition_end_label_18:
544 | condition_end_label_8:
545 | push offset string_25
546 | push offset format_printf_string
547 | call crt_printf
548 | add esp, 8
549 | push 48
550 | push offset format_printf_char
551 | call crt_printf
552 | add esp, 8
553 | push 10
554 | push offset format_printf_char
555 | call crt_printf
556 | add esp, 8
557 | mov eax, 48
558 | mov [ebp-4], eax
559 | mov eax, [ebp-4]
560 | leave
561 | ret
562 | f_func2_005AB5A8 endp
563 |
564 | p_proc2_005AB610 proc
565 | push ebp
566 | mov ebp, esp
567 | sub esp, 20
568 | push offset string_26
569 | push offset format_printf_string
570 | call crt_printf
571 | add esp, 8
572 | push 10
573 | push offset format_printf_char
574 | call crt_printf
575 | add esp, 8
576 | push offset string_27
577 | push offset format_printf_string
578 | call crt_printf
579 | add esp, 8
580 | push 10
581 | push offset format_printf_char
582 | call crt_printf
583 | add esp, 8
584 | push [ebp+8]
585 | push offset format_printf_int
586 | call crt_printf
587 | add esp, 8
588 | push 10
589 | push offset format_printf_char
590 | call crt_printf
591 | add esp, 8
592 | push [ebp+12]
593 | push offset format_printf_int
594 | call crt_printf
595 | add esp, 8
596 | push 10
597 | push offset format_printf_char
598 | call crt_printf
599 | add esp, 8
600 | mov eax, [ebp+16]
601 | mov ebx, [eax]
602 | push ebx
603 | push offset format_printf_int
604 | mov [ebp+16], eax
605 | mov [ebp-4], ebx
606 | call crt_printf
607 | add esp, 8
608 | push 10
609 | push offset format_printf_char
610 | call crt_printf
611 | add esp, 8
612 | mov eax, 0
613 | mov ebx, [ebp+16]
614 | mov [ebx], eax
615 | mov [ebp+16], ebx
616 | loop_do_while_label_19:
617 | mov eax, [ebp+16]
618 | mov ebx, [eax]
619 | mov ecx, ebx
620 | add ecx, [ebp+12]
621 | mov [eax], ecx
622 | mov edi, [ebp+8]
623 | add edi, 1
624 | mov [ebp+8], edi
625 | mov [ebp+16], eax
626 | mov [ebp-8], ebx
627 | mov [ebp-12], ecx
628 | mov [ebp-16], edi
629 | mov eax, [ebp+8]
630 | cmp eax, [ebp+12]
631 | jl loop_do_while_label_19
632 | push offset string_28
633 | push offset format_printf_string
634 | call crt_printf
635 | add esp, 8
636 | mov eax, [ebp+16]
637 | mov ebx, [eax]
638 | push ebx
639 | push offset format_printf_int
640 | mov [ebp+16], eax
641 | mov [ebp-20], ebx
642 | call crt_printf
643 | add esp, 8
644 | push 10
645 | push offset format_printf_char
646 | call crt_printf
647 | add esp, 8
648 | push offset string_29
649 | push offset format_printf_string
650 | call crt_printf
651 | add esp, 8
652 | push 10
653 | push offset format_printf_char
654 | call crt_printf
655 | add esp, 8
656 | leave
657 | ret
658 | p_proc2_005AB610 endp
659 |
660 | _main:
661 | push ebp
662 | mov ebp, esp
663 | sub esp, 4
664 | sub esp, 4
665 | sub esp, 4
666 | sub esp, 4
667 | sub esp, 4
668 | sub esp, 12
669 | sub esp, 28
670 | push ebp
671 | call p_proc1_005A5D38
672 | add esp, 4
673 | mov eax, 3
674 | imul eax, 3
675 | mov ebx, 2
676 | imul ebx, 5
677 | mov ecx, eax
678 | sub ecx, ebx
679 | mov edi, ecx
680 | add edi, 1
681 | mov edx, ebp
682 | sub edx, 20
683 | mov esi, edi
684 | shl esi, 2
685 | sub edx, esi
686 | push ebp
687 | push edx
688 | push [ebp-8]
689 | push [ebp-4]
690 | mov [ebp-36], eax
691 | mov [ebp-40], ebx
692 | mov [ebp-44], ecx
693 | mov [ebp-48], edi
694 | mov [ebp-52], edx
695 | call p_proc2_005AB610
696 | add esp, 16
697 | push ebp
698 | push 4
699 | call f_func1_005AB200
700 | add esp, 8
701 | mov [ebp-56], eax
702 | mov ebx, [ebp-56]
703 | mov [ebp-4], ebx
704 | push ebp
705 | mov [ebp-56], ebx
706 | call f_func2_005AB5A8
707 | add esp, 4
708 | mov [ebp-60], eax
709 | mov ebx, [ebp-60]
710 | mov [ebp-12], ebx
711 | push 0
712 | call ExitProcess
713 | leave
714 | ret
715 | end _main
716 | end
717 |
--------------------------------------------------------------------------------
/07_目标代码生成/test.txt:
--------------------------------------------------------------------------------
1 | const TEN = 0010,
2 | NINE = +9,
3 | EIGHT1 = -8,
4 | A = 'A',
5 | ZERO = '0';
6 | var int1, int2: integer;
7 | ch1, ch2: char;
8 | intArray: array[3] of integer;
9 | chArray: array[1] of char;
10 | procedure proc1;
11 | begin
12 | write("proc1 start...");
13 | int1 := -(TEN + NINE) * EIGHT1 + 1024;
14 | ch1 := A;
15 | ch2 := ZERO;
16 | write("int1: ", int1);
17 | write("ch1: ", ch1);
18 | write("ch2: ", ch2);
19 | write("chArray:");
20 | for int2 := 0 downto 0 do
21 | begin
22 | chArray[int2] := ZERO;
23 | write(chArray[int2]);
24 | end;
25 | write("intArray:");
26 | for int2 := 0 to 2 do
27 | begin
28 | intArray[int2] := int2;
29 | write(intArray[int2])
30 | end;
31 | begin
32 | write("proc1 end.");
33 | end
34 | end;
35 | function func1(num: integer): integer;
36 | var steps: integer;
37 | procedure mov(tstart, tend, tmid, num: integer; var count: integer);
38 | begin
39 | if num > 0 then
40 | begin
41 | mov(tstart, tmid, tend, num-1, count);
42 | count := count + 1;
43 | write("step ", count);
44 | write("from: ", tstart);
45 | write("to: ", tend);
46 | mov(tmid, tend, tstart, num-1, count);
47 | end
48 | end;
49 | begin
50 | write("func1 start...");
51 | write("argument is num: integer");
52 | write(num);
53 | write("Hanoi Tower with levels: ", num);
54 | steps := 0;
55 | mov(1, 3, 2, num, steps);
56 | write("The total number of steps is: ", steps);
57 | write("func1 end with: ", steps);
58 | func1 := steps;
59 | end;
60 | function func2: char;
61 | begin
62 | write("func2 start...");
63 | write("Please input ch1, ch2, int1...");
64 | read(ch1, ch2);
65 | read(int1);
66 | if ch1 <= ch2 then
67 | if ch1 < ch2 then
68 | if 0 = int1 then
69 | write("<=")
70 | else
71 | write("<")
72 | else if int1 >= 0 then
73 | if int1 > 0 then
74 | write("<>")
75 | else
76 | write("=")
77 | else
78 | write("<>")
79 | else
80 | if 0 <> int1 then
81 | write(">")
82 | else
83 | write(">=");
84 | write("func2 end with: ", ZERO);
85 | func2 := ZERO;
86 | end;
87 | procedure proc2(int1, int2: integer; var int3: integer);
88 | begin
89 | write("proc2 start...");
90 | write("arguments are int1, int2: integer; var int3: integer");
91 | write(int1);
92 | write(int2);
93 | write(int3);
94 | int3 := 0;
95 | do
96 | begin
97 | int3 := int3 + int2;
98 | int1 := int1 + 1;
99 | end
100 | while int1 < int2;
101 | write("int3 now is :", int3);
102 | write("proc2 end.");
103 | end;
104 | begin
105 | proc1;
106 | proc2(int1, int2, intArray[3 * 3 - 2 * 5 + 1]);
107 | int1 := func1(4);
108 | ch1 := func2;
109 | end.
--------------------------------------------------------------------------------
/07_目标代码生成/目标代码生成程序源码/ErrorHandler.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/目标代码生成程序源码/ErrorHandler.cpp
--------------------------------------------------------------------------------
/07_目标代码生成/目标代码生成程序源码/ErrorHandler.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/目标代码生成程序源码/ErrorHandler.h
--------------------------------------------------------------------------------
/07_目标代码生成/目标代码生成程序源码/GrammarAnalyzer.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/目标代码生成程序源码/GrammarAnalyzer.cpp
--------------------------------------------------------------------------------
/07_目标代码生成/目标代码生成程序源码/GrammarAnalyzer.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/目标代码生成程序源码/GrammarAnalyzer.h
--------------------------------------------------------------------------------
/07_目标代码生成/目标代码生成程序源码/LexicalAnalyzer.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/目标代码生成程序源码/LexicalAnalyzer.cpp
--------------------------------------------------------------------------------
/07_目标代码生成/目标代码生成程序源码/LexicalAnalyzer.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/目标代码生成程序源码/LexicalAnalyzer.h
--------------------------------------------------------------------------------
/07_目标代码生成/目标代码生成程序源码/Quadruples.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/目标代码生成程序源码/Quadruples.cpp
--------------------------------------------------------------------------------
/07_目标代码生成/目标代码生成程序源码/Quadruples.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/目标代码生成程序源码/Quadruples.h
--------------------------------------------------------------------------------
/07_目标代码生成/目标代码生成程序源码/RegisterPool.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/目标代码生成程序源码/RegisterPool.cpp
--------------------------------------------------------------------------------
/07_目标代码生成/目标代码生成程序源码/RegisterPool.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/目标代码生成程序源码/RegisterPool.h
--------------------------------------------------------------------------------
/07_目标代码生成/目标代码生成程序源码/SemanticAnalyzer.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/目标代码生成程序源码/SemanticAnalyzer.cpp
--------------------------------------------------------------------------------
/07_目标代码生成/目标代码生成程序源码/SemanticAnalyzer.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/目标代码生成程序源码/SemanticAnalyzer.h
--------------------------------------------------------------------------------
/07_目标代码生成/目标代码生成程序源码/StackManager.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/目标代码生成程序源码/StackManager.cpp
--------------------------------------------------------------------------------
/07_目标代码生成/目标代码生成程序源码/StackManager.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/目标代码生成程序源码/StackManager.h
--------------------------------------------------------------------------------
/07_目标代码生成/目标代码生成程序源码/SymbolTableManager.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/目标代码生成程序源码/SymbolTableManager.cpp
--------------------------------------------------------------------------------
/07_目标代码生成/目标代码生成程序源码/SymbolTableManager.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/目标代码生成程序源码/SymbolTableManager.h
--------------------------------------------------------------------------------
/07_目标代码生成/目标代码生成程序源码/TargetCodeGenerator.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/目标代码生成程序源码/TargetCodeGenerator.cpp
--------------------------------------------------------------------------------
/07_目标代码生成/目标代码生成程序源码/TargetCodeGenerator.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/目标代码生成程序源码/TargetCodeGenerator.h
--------------------------------------------------------------------------------
/07_目标代码生成/目标代码生成程序源码/main.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/目标代码生成程序源码/main.cpp
--------------------------------------------------------------------------------
/07_目标代码生成/目标代码生成程序源码/type.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/目标代码生成程序源码/type.h
--------------------------------------------------------------------------------
/07_目标代码生成/目标代码生成程序源码/x86_instruction.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/07_目标代码生成/目标代码生成程序源码/x86_instruction.h
--------------------------------------------------------------------------------
/08_最终结果/README.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/README.txt
--------------------------------------------------------------------------------
/08_最终结果/文档/编译课设文档.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/文档/编译课设文档.docx
--------------------------------------------------------------------------------
/08_最终结果/文档/编译课设申优文档.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/文档/编译课设申优文档.docx
--------------------------------------------------------------------------------
/08_最终结果/测试程序/测试程序.txt:
--------------------------------------------------------------------------------
1 | const TEN = 0010,
2 | NINE = +9,
3 | EIGHT1 = -8,
4 | A = 'A',
5 | ZERO = '0';
6 | var int1, int2: integer;
7 | ch1, ch2: char;
8 | intArray: array[3] of integer;
9 | chArray: array[1] of char;
10 | procedure proc1;
11 | begin
12 | write("proc1 start...");
13 | int1 := -(TEN + NINE) * EIGHT1 + 1024;
14 | ch1 := A;
15 | ch2 := ZERO;
16 | write("int1: ", int1);
17 | write("ch1: ", ch1);
18 | write("ch2: ", ch2);
19 | write("chArray:");
20 | for int2 := 0 downto 0 do
21 | begin
22 | chArray[int2] := ZERO;
23 | write(chArray[int2]);
24 | end;
25 | write("intArray:");
26 | for int2 := 0 to 2 do
27 | begin
28 | intArray[int2] := int2;
29 | write(intArray[int2])
30 | end;
31 | begin
32 | write("proc1 end.");
33 | end
34 | end;
35 | function func1(num: integer): integer;
36 | var steps: integer;
37 | procedure mov(tstart, tend, tmid, num: integer; var count: integer);
38 | begin
39 | if num > 0 then
40 | begin
41 | mov(tstart, tmid, tend, num-1, count);
42 | count := count + 1;
43 | write("step ", count);
44 | write("from: ", tstart);
45 | write("to: ", tend);
46 | mov(tmid, tend, tstart, num-1, count);
47 | end
48 | end;
49 | begin
50 | write("func1 start...");
51 | write("argument is num: integer");
52 | write(num);
53 | write("Hanoi Tower with levels: ", num);
54 | steps := 0;
55 | mov(1, 3, 2, num, steps);
56 | write("The total number of steps is: ", steps);
57 | write("func1 end with: ", steps);
58 | func1 := steps;
59 | end;
60 | function func2: char;
61 | begin
62 | write("func2 start...");
63 | write("Please input ch1, ch2, int1...");
64 | read(ch1, ch2);
65 | read(int1);
66 | if ch1 <= ch2 then
67 | if ch1 < ch2 then
68 | if 0 = int1 then
69 | write("<=")
70 | else
71 | write("<")
72 | else if int1 >= 0 then
73 | if int1 > 0 then
74 | write("<>")
75 | else
76 | write("=")
77 | else
78 | write("<>")
79 | else
80 | if 0 <> int1 then
81 | write(">")
82 | else
83 | write(">=");
84 | write("func2 end with: ", ZERO);
85 | func2 := ZERO;
86 | end;
87 | procedure proc2(int1, int2: integer; var int3: integer);
88 | begin
89 | write("proc2 start...");
90 | write("arguments are int1, int2: integer; var int3: integer");
91 | write(int1);
92 | write(int2);
93 | write(int3);
94 | int3 := 0;
95 | do
96 | begin
97 | int3 := int3 + int2;
98 | int1 := int1 + 1;
99 | end
100 | while int1 < int2;
101 | write("int3 now is :", int3);
102 | write("proc2 end.");
103 | end;
104 | begin
105 | proc1;
106 | proc2(int1, int2, intArray[3 * 3 - 2 * 5 + 1]);
107 | int1 := func1(4);
108 | ch1 := func2;
109 | end.
--------------------------------------------------------------------------------
/08_最终结果/测试程序/目标代码运行结果.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/测试程序/目标代码运行结果.txt
--------------------------------------------------------------------------------
/08_最终结果/测试程序/编译结果.asm:
--------------------------------------------------------------------------------
1 | .386
2 | .model flat, c
3 | option casemap: none
4 |
5 | includelib masm32\lib\kernel32.lib
6 | includelib masm32\lib\msvcrt.lib
7 | include masm32\include\msvcrt.inc
8 | include masm32\include\kernel32.inc
9 |
10 | .data
11 | format_printf_char db "%c", 0
12 | format_printf_int db "%d", 0
13 | format_printf_string db "%s", 0
14 | format_scanf_char db " %c", 0
15 | format_scanf_int db " %d", 0
16 | string_1 db "proc1 start...", 0
17 | string_10 db "to: ", 0
18 | string_11 db "func1 start...", 0
19 | string_12 db "argument is num: integer", 0
20 | string_13 db "Hanoi Tower with levels: ", 0
21 | string_14 db "The total number of steps is: ", 0
22 | string_15 db "func1 end with: ", 0
23 | string_16 db "func2 start...", 0
24 | string_17 db "Please input ch1, ch2, int1...", 0
25 | string_18 db "<=", 0
26 | string_19 db "<", 0
27 | string_2 db "int1: ", 0
28 | string_20 db "<>", 0
29 | string_21 db "=", 0
30 | string_22 db "<>", 0
31 | string_23 db ">", 0
32 | string_24 db ">=", 0
33 | string_25 db "func2 end with: ", 0
34 | string_26 db "proc2 start...", 0
35 | string_27 db "arguments are int1, int2: integer; var int3: integer", 0
36 | string_28 db "int3 now is :", 0
37 | string_29 db "proc2 end.", 0
38 | string_3 db "ch1: ", 0
39 | string_4 db "ch2: ", 0
40 | string_5 db "chArray:", 0
41 | string_6 db "intArray:", 0
42 | string_7 db "proc1 end.", 0
43 | string_8 db "step ", 0
44 | string_9 db "from: ", 0
45 |
46 | .code
47 |
48 | p_proc1_005A5D38 proc
49 | push ebp
50 | mov ebp, esp
51 | sub esp, 48
52 | push offset string_1
53 | push offset format_printf_string
54 | call crt_printf
55 | add esp, 8
56 | push 10
57 | push offset format_printf_char
58 | call crt_printf
59 | add esp, 8
60 | mov eax, 10
61 | add eax, 9
62 | mov ebx, eax
63 | imul ebx, 8
64 | mov ecx, ebx
65 | neg ecx
66 | mov edi, ecx
67 | add edi, 1024
68 | mov edx, [ebp+8]
69 | mov [edx-4], edi
70 | mov edx, [ebp+8]
71 | mov esi, 65
72 | mov [edx-12], esi
73 | mov edx, [ebp+8]
74 | mov esi, 48
75 | mov [edx-16], esi
76 | push offset string_2
77 | push offset format_printf_string
78 | mov [ebp-4], eax
79 | mov [ebp-8], ebx
80 | mov [ebp-12], ecx
81 | mov [ebp-16], edi
82 | call crt_printf
83 | add esp, 8
84 | mov eax, [ebp+8]
85 | push [eax-4]
86 | push offset format_printf_int
87 | call crt_printf
88 | add esp, 8
89 | push 10
90 | push offset format_printf_char
91 | call crt_printf
92 | add esp, 8
93 | push offset string_3
94 | push offset format_printf_string
95 | call crt_printf
96 | add esp, 8
97 | mov eax, [ebp+8]
98 | push [eax-12]
99 | push offset format_printf_char
100 | call crt_printf
101 | add esp, 8
102 | push 10
103 | push offset format_printf_char
104 | call crt_printf
105 | add esp, 8
106 | push offset string_4
107 | push offset format_printf_string
108 | call crt_printf
109 | add esp, 8
110 | mov eax, [ebp+8]
111 | push [eax-16]
112 | push offset format_printf_char
113 | call crt_printf
114 | add esp, 8
115 | push 10
116 | push offset format_printf_char
117 | call crt_printf
118 | add esp, 8
119 | push offset string_5
120 | push offset format_printf_string
121 | call crt_printf
122 | add esp, 8
123 | push 10
124 | push offset format_printf_char
125 | call crt_printf
126 | add esp, 8
127 | mov eax, [ebp+8]
128 | mov ebx, 0
129 | mov [eax-8], ebx
130 | loop_for_start_label_1:
131 | mov eax, [ebp+8]
132 | mov eax, [eax-8]
133 | cmp eax, 0
134 | jl loop_for_end_label_2
135 | mov eax, [ebp+8]
136 | sub eax, 32
137 | mov ecx, [ebp+8]
138 | mov ebx, [ecx-8]
139 | shl ebx, 2
140 | sub eax, ebx
141 | mov ebx, 48
142 | mov [eax], ebx
143 | mov ebx, [ebp+8]
144 | sub ebx, 32
145 | mov edi, [ebp+8]
146 | mov ecx, [edi-8]
147 | shl ecx, 2
148 | sub ebx, ecx
149 | mov edx, [ebx]
150 | push edx
151 | push offset format_printf_char
152 | mov [ebp-20], eax
153 | mov [ebp-24], ebx
154 | mov [ebp-28], edx
155 | call crt_printf
156 | add esp, 8
157 | push 10
158 | push offset format_printf_char
159 | call crt_printf
160 | add esp, 8
161 | mov ebx, [ebp+8]
162 | mov eax, [ebx-8]
163 | add eax, -1
164 | mov ebx, [ebp+8]
165 | mov [ebx-8], eax
166 | mov [ebp-32], eax
167 | jmp loop_for_start_label_1
168 | loop_for_end_label_2:
169 | push offset string_6
170 | push offset format_printf_string
171 | call crt_printf
172 | add esp, 8
173 | push 10
174 | push offset format_printf_char
175 | call crt_printf
176 | add esp, 8
177 | mov eax, [ebp+8]
178 | mov ebx, 0
179 | mov [eax-8], ebx
180 | loop_for_start_label_3:
181 | mov eax, [ebp+8]
182 | mov eax, [eax-8]
183 | cmp eax, 2
184 | jg loop_for_end_label_4
185 | mov eax, [ebp+8]
186 | sub eax, 20
187 | mov ecx, [ebp+8]
188 | mov ebx, [ecx-8]
189 | shl ebx, 2
190 | sub eax, ebx
191 | mov ebx, [ebp+8]
192 | mov ebx, [ebx-8]
193 | mov [eax], ebx
194 | mov ecx, [ebp+8]
195 | sub ecx, 20
196 | mov edi, ebx
197 | shl edi, 2
198 | sub ecx, edi
199 | mov edx, [ecx]
200 | push edx
201 | push offset format_printf_int
202 | mov [ebp-36], eax
203 | mov eax, [ebp+8]
204 | mov [eax-8], ebx
205 | mov [ebp-40], ecx
206 | mov [ebp-44], edx
207 | call crt_printf
208 | add esp, 8
209 | push 10
210 | push offset format_printf_char
211 | call crt_printf
212 | add esp, 8
213 | mov ebx, [ebp+8]
214 | mov eax, [ebx-8]
215 | add eax, 1
216 | mov ebx, [ebp+8]
217 | mov [ebx-8], eax
218 | mov [ebp-48], eax
219 | jmp loop_for_start_label_3
220 | loop_for_end_label_4:
221 | push offset string_7
222 | push offset format_printf_string
223 | call crt_printf
224 | add esp, 8
225 | push 10
226 | push offset format_printf_char
227 | call crt_printf
228 | add esp, 8
229 | leave
230 | ret
231 | p_proc1_005A5D38 endp
232 |
233 | p_mov_005AB338 proc
234 | push ebp
235 | mov ebp, esp
236 | sub esp, 20
237 | mov eax, [ebp+20]
238 | cmp eax, 0
239 | jle condition_else_label_5
240 | mov eax, [ebp+20]
241 | sub eax, 1
242 | push [ebp+32]
243 | push [ebp+28]
244 | push [ebp+24]
245 | push eax
246 | push [ebp+12]
247 | push [ebp+16]
248 | push [ebp+8]
249 | mov [ebp-4], eax
250 | call p_mov_005AB338
251 | add esp, 28
252 | mov eax, [ebp+24]
253 | mov ebx, [eax]
254 | mov ecx, ebx
255 | add ecx, 1
256 | mov [eax], ecx
257 | push offset string_8
258 | push offset format_printf_string
259 | mov [ebp+24], eax
260 | mov [ebp-8], ebx
261 | mov [ebp-12], ecx
262 | call crt_printf
263 | add esp, 8
264 | mov eax, [ebp+24]
265 | mov ebx, [eax]
266 | push ebx
267 | push offset format_printf_int
268 | mov [ebp+24], eax
269 | mov [ebp-16], ebx
270 | call crt_printf
271 | add esp, 8
272 | push 10
273 | push offset format_printf_char
274 | call crt_printf
275 | add esp, 8
276 | push offset string_9
277 | push offset format_printf_string
278 | call crt_printf
279 | add esp, 8
280 | push [ebp+8]
281 | push offset format_printf_int
282 | call crt_printf
283 | add esp, 8
284 | push 10
285 | push offset format_printf_char
286 | call crt_printf
287 | add esp, 8
288 | push offset string_10
289 | push offset format_printf_string
290 | call crt_printf
291 | add esp, 8
292 | push [ebp+12]
293 | push offset format_printf_int
294 | call crt_printf
295 | add esp, 8
296 | push 10
297 | push offset format_printf_char
298 | call crt_printf
299 | add esp, 8
300 | mov eax, [ebp+20]
301 | sub eax, 1
302 | push [ebp+32]
303 | push [ebp+28]
304 | push [ebp+24]
305 | push eax
306 | push [ebp+8]
307 | push [ebp+12]
308 | push [ebp+16]
309 | mov [ebp-20], eax
310 | call p_mov_005AB338
311 | add esp, 28
312 | jmp condition_end_label_6
313 | condition_else_label_5:
314 | condition_end_label_6:
315 | leave
316 | ret
317 | p_mov_005AB338 endp
318 |
319 | f_func1_005AB200 proc
320 | push ebp
321 | mov ebp, esp
322 | sub esp, 4
323 | sub esp, 4
324 | sub esp, 4
325 | push offset string_11
326 | push offset format_printf_string
327 | call crt_printf
328 | add esp, 8
329 | push 10
330 | push offset format_printf_char
331 | call crt_printf
332 | add esp, 8
333 | push offset string_12
334 | push offset format_printf_string
335 | call crt_printf
336 | add esp, 8
337 | push 10
338 | push offset format_printf_char
339 | call crt_printf
340 | add esp, 8
341 | push [ebp+8]
342 | push offset format_printf_int
343 | call crt_printf
344 | add esp, 8
345 | push 10
346 | push offset format_printf_char
347 | call crt_printf
348 | add esp, 8
349 | push offset string_13
350 | push offset format_printf_string
351 | call crt_printf
352 | add esp, 8
353 | push [ebp+8]
354 | push offset format_printf_int
355 | call crt_printf
356 | add esp, 8
357 | push 10
358 | push offset format_printf_char
359 | call crt_printf
360 | add esp, 8
361 | mov ebx, 0
362 | mov [ebp-8], ebx
363 | mov eax, ebp
364 | sub eax, 8
365 | push [ebp+12]
366 | push ebp
367 | push eax
368 | push [ebp+8]
369 | push 2
370 | push 3
371 | push 1
372 | mov [ebp-12], eax
373 | call p_mov_005AB338
374 | add esp, 28
375 | push offset string_14
376 | push offset format_printf_string
377 | call crt_printf
378 | add esp, 8
379 | push [ebp-8]
380 | push offset format_printf_int
381 | call crt_printf
382 | add esp, 8
383 | push 10
384 | push offset format_printf_char
385 | call crt_printf
386 | add esp, 8
387 | push offset string_15
388 | push offset format_printf_string
389 | call crt_printf
390 | add esp, 8
391 | push [ebp-8]
392 | push offset format_printf_int
393 | call crt_printf
394 | add esp, 8
395 | push 10
396 | push offset format_printf_char
397 | call crt_printf
398 | add esp, 8
399 | mov eax, [ebp-8]
400 | mov [ebp-4], eax
401 | mov eax, [ebp-4]
402 | leave
403 | ret
404 | f_func1_005AB200 endp
405 |
406 | f_func2_005AB5A8 proc
407 | push ebp
408 | mov ebp, esp
409 | sub esp, 4
410 | sub esp, 0
411 | push offset string_16
412 | push offset format_printf_string
413 | call crt_printf
414 | add esp, 8
415 | push 10
416 | push offset format_printf_char
417 | call crt_printf
418 | add esp, 8
419 | push offset string_17
420 | push offset format_printf_string
421 | call crt_printf
422 | add esp, 8
423 | push 10
424 | push offset format_printf_char
425 | call crt_printf
426 | add esp, 8
427 | mov eax, [ebp+8]
428 | sub eax, 12
429 | push eax
430 | push offset format_scanf_char
431 | call crt_scanf
432 | add esp, 8
433 | mov eax, [ebp+8]
434 | sub eax, 16
435 | push eax
436 | push offset format_scanf_char
437 | call crt_scanf
438 | add esp, 8
439 | mov eax, [ebp+8]
440 | sub eax, 4
441 | push eax
442 | push offset format_scanf_int
443 | call crt_scanf
444 | add esp, 8
445 | mov eax, [ebp+8]
446 | mov eax, [eax-12]
447 | mov ebx, [ebp+8]
448 | cmp eax, [ebx-16]
449 | jg condition_else_label_7
450 | mov eax, [ebp+8]
451 | mov eax, [eax-12]
452 | mov ebx, [ebp+8]
453 | cmp eax, [ebx-16]
454 | jge condition_else_label_9
455 | mov eax, 0
456 | mov ebx, [ebp+8]
457 | cmp eax, [ebx-4]
458 | jne condition_else_label_11
459 | push offset string_18
460 | push offset format_printf_string
461 | call crt_printf
462 | add esp, 8
463 | push 10
464 | push offset format_printf_char
465 | call crt_printf
466 | add esp, 8
467 | jmp condition_end_label_12
468 | condition_else_label_11:
469 | push offset string_19
470 | push offset format_printf_string
471 | call crt_printf
472 | add esp, 8
473 | push 10
474 | push offset format_printf_char
475 | call crt_printf
476 | add esp, 8
477 | condition_end_label_12:
478 | jmp condition_end_label_10
479 | condition_else_label_9:
480 | mov eax, [ebp+8]
481 | mov eax, [eax-4]
482 | cmp eax, 0
483 | jl condition_else_label_13
484 | mov eax, [ebp+8]
485 | mov eax, [eax-4]
486 | cmp eax, 0
487 | jle condition_else_label_15
488 | push offset string_20
489 | push offset format_printf_string
490 | call crt_printf
491 | add esp, 8
492 | push 10
493 | push offset format_printf_char
494 | call crt_printf
495 | add esp, 8
496 | jmp condition_end_label_16
497 | condition_else_label_15:
498 | push offset string_21
499 | push offset format_printf_string
500 | call crt_printf
501 | add esp, 8
502 | push 10
503 | push offset format_printf_char
504 | call crt_printf
505 | add esp, 8
506 | condition_end_label_16:
507 | jmp condition_end_label_14
508 | condition_else_label_13:
509 | push offset string_22
510 | push offset format_printf_string
511 | call crt_printf
512 | add esp, 8
513 | push 10
514 | push offset format_printf_char
515 | call crt_printf
516 | add esp, 8
517 | condition_end_label_14:
518 | condition_end_label_10:
519 | jmp condition_end_label_8
520 | condition_else_label_7:
521 | mov eax, 0
522 | mov ebx, [ebp+8]
523 | cmp eax, [ebx-4]
524 | je condition_else_label_17
525 | push offset string_23
526 | push offset format_printf_string
527 | call crt_printf
528 | add esp, 8
529 | push 10
530 | push offset format_printf_char
531 | call crt_printf
532 | add esp, 8
533 | jmp condition_end_label_18
534 | condition_else_label_17:
535 | push offset string_24
536 | push offset format_printf_string
537 | call crt_printf
538 | add esp, 8
539 | push 10
540 | push offset format_printf_char
541 | call crt_printf
542 | add esp, 8
543 | condition_end_label_18:
544 | condition_end_label_8:
545 | push offset string_25
546 | push offset format_printf_string
547 | call crt_printf
548 | add esp, 8
549 | push 48
550 | push offset format_printf_char
551 | call crt_printf
552 | add esp, 8
553 | push 10
554 | push offset format_printf_char
555 | call crt_printf
556 | add esp, 8
557 | mov eax, 48
558 | mov [ebp-4], eax
559 | mov eax, [ebp-4]
560 | leave
561 | ret
562 | f_func2_005AB5A8 endp
563 |
564 | p_proc2_005AB610 proc
565 | push ebp
566 | mov ebp, esp
567 | sub esp, 20
568 | push offset string_26
569 | push offset format_printf_string
570 | call crt_printf
571 | add esp, 8
572 | push 10
573 | push offset format_printf_char
574 | call crt_printf
575 | add esp, 8
576 | push offset string_27
577 | push offset format_printf_string
578 | call crt_printf
579 | add esp, 8
580 | push 10
581 | push offset format_printf_char
582 | call crt_printf
583 | add esp, 8
584 | push [ebp+8]
585 | push offset format_printf_int
586 | call crt_printf
587 | add esp, 8
588 | push 10
589 | push offset format_printf_char
590 | call crt_printf
591 | add esp, 8
592 | push [ebp+12]
593 | push offset format_printf_int
594 | call crt_printf
595 | add esp, 8
596 | push 10
597 | push offset format_printf_char
598 | call crt_printf
599 | add esp, 8
600 | mov eax, [ebp+16]
601 | mov ebx, [eax]
602 | push ebx
603 | push offset format_printf_int
604 | mov [ebp+16], eax
605 | mov [ebp-4], ebx
606 | call crt_printf
607 | add esp, 8
608 | push 10
609 | push offset format_printf_char
610 | call crt_printf
611 | add esp, 8
612 | mov eax, 0
613 | mov ebx, [ebp+16]
614 | mov [ebx], eax
615 | mov [ebp+16], ebx
616 | loop_do_while_label_19:
617 | mov eax, [ebp+16]
618 | mov ebx, [eax]
619 | mov ecx, ebx
620 | add ecx, [ebp+12]
621 | mov [eax], ecx
622 | mov edi, [ebp+8]
623 | add edi, 1
624 | mov [ebp+8], edi
625 | mov [ebp+16], eax
626 | mov [ebp-8], ebx
627 | mov [ebp-12], ecx
628 | mov [ebp-16], edi
629 | mov eax, [ebp+8]
630 | cmp eax, [ebp+12]
631 | jl loop_do_while_label_19
632 | push offset string_28
633 | push offset format_printf_string
634 | call crt_printf
635 | add esp, 8
636 | mov eax, [ebp+16]
637 | mov ebx, [eax]
638 | push ebx
639 | push offset format_printf_int
640 | mov [ebp+16], eax
641 | mov [ebp-20], ebx
642 | call crt_printf
643 | add esp, 8
644 | push 10
645 | push offset format_printf_char
646 | call crt_printf
647 | add esp, 8
648 | push offset string_29
649 | push offset format_printf_string
650 | call crt_printf
651 | add esp, 8
652 | push 10
653 | push offset format_printf_char
654 | call crt_printf
655 | add esp, 8
656 | leave
657 | ret
658 | p_proc2_005AB610 endp
659 |
660 | _main:
661 | push ebp
662 | mov ebp, esp
663 | sub esp, 4
664 | sub esp, 4
665 | sub esp, 4
666 | sub esp, 4
667 | sub esp, 4
668 | sub esp, 12
669 | sub esp, 28
670 | push ebp
671 | call p_proc1_005A5D38
672 | add esp, 4
673 | mov eax, 3
674 | imul eax, 3
675 | mov ebx, 2
676 | imul ebx, 5
677 | mov ecx, eax
678 | sub ecx, ebx
679 | mov edi, ecx
680 | add edi, 1
681 | mov edx, ebp
682 | sub edx, 20
683 | mov esi, edi
684 | shl esi, 2
685 | sub edx, esi
686 | push ebp
687 | push edx
688 | push [ebp-8]
689 | push [ebp-4]
690 | mov [ebp-36], eax
691 | mov [ebp-40], ebx
692 | mov [ebp-44], ecx
693 | mov [ebp-48], edi
694 | mov [ebp-52], edx
695 | call p_proc2_005AB610
696 | add esp, 16
697 | push ebp
698 | push 4
699 | call f_func1_005AB200
700 | add esp, 8
701 | mov [ebp-56], eax
702 | mov ebx, [ebp-56]
703 | mov [ebp-4], ebx
704 | push ebp
705 | mov [ebp-56], ebx
706 | call f_func2_005AB5A8
707 | add esp, 4
708 | mov [ebp-60], eax
709 | mov ebx, [ebp-60]
710 | mov [ebp-12], ebx
711 | push 0
712 | call ExitProcess
713 | leave
714 | ret
715 | end _main
716 | end
717 |
--------------------------------------------------------------------------------
/08_最终结果/源代码/ErrorHandler.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/源代码/ErrorHandler.cpp
--------------------------------------------------------------------------------
/08_最终结果/源代码/ErrorHandler.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/源代码/ErrorHandler.h
--------------------------------------------------------------------------------
/08_最终结果/源代码/GrammarAnalyzer.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/源代码/GrammarAnalyzer.cpp
--------------------------------------------------------------------------------
/08_最终结果/源代码/GrammarAnalyzer.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/源代码/GrammarAnalyzer.h
--------------------------------------------------------------------------------
/08_最终结果/源代码/LexicalAnalyzer.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/源代码/LexicalAnalyzer.cpp
--------------------------------------------------------------------------------
/08_最终结果/源代码/LexicalAnalyzer.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/源代码/LexicalAnalyzer.h
--------------------------------------------------------------------------------
/08_最终结果/源代码/Quadruples.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/源代码/Quadruples.cpp
--------------------------------------------------------------------------------
/08_最终结果/源代码/Quadruples.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/源代码/Quadruples.h
--------------------------------------------------------------------------------
/08_最终结果/源代码/RegisterPool.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/源代码/RegisterPool.cpp
--------------------------------------------------------------------------------
/08_最终结果/源代码/RegisterPool.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/源代码/RegisterPool.h
--------------------------------------------------------------------------------
/08_最终结果/源代码/SemanticAnalyzer.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/源代码/SemanticAnalyzer.cpp
--------------------------------------------------------------------------------
/08_最终结果/源代码/SemanticAnalyzer.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/源代码/SemanticAnalyzer.h
--------------------------------------------------------------------------------
/08_最终结果/源代码/StackManager.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/源代码/StackManager.cpp
--------------------------------------------------------------------------------
/08_最终结果/源代码/StackManager.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/源代码/StackManager.h
--------------------------------------------------------------------------------
/08_最终结果/源代码/SymbolTableManager.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/源代码/SymbolTableManager.cpp
--------------------------------------------------------------------------------
/08_最终结果/源代码/SymbolTableManager.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/源代码/SymbolTableManager.h
--------------------------------------------------------------------------------
/08_最终结果/源代码/TargetCodeGenerator.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/源代码/TargetCodeGenerator.cpp
--------------------------------------------------------------------------------
/08_最终结果/源代码/TargetCodeGenerator.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/源代码/TargetCodeGenerator.h
--------------------------------------------------------------------------------
/08_最终结果/源代码/main.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/源代码/main.cpp
--------------------------------------------------------------------------------
/08_最终结果/源代码/type.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/源代码/type.h
--------------------------------------------------------------------------------
/08_最终结果/源代码/x86_instruction.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/08_最终结果/源代码/x86_instruction.h
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/README.md
--------------------------------------------------------------------------------
/扩充PL_0文法.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luice/BUAA-Compiler-Pascal-to-x86/da8ab33ada007eacdcbbdbfc0c5f866f5604b307/扩充PL_0文法.txt
--------------------------------------------------------------------------------
/测试程序.txt:
--------------------------------------------------------------------------------
1 | const TEN = 0010,
2 | NINE = +9,
3 | EIGHT1 = -8,
4 | A = 'A',
5 | ZERO = '0';
6 | var int1, int2: integer;
7 | ch1, ch2: char;
8 | intArray: array[3] of integer;
9 | chArray: array[1] of char;
10 | procedure proc1;
11 | begin
12 | write("proc1 start...");
13 | int1 := -(TEN + NINE) * EIGHT1 + 1024;
14 | ch1 := A;
15 | ch2 := ZERO;
16 | write("int1: ", int1);
17 | write("ch1: ", ch1);
18 | write("ch2: ", ch2);
19 | write("chArray:");
20 | for int2 := 0 downto 0 do
21 | begin
22 | chArray[int2] := ZERO;
23 | write(chArray[int2]);
24 | end;
25 | write("intArray:");
26 | for int2 := 0 to 2 do
27 | begin
28 | intArray[int2] := int2;
29 | write(intArray[int2])
30 | end;
31 | begin
32 | write("proc1 end.");
33 | end
34 | end;
35 | function func1(num: integer): integer;
36 | var steps: integer;
37 | procedure mov(tstart, tend, tmid, num: integer; var count: integer);
38 | begin
39 | if num > 0 then
40 | begin
41 | mov(tstart, tmid, tend, num-1, count);
42 | count := count + 1;
43 | write("step ", count);
44 | write("from: ", tstart);
45 | write("to: ", tend);
46 | mov(tmid, tend, tstart, num-1, count);
47 | end
48 | end;
49 | begin
50 | write("func1 start...");
51 | write("argument is num: integer");
52 | write(num);
53 | write("Hanoi Tower with levels: ", num);
54 | steps := 0;
55 | mov(1, 3, 2, num, steps);
56 | write("The total number of steps is: ", steps);
57 | write("func1 end with: ", steps);
58 | func1 := steps;
59 | end;
60 | function func2: char;
61 | begin
62 | write("func2 start...");
63 | write("Please input ch1, ch2, int1...");
64 | read(ch1, ch2);
65 | read(int1);
66 | if ch1 <= ch2 then
67 | if ch1 < ch2 then
68 | if 0 = int1 then
69 | write("<=")
70 | else
71 | write("<")
72 | else if int1 >= 0 then
73 | if int1 > 0 then
74 | write("<>")
75 | else
76 | write("=")
77 | else
78 | write("<>")
79 | else
80 | if 0 <> int1 then
81 | write(">")
82 | else
83 | write(">=");
84 | write("func2 end with: ", ZERO);
85 | func2 := ZERO;
86 | end;
87 | procedure proc2(int1, int2: integer; var int3: integer);
88 | begin
89 | write("proc2 start...");
90 | write("arguments are int1, int2: integer; var int3: integer");
91 | write(int1);
92 | write(int2);
93 | write(int3);
94 | int3 := 0;
95 | do
96 | begin
97 | int3 := int3 + int2;
98 | int1 := int1 + 1;
99 | end
100 | while int1 < int2;
101 | write("int3 now is :", int3);
102 | write("proc2 end.");
103 | end;
104 | begin
105 | proc1;
106 | proc2(int1, int2, intArray[3 * 3 - 2 * 5 + 1]);
107 | int1 := func1(4);
108 | ch1 := func2;
109 | end.
--------------------------------------------------------------------------------