├── 编译器源码 ├── id_table.txt ├── FIRST.txt ├── FOLLOW.txt ├── SELECT.txt ├── main.cpp ├── main.exe ├── struct.h ├── grammar.txt ├── pre_list.txt ├── process.txt ├── main_table.txt ├── translation.h ├── word_analysis.h ├── grammar_analysis.h ├── number_table.txt ├── programe.txt ├── four_exp.txt ├── twox.txt └── assemble.txt └── README.txt /编译器源码/id_table.txt: -------------------------------------------------------------------------------- 1 | ans 2 | main 3 | n 4 | -------------------------------------------------------------------------------- /编译器源码/FIRST.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fankc/CCompiler/HEAD/编译器源码/FIRST.txt -------------------------------------------------------------------------------- /编译器源码/FOLLOW.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fankc/CCompiler/HEAD/编译器源码/FOLLOW.txt -------------------------------------------------------------------------------- /编译器源码/SELECT.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fankc/CCompiler/HEAD/编译器源码/SELECT.txt -------------------------------------------------------------------------------- /编译器源码/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fankc/CCompiler/HEAD/编译器源码/main.cpp -------------------------------------------------------------------------------- /编译器源码/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fankc/CCompiler/HEAD/编译器源码/main.exe -------------------------------------------------------------------------------- /编译器源码/struct.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fankc/CCompiler/HEAD/编译器源码/struct.h -------------------------------------------------------------------------------- /编译器源码/grammar.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fankc/CCompiler/HEAD/编译器源码/grammar.txt -------------------------------------------------------------------------------- /编译器源码/pre_list.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fankc/CCompiler/HEAD/编译器源码/pre_list.txt -------------------------------------------------------------------------------- /编译器源码/process.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fankc/CCompiler/HEAD/编译器源码/process.txt -------------------------------------------------------------------------------- /编译器源码/main_table.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fankc/CCompiler/HEAD/编译器源码/main_table.txt -------------------------------------------------------------------------------- /编译器源码/translation.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fankc/CCompiler/HEAD/编译器源码/translation.h -------------------------------------------------------------------------------- /编译器源码/word_analysis.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fankc/CCompiler/HEAD/编译器源码/word_analysis.h -------------------------------------------------------------------------------- /编译器源码/grammar_analysis.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fankc/CCompiler/HEAD/编译器源码/grammar_analysis.h -------------------------------------------------------------------------------- /编译器源码/number_table.txt: -------------------------------------------------------------------------------- 1 | 1.int 2.double 2 | 3 | 1 0 4 | 1 0 5 | 1 10 6 | 1 10 7 | 1 10 8 | 1 0 9 | -------------------------------------------------------------------------------- /编译器源码/programe.txt: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | int n; 4 | int ans; 5 | ans = 0; 6 | cin >> n; 7 | while(n > 0) 8 | { 9 | ans = ans * 10 + n % 10; 10 | n = n / 10; 11 | } 12 | cout << ans; 13 | return 0; 14 | } -------------------------------------------------------------------------------- /编译器源码/four_exp.txt: -------------------------------------------------------------------------------- 1 | ============================================================= 2 | Four_expression 3 | ============================================================= 4 | (0) ( = , 0 , _ , ans ) 5 | (1) ( cin , _ , _ , n ) 6 | (2) ( > , n , 0 , t0 ) 7 | (3) ( J= , t0 , 1 , (5) ) 8 | (4) ( J , _ , _ , (12) ) 9 | (5) ( * , ans , 10 , t1 ) 10 | (6) ( % , n , 10 , t2 ) 11 | (7) ( + , t1 , t2 , t3 ) 12 | (8) ( = , t3 , _ , ans ) 13 | (9) ( / , n , 10 , t4 ) 14 | (10) ( = , t4 , _ , n ) 15 | (11) ( J , _ , _ , (3) ) 16 | (12) ( cout , _ , _ , ans ) 17 | -------------------------------------------------------------------------------- /编译器源码/twox.txt: -------------------------------------------------------------------------------- 1 | int type 1 2 | main id 2 3 | ( ( 4 4 | ) ) 4 5 | { { 4 6 | int type 1 7 | n id 2 8 | ; ; 4 9 | int type 1 10 | ans id 2 11 | ; ; 4 12 | ans id 2 13 | = = 6 14 | 0 number 3 15 | ; ; 4 16 | cin cin 1 17 | >> >> 5 18 | n id 2 19 | ; ; 4 20 | while while 1 21 | ( ( 4 22 | n id 2 23 | > > 5 24 | 0 number 3 25 | ) ) 4 26 | { { 4 27 | ans id 2 28 | = = 6 29 | ans id 2 30 | * * 5 31 | 10 number 3 32 | + + 5 33 | n id 2 34 | % % 5 35 | 10 number 3 36 | ; ; 4 37 | n id 2 38 | = = 6 39 | n id 2 40 | / / 5 41 | 10 number 3 42 | ; ; 4 43 | } } 4 44 | cout cout 1 45 | << << 5 46 | ans id 2 47 | ; ; 4 48 | return return 1 49 | 0 number 3 50 | ; ; 4 51 | } } 4 52 | -------------------------------------------------------------------------------- /编译器源码/assemble.txt: -------------------------------------------------------------------------------- 1 | =================================================================== 2 | Assemble_code 3 | =================================================================== 4 | (0) MOV ans , 0 5 | (1) IN n 6 | (2) CMP n , 0 7 | (3) JG (5) 8 | (4) MOV t0 , 0 9 | (5) MOV t0 , 1 10 | (6) CMP t0 , 1 11 | (7) JZ (8) 12 | (8) JMP (24) 13 | (9) MOV R1 , ans 14 | (10) MUL R1 , 10 15 | (11) MOV t1 , R1 16 | (12) MOV R2 , n 17 | (13) MOD R2 , 10 18 | (14) MOV t2 , R2 19 | (15) MOV R3 , t1 20 | (16) ADD R3 , t2 21 | (17) MOV t3 , R3 22 | (18) MOV ans , t3 23 | (19) MOV R4 , n 24 | (20) DIV R4 , 10 25 | (21) MOV t4 , R4 26 | (22) MOV n , t4 27 | (23) JMP (3) 28 | (24) OUT ans 29 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | 文件清单: 2 | 1.programe.txt 输入文件(待分析程序) 3 | 2.grammar.txt 输入文件(语法规则) 4 | 3.main_table.txt 词法分析结果(主表) 5 | 4.id_table.txt 词法分析结果(标识符表) 6 | 5.number_table.txt 词法分析结果(数字表) 7 | 6.twox.txt 词法分析结果(三元式) 8 | 7.FIRST.txt 语法分析结果(FIRST集) 9 | 8.FOLLOW.txt 语法分析结果(FOLLOW集) 10 | 9.SELECT.txt 语法分析结果(SELECT集) 11 | 10.pre_list.txt 语法分析结果(分析表) 12 | 11.process.txt 语法分析结果(语法分析过程) 13 | 12.four_exp.txt 中间代码(四元式) 14 | 13.assemble.txt 目标代码(汇编语言) 15 | 14.struct.h 程序总体数据结构 16 | 15.word_analysis.h 词法分析 17 | 16.grammar_analysis.h 语法分析 18 | 17.translation.h 中间代码、目标代码生成 19 | 18.main.cpp 主程序 20 | 19.main.exe 执行文件 21 | 20.README.txt 帮助文件 22 | 23 | 24 | 程序使用: 25 | 将所有文件放于同一文件夹下 26 | 在programe.txt中输入待分析程序,双击可执行文件(main.exe)即可输出结果(以文件形式输出) 27 | --------------------------------------------------------------------------------