├── 词法分析
├── 103词法分析程序报告.doc
├── LexicalAnalyzer
│ ├── .classpath
│ ├── .project
│ ├── .settings
│ │ └── org.eclipse.jdt.core.prefs
│ ├── bin
│ │ ├── Analyzer.class
│ │ ├── IDType.class
│ │ ├── NumType.class
│ │ └── Token.class
│ ├── input.txt
│ ├── output.txt
│ └── src
│ │ ├── Analyzer.java
│ │ ├── IDType.java
│ │ ├── NumType.java
│ │ └── Token.java
├── 查看程序说明文档.txt
└── 词法分析的DFA.jpg
└── 语法分析
├── 103语法分析程序报告.doc
├── SyntaxAnalyzer
├── .classpath
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
├── bin
│ ├── Production.class
│ └── SyntaxAnanlyzer.class
├── input.txt
├── output.txt
└── src
│ ├── Production.java
│ └── SyntaxAnanlyzer.java
├── 分析表.jpg
├── 查看程序说明文档.txt
└── 语法分析的状态转换图.jpg
/词法分析/103词法分析程序报告.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FannyChung/Compiler/d10338c5d3193f8e59d06f87e0905cf80361c011/词法分析/103词法分析程序报告.doc
--------------------------------------------------------------------------------
/词法分析/LexicalAnalyzer/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/词法分析/LexicalAnalyzer/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | LexicalAnalyzer
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/词法分析/LexicalAnalyzer/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.7
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=1.7
12 |
--------------------------------------------------------------------------------
/词法分析/LexicalAnalyzer/bin/Analyzer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FannyChung/Compiler/d10338c5d3193f8e59d06f87e0905cf80361c011/词法分析/LexicalAnalyzer/bin/Analyzer.class
--------------------------------------------------------------------------------
/词法分析/LexicalAnalyzer/bin/IDType.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FannyChung/Compiler/d10338c5d3193f8e59d06f87e0905cf80361c011/词法分析/LexicalAnalyzer/bin/IDType.class
--------------------------------------------------------------------------------
/词法分析/LexicalAnalyzer/bin/NumType.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FannyChung/Compiler/d10338c5d3193f8e59d06f87e0905cf80361c011/词法分析/LexicalAnalyzer/bin/NumType.class
--------------------------------------------------------------------------------
/词法分析/LexicalAnalyzer/bin/Token.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FannyChung/Compiler/d10338c5d3193f8e59d06f87e0905cf80361c011/词法分析/LexicalAnalyzer/bin/Token.class
--------------------------------------------------------------------------------
/词法分析/LexicalAnalyzer/input.txt:
--------------------------------------------------------------------------------
1 | if(a`>0)
2 | x~ = \
--------------------------------------------------------------------------------
/词法分析/LexicalAnalyzer/output.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FannyChung/Compiler/d10338c5d3193f8e59d06f87e0905cf80361c011/词法分析/LexicalAnalyzer/output.txt
--------------------------------------------------------------------------------
/词法分析/LexicalAnalyzer/src/Analyzer.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FannyChung/Compiler/d10338c5d3193f8e59d06f87e0905cf80361c011/词法分析/LexicalAnalyzer/src/Analyzer.java
--------------------------------------------------------------------------------
/词法分析/LexicalAnalyzer/src/IDType.java:
--------------------------------------------------------------------------------
1 | import java.util.Vector;
2 |
3 | /**
4 | *
5 | */
6 |
7 | /**
8 | * @author zhongfang
9 | *
10 | */
11 | public class IDType {
12 |
13 | private static int numOfID = 0;
14 | private static Vector iDs = new Vector<>();
15 | private final static String keywords[] = { "abstract", "assert", "boolean",
16 | "break", "byte", "case", "catch", "char", "class", "const",
17 | "continue", "default", "do", "double", "else", "enum", "extends",
18 | "final", "finally", "float", "for", "goto", "if", "implements",
19 | "import", "instanceof", "int", "interface", "long", "native",
20 | "new", "package", "private", "protected", "public", "return",
21 | "short", "static", "strictfp", "super", "switch", "synchronized",
22 | "this", "thorw", "throws", "transient", "try", "void", "volatile",
23 | "while" };
24 |
25 | /**
26 | *
27 | */
28 | public IDType() {
29 | // TODO Auto-generated constructor stub
30 | }
31 |
32 | public static boolean isKeywords(String s) {
33 | for (String string : keywords)
34 | if (s.equals(string))
35 | return true;
36 | return false;
37 | }
38 |
39 | public static void insertID(String string) {
40 | iDs.addElement(string);
41 | numOfID++;
42 | }
43 |
44 | public static int findID(String s) {
45 | return iDs.indexOf(s);
46 | }
47 |
48 | /**
49 | * @return the numOfID
50 | */
51 | public static int getNumOfID() {
52 | return numOfID;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/词法分析/LexicalAnalyzer/src/NumType.java:
--------------------------------------------------------------------------------
1 | import java.util.Vector;
2 |
3 | /**
4 | *
5 | */
6 |
7 | /**
8 | * @author zhongfang
9 | *
10 | */
11 | public class NumType {
12 |
13 | private static int numOfN = 0;
14 | private static Vector nums = new Vector();
15 |
16 | /**
17 | *
18 | */
19 | public NumType() {
20 | // TODO Auto-generated constructor stub
21 | }
22 |
23 | /**
24 | * @return the numOfN
25 | */
26 | public static int getNumOfN() {
27 | return numOfN;
28 | }
29 |
30 | public static int findNum(String s) {
31 | return nums.indexOf(s);
32 | }
33 |
34 | public static void insertNum(String a) {
35 | nums.addElement(a);
36 | numOfN++;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/词法分析/LexicalAnalyzer/src/Token.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 |
5 | /**
6 | * @author zhongfang
7 | *
8 | */
9 | public class Token {
10 |
11 | private String name;
12 | private String type;
13 | private String location;
14 |
15 | @Override
16 | public String toString() {
17 | String string = "< " + this.name + " , " + this.type + " , "
18 | + this.location + " >";
19 | return string;
20 | }
21 |
22 | public void display() {
23 | System.out.println("< " + this.name + " , " + this.type + " , "
24 | + this.location + " >");
25 | }
26 |
27 | /**
28 | * @return the name
29 | */
30 | public String getName() {
31 | return name;
32 | }
33 |
34 | /**
35 | * @param name
36 | * the name to set
37 | */
38 | public void setName(String name) {
39 | this.name = name;
40 | }
41 |
42 | /**
43 | * @return the type
44 | */
45 | public String getType() {
46 | return type;
47 | }
48 |
49 | /**
50 | * @param type
51 | * the type to set
52 | */
53 | public void setType(String type) {
54 | this.type = type;
55 | }
56 |
57 | /**
58 | * @return the location
59 | */
60 | public String getLocation() {
61 | return location;
62 | }
63 |
64 | /**
65 | * @param location
66 | * the location to set
67 | */
68 | public void setLocation(String location) {
69 | this.location = location;
70 | }
71 |
72 | /**
73 | *
74 | */
75 | public Token() {
76 | // TODO Auto-generated constructor stub
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/词法分析/查看程序说明文档.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FannyChung/Compiler/d10338c5d3193f8e59d06f87e0905cf80361c011/词法分析/查看程序说明文档.txt
--------------------------------------------------------------------------------
/词法分析/词法分析的DFA.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FannyChung/Compiler/d10338c5d3193f8e59d06f87e0905cf80361c011/词法分析/词法分析的DFA.jpg
--------------------------------------------------------------------------------
/语法分析/103语法分析程序报告.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FannyChung/Compiler/d10338c5d3193f8e59d06f87e0905cf80361c011/语法分析/103语法分析程序报告.doc
--------------------------------------------------------------------------------
/语法分析/SyntaxAnalyzer/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/语法分析/SyntaxAnalyzer/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | SyntaxAnalyzer
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/语法分析/SyntaxAnalyzer/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.7
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=1.7
12 |
--------------------------------------------------------------------------------
/语法分析/SyntaxAnalyzer/bin/Production.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FannyChung/Compiler/d10338c5d3193f8e59d06f87e0905cf80361c011/语法分析/SyntaxAnalyzer/bin/Production.class
--------------------------------------------------------------------------------
/语法分析/SyntaxAnalyzer/bin/SyntaxAnanlyzer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FannyChung/Compiler/d10338c5d3193f8e59d06f87e0905cf80361c011/语法分析/SyntaxAnalyzer/bin/SyntaxAnanlyzer.class
--------------------------------------------------------------------------------
/语法分析/SyntaxAnalyzer/input.txt:
--------------------------------------------------------------------------------
1 | i+i+i*i
2 | i++
--------------------------------------------------------------------------------
/语法分析/SyntaxAnalyzer/output.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FannyChung/Compiler/d10338c5d3193f8e59d06f87e0905cf80361c011/语法分析/SyntaxAnalyzer/output.txt
--------------------------------------------------------------------------------
/语法分析/SyntaxAnalyzer/src/Production.java:
--------------------------------------------------------------------------------
1 | import java.util.Vector;
2 |
3 | /**
4 | *
5 | */
6 |
7 | /**
8 | * @author zhongfang
9 | *
10 | */
11 | public class Production {
12 |
13 | private String[] productions={"S'->E","E->E+T","E->T","T->T*F","T->F","F->(E)","F->i"};
14 | private int[] numOfP={1,3,1,3,1,3,1};
15 | private Vector productionList=new Vector();
16 |
17 | /**
18 | *
19 | */
20 | public Production() {
21 | for(String st:productions)
22 | productionList.addElement(st);
23 | }
24 |
25 |
26 | public String getProduction(int i){
27 | // return productionList.get(i);
28 | return productions[i];
29 | }
30 |
31 | public int getNumOfP(int i){
32 | return numOfP[i];
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/语法分析/SyntaxAnalyzer/src/SyntaxAnanlyzer.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FannyChung/Compiler/d10338c5d3193f8e59d06f87e0905cf80361c011/语法分析/SyntaxAnalyzer/src/SyntaxAnanlyzer.java
--------------------------------------------------------------------------------
/语法分析/分析表.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FannyChung/Compiler/d10338c5d3193f8e59d06f87e0905cf80361c011/语法分析/分析表.jpg
--------------------------------------------------------------------------------
/语法分析/查看程序说明文档.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FannyChung/Compiler/d10338c5d3193f8e59d06f87e0905cf80361c011/语法分析/查看程序说明文档.txt
--------------------------------------------------------------------------------
/语法分析/语法分析的状态转换图.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FannyChung/Compiler/d10338c5d3193f8e59d06f87e0905cf80361c011/语法分析/语法分析的状态转换图.jpg
--------------------------------------------------------------------------------