├── .gitattributes ├── .vs └── compiler │ └── v15 │ ├── .suo │ ├── Browse.VC.db │ └── ipch │ └── AutoPCH │ └── 93933ba425dadd75 │ └── ANALYSIS.ipch ├── Debug ├── compiler.exe ├── compiler.ilk └── compiler.pdb ├── README.md ├── compiler.sln └── compiler ├── Analysis.cpp ├── Analysis.h ├── Debug ├── Analysis.obj ├── Base.obj ├── TableStack.obj ├── base.obj.enc ├── compiler.log ├── compiler.tlog │ ├── CL.command.1.tlog │ ├── CL.read.1.tlog │ ├── CL.write.1.tlog │ ├── compiler.lastbuildstate │ ├── link.command.1.tlog │ ├── link.read.1.tlog │ └── link.write.1.tlog ├── main.obj ├── vc141.idb └── vc141.pdb ├── Input.txt ├── Input2.txt ├── TableStack.cpp ├── TableStack.h ├── Table_Output.txt ├── compiler.vcxproj ├── compiler.vcxproj.filters └── main.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.vs/compiler/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/.vs/compiler/v15/.suo -------------------------------------------------------------------------------- /.vs/compiler/v15/Browse.VC.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/.vs/compiler/v15/Browse.VC.db -------------------------------------------------------------------------------- /.vs/compiler/v15/ipch/AutoPCH/93933ba425dadd75/ANALYSIS.ipch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/.vs/compiler/v15/ipch/AutoPCH/93933ba425dadd75/ANALYSIS.ipch -------------------------------------------------------------------------------- /Debug/compiler.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/Debug/compiler.exe -------------------------------------------------------------------------------- /Debug/compiler.ilk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/Debug/compiler.ilk -------------------------------------------------------------------------------- /Debug/compiler.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/Debug/compiler.pdb -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LL(1)语法分析器 2 | 3 | # Author 4 | -XingruiYi 5 | 6 | # 实现功能 7 | -绘制LL(1)语法分析表 8 | 9 | -可以消除直接左递归 10 | 11 | # 输入要求 12 | -在Input.txt文件中进行输入 13 | 14 | -每一个终结符,非终结符,|,->,用单个空格分开 15 | 16 | -其中#表示空字符 17 | 18 | -非终结字符末尾不能带“'”(为实现直接左递归消除专用符号) 19 | 20 | -其中Input2.txt为测试不含左递归语法的测试输入,需要修改文件名为Input.txt为之进行测试 21 | 22 | -TABLE_Output.txt文件为输出文件 -------------------------------------------------------------------------------- /compiler.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26730.16 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "compiler", "compiler\compiler.vcxproj", "{3C3E5FAF-12DE-48DC-A15B-8E7F1E890DAD}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {3C3E5FAF-12DE-48DC-A15B-8E7F1E890DAD}.Debug|x64.ActiveCfg = Debug|x64 17 | {3C3E5FAF-12DE-48DC-A15B-8E7F1E890DAD}.Debug|x64.Build.0 = Debug|x64 18 | {3C3E5FAF-12DE-48DC-A15B-8E7F1E890DAD}.Debug|x86.ActiveCfg = Debug|Win32 19 | {3C3E5FAF-12DE-48DC-A15B-8E7F1E890DAD}.Debug|x86.Build.0 = Debug|Win32 20 | {3C3E5FAF-12DE-48DC-A15B-8E7F1E890DAD}.Release|x64.ActiveCfg = Release|x64 21 | {3C3E5FAF-12DE-48DC-A15B-8E7F1E890DAD}.Release|x64.Build.0 = Release|x64 22 | {3C3E5FAF-12DE-48DC-A15B-8E7F1E890DAD}.Release|x86.ActiveCfg = Release|Win32 23 | {3C3E5FAF-12DE-48DC-A15B-8E7F1E890DAD}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {19EA572C-FAA4-4968-8777-76D9D1C49C9F} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /compiler/Analysis.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/compiler/Analysis.cpp -------------------------------------------------------------------------------- /compiler/Analysis.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/compiler/Analysis.h -------------------------------------------------------------------------------- /compiler/Debug/Analysis.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/compiler/Debug/Analysis.obj -------------------------------------------------------------------------------- /compiler/Debug/Base.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/compiler/Debug/Base.obj -------------------------------------------------------------------------------- /compiler/Debug/TableStack.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/compiler/Debug/TableStack.obj -------------------------------------------------------------------------------- /compiler/Debug/base.obj.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/compiler/Debug/base.obj.enc -------------------------------------------------------------------------------- /compiler/Debug/compiler.log: -------------------------------------------------------------------------------- 1 |  Analysis.cpp 2 | c:\users\h3743\desktop\编译原理\编译原理project-易兴睿-516021910717\compiler\analysis.cpp(5): warning C4018: “<”: 有符号/无符号不匹配 3 | c:\users\h3743\desktop\编译原理\编译原理project-易兴睿-516021910717\compiler\analysis.cpp(12): warning C4018: “<”: 有符号/无符号不匹配 4 | c:\users\h3743\desktop\编译原理\编译原理project-易兴睿-516021910717\compiler\analysis.cpp(21): warning C4018: “<”: 有符号/无符号不匹配 5 | c:\users\h3743\desktop\编译原理\编译原理project-易兴睿-516021910717\compiler\analysis.cpp(144): warning C4018: “<”: 有符号/无符号不匹配 6 | c:\users\h3743\desktop\编译原理\编译原理project-易兴睿-516021910717\compiler\analysis.cpp(154): warning C4018: “<”: 有符号/无符号不匹配 7 | c:\users\h3743\desktop\编译原理\编译原理project-易兴睿-516021910717\compiler\analysis.cpp(171): warning C4018: “<”: 有符号/无符号不匹配 8 | c:\users\h3743\desktop\编译原理\编译原理project-易兴睿-516021910717\compiler\analysis.cpp(185): warning C4018: “<”: 有符号/无符号不匹配 9 | c:\users\h3743\desktop\编译原理\编译原理project-易兴睿-516021910717\compiler\analysis.cpp(204): warning C4018: “<”: 有符号/无符号不匹配 10 | c:\users\h3743\desktop\编译原理\编译原理project-易兴睿-516021910717\compiler\analysis.cpp(220): warning C4018: “<”: 有符号/无符号不匹配 11 | c:\users\h3743\desktop\编译原理\编译原理project-易兴睿-516021910717\compiler\analysis.cpp(225): warning C4018: “<”: 有符号/无符号不匹配 12 | c:\users\h3743\desktop\编译原理\编译原理project-易兴睿-516021910717\compiler\analysis.cpp(232): warning C4018: “<”: 有符号/无符号不匹配 13 | c:\users\h3743\desktop\编译原理\编译原理project-易兴睿-516021910717\compiler\analysis.cpp(272): warning C4018: “<”: 有符号/无符号不匹配 14 | c:\users\h3743\desktop\编译原理\编译原理project-易兴睿-516021910717\compiler\analysis.cpp(303): warning C4018: “<”: 有符号/无符号不匹配 15 | c:\users\h3743\desktop\编译原理\编译原理project-易兴睿-516021910717\compiler\analysis.cpp(314): warning C4018: “<”: 有符号/无符号不匹配 16 | c:\users\h3743\desktop\编译原理\编译原理project-易兴睿-516021910717\compiler\analysis.cpp(333): warning C4018: “<”: 有符号/无符号不匹配 17 | c:\users\h3743\desktop\编译原理\编译原理project-易兴睿-516021910717\compiler\analysis.cpp(343): warning C4018: “<”: 有符号/无符号不匹配 18 | compiler.vcxproj -> C:\Users\h3743\Desktop\编译原理\编译原理Project-易兴睿-516021910717\Debug\compiler.exe 19 | compiler.vcxproj -> C:\Users\h3743\Desktop\编译原理\编译原理Project-易兴睿-516021910717\Debug\compiler.pdb (Partial PDB) 20 | -------------------------------------------------------------------------------- /compiler/Debug/compiler.tlog/CL.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/compiler/Debug/compiler.tlog/CL.command.1.tlog -------------------------------------------------------------------------------- /compiler/Debug/compiler.tlog/CL.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/compiler/Debug/compiler.tlog/CL.read.1.tlog -------------------------------------------------------------------------------- /compiler/Debug/compiler.tlog/CL.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/compiler/Debug/compiler.tlog/CL.write.1.tlog -------------------------------------------------------------------------------- /compiler/Debug/compiler.tlog/compiler.lastbuildstate: -------------------------------------------------------------------------------- 1 | #TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.15063.0 2 | Debug|Win32|C:\Users\h3743\Desktop\编译原理\编译原理Project-易兴睿-516021910717\| 3 | -------------------------------------------------------------------------------- /compiler/Debug/compiler.tlog/link.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/compiler/Debug/compiler.tlog/link.command.1.tlog -------------------------------------------------------------------------------- /compiler/Debug/compiler.tlog/link.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/compiler/Debug/compiler.tlog/link.read.1.tlog -------------------------------------------------------------------------------- /compiler/Debug/compiler.tlog/link.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/compiler/Debug/compiler.tlog/link.write.1.tlog -------------------------------------------------------------------------------- /compiler/Debug/main.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/compiler/Debug/main.obj -------------------------------------------------------------------------------- /compiler/Debug/vc141.idb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/compiler/Debug/vc141.idb -------------------------------------------------------------------------------- /compiler/Debug/vc141.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/compiler/Debug/vc141.pdb -------------------------------------------------------------------------------- /compiler/Input.txt: -------------------------------------------------------------------------------- 1 | E -> E + T | T 2 | T -> T * F | F 3 | F -> id | ( E ) 4 | -------------------------------------------------------------------------------- /compiler/Input2.txt: -------------------------------------------------------------------------------- 1 | E -> T E' 2 | E' -> + T E' | # 3 | T -> F T' 4 | T' -> * F T' | # 5 | F -> ( E ) | id 6 | 7 | -------------------------------------------------------------------------------- /compiler/TableStack.cpp: -------------------------------------------------------------------------------- 1 | #include"TableStack.h" 2 | 3 | void TableStack::get_table() 4 | { 5 | for (int i = 0; i < T; i++) 6 | { 7 | string tmp = analysis_str[i].right[0]; 8 | if (!isNotTerminal(tmp)) 9 | { 10 | if (tmp != "#") 11 | tableMap[get_index(analysis_str[i].left)][get_non_index(tmp)] = i; 12 | if (tmp == "#") 13 | { 14 | set::iterator it; 15 | for (it = follow_set[get_index(analysis_str[i].left)].begin(); it != follow_set[get_index(analysis_str[i].left)].end(); it++) 16 | { 17 | tableMap[get_index(analysis_str[i].left)][get_non_index(*it)] = i; 18 | } 19 | } 20 | } 21 | else 22 | { 23 | set::iterator ti; 24 | for (ti = first_set[get_index(tmp)].begin(); ti != first_set[get_index(tmp)].end(); ti++) 25 | { 26 | tableMap[get_index(analysis_str[i].left)][get_non_index(*ti)] = i; 27 | } 28 | if (first_set[get_index(tmp)].count("#") != 0) 29 | { 30 | set::iterator it; 31 | for (it = follow_set[get_index(analysis_str[i].left)].begin(); it != follow_set[get_index(analysis_str[i].left)].end(); it++) 32 | { 33 | tableMap[get_index(analysis_str[i].left)][get_non_index(*it)] = i; 34 | } 35 | } 36 | } 37 | } 38 | } 39 | 40 | void TableStack::print_out() 41 | { 42 | ofstream Out("Table_Output.txt"); 43 | Out << setw(10) << '\0'; 44 | for (int i = 0; i < ter_withoutblack.size(); i++) 45 | { 46 | string tercopy; 47 | tercopy += " "; 48 | tercopy += ter_withoutblack[i]; 49 | Out << left << setw(15) << tercopy; 50 | } 51 | Out << endl; 52 | for (int i = 0; i < nonterminal.size(); i++) 53 | { 54 | string nonter; 55 | nonter = nonterminal[i] + ": "; 56 | Out << setw(10) << nonter; 57 | for (int j = 0; j < ter_withoutblack.size(); j++) 58 | { 59 | if (tableMap[i][j] == -1) 60 | Out << setw(15) << '\0'; 61 | else 62 | { 63 | int k = 0; 64 | string ss; 65 | ss += nonterminal[i]; 66 | ss += "->"; 67 | while (analysis_str[tableMap[i][j]].right[k] != "") 68 | { 69 | ss += analysis_str[tableMap[i][j]].right[k]; 70 | k++; 71 | } 72 | Out << left << setw(15) << ss; 73 | } 74 | } 75 | Out << endl; 76 | } 77 | Out.close(); 78 | } 79 | 80 | void TableStack::manage() 81 | { 82 | inputAndSolve(); 83 | display(); 84 | get_table(); 85 | print_out(); 86 | return; 87 | } -------------------------------------------------------------------------------- /compiler/TableStack.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/compiler/TableStack.h -------------------------------------------------------------------------------- /compiler/Table_Output.txt: -------------------------------------------------------------------------------- 1 | + * id ( ) $ 2 | E: E->TE' E->TE' 3 | T: T->FT' T->FT' 4 | F: F->id F->(E) 5 | E': E'->+TE' E'-># E'-># 6 | T': T'-># T'->*FT' T'-># T'-># 7 | -------------------------------------------------------------------------------- /compiler/compiler.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {3C3E5FAF-12DE-48DC-A15B-8E7F1E890DAD} 24 | compiler 25 | 10.0.15063.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v141 32 | MultiByte 33 | 34 | 35 | Application 36 | false 37 | v141 38 | true 39 | MultiByte 40 | 41 | 42 | Application 43 | true 44 | v141 45 | MultiByte 46 | 47 | 48 | Application 49 | false 50 | v141 51 | true 52 | MultiByte 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | Level3 76 | Disabled 77 | true 78 | 79 | 80 | 81 | 82 | Level3 83 | Disabled 84 | true 85 | 86 | 87 | 88 | 89 | Level3 90 | MaxSpeed 91 | true 92 | true 93 | true 94 | 95 | 96 | true 97 | true 98 | 99 | 100 | 101 | 102 | Level3 103 | MaxSpeed 104 | true 105 | true 106 | true 107 | 108 | 109 | true 110 | true 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /compiler/compiler.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 26 | 27 | 源文件 28 | 29 | 30 | 源文件 31 | 32 | 33 | 源文件 34 | 35 | 36 | -------------------------------------------------------------------------------- /compiler/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiXR/LL1-Grammar/685aca612d0c7e65216f2d3d4e139926c0196fa2/compiler/main.cpp --------------------------------------------------------------------------------