Skip to content

Commit a1441e8

Browse files
committed
修改输出格式以满足要求
1 parent eb560a6 commit a1441e8

12 files changed

+9
-51
lines changed

output/First集合.txt renamed to output/First集合.tsv

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
First列表结果如下: --------------------
2-
总共有 68 条数据
3-
41
argFunctionR [,]
52
<= [<=]
63
decl [const, int]

output/Follow集合.txt renamed to output/Follow集合.tsv

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
Follow列表结果如下: --------------------
2-
总共有 43 条数据
3-
41
argFunctionR [), #]
52
eqExpAtom [=, ,, ;, ), #]
63
decl [const, void, int, ;, {, return, +, -, !, Ident, (, INT, }, #]

output/分析表.txt renamed to output/分析表.tsv

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
预测表结果如下: --------------------
2-
总共有 217 条数据
3-
41
{横坐标: ( 纵坐标: constInitVal} 文法: constInitVal->[constExp]
52
{横坐标: >= 纵坐标: addExpAtom} 文法: addExpAtom->[$]
63
{横坐标: < 纵坐标: addExpAtom} 文法: addExpAtom->[$]

output/文法.txt renamed to output/文法.tsv

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
文法解析结果如下: --------------------
2-
总共有 77 条数据
3-
41
文法左侧: program 文法右侧: [compUnit]
52
文法左侧: compUnit 文法右侧: [decl, compUnit]
63
文法左侧: compUnit 文法右侧: [funcDef, compUnit]

output/终结符.txt renamed to output/终结符.tsv

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
从文法中解析的终结符结果如下: --------------------
2-
总共有 45 条数据
3-
41
const
52
;
63
,

output/词法分析产生的中间结果.txt renamed to output/词法分析产生的中间结果.tsv

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
词法分析的中间结果结果如下: --------------------
2-
总共有 57 条数据
3-
41
int
52
Ident
63
=

output/非终结符.txt renamed to output/非终结符.tsv

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
从文法中解析的非终结符结果如下: --------------------
2-
总共有 43 条数据
3-
41
program
52
compUnit
63
decl
File renamed without changes.
File renamed without changes.

src/Config.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ public class Config {
88
// static String lexInputPath = ".\\input\\4.txt";
99
static String lexInputPath = ".\\input\\5.txt";
1010

11-
static String formulaPath = ".\\output\\文法.txt";
12-
static String firstTablePath = ".\\output\\First集合.txt";
13-
static String followTablePath = ".\\output\\Follow集合.txt";
14-
static String predictMapPath = ".\\output\\分析表.txt";
15-
static String terminalPath = ".\\output\\终结符.txt";
16-
static String nonTerminalPath = ".\\output\\非终结符.txt";
17-
static String lexiconMiddleResult = ".\\output\\词法分析产生的中间结果.txt";
18-
static String parseResultPath = ".\\result\\语法分析结果.txt";
19-
static String lexiconResultPath = ".\\result\\词法分析结果.txt";
11+
static String formulaPath = ".\\output\\文法.tsv";
12+
static String firstTablePath = ".\\output\\First集合.tsv";
13+
static String followTablePath = ".\\output\\Follow集合.tsv";
14+
static String predictMapPath = ".\\output\\分析表.tsv";
15+
static String terminalPath = ".\\output\\终结符.tsv";
16+
static String nonTerminalPath = ".\\output\\非终结符.tsv";
17+
static String lexiconMiddleResult = ".\\output\\词法分析产生的中间结果.tsv";
18+
static String parseResultPath = ".\\result\\15 gra.tsv";
19+
static String lexiconResultPath = ".\\result\\15 lex.tsv";
2020

2121
static String initSymbol = "program"; // 入口文法!
2222
}

src/MainParse.java

-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ static void DoParse() {
3535
static void writeLexiconMiddleResultIntoFile() {
3636
try {
3737
BufferedWriter out = new BufferedWriter(new FileWriter(Config.lexiconMiddleResult));
38-
out.write("词法分析的中间结果结果如下: --------------------\n");
39-
out.write("总共有 " + input_str.size() + " 条数据\n");
40-
out.write("\n");
4138
for (String s : input_str) {
4239
out.write(s + "\n");
4340
}

src/TextParse.java

-18
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ public class TextParse {
1515
static void writeAllIntoFile() {
1616
try {
1717
BufferedWriter out = new BufferedWriter(new FileWriter(Config.formulaPath));
18-
out.write("文法解析结果如下: --------------------\n");
19-
out.write("总共有 " + formulas.size() + " 条数据\n");
20-
out.write("\n");
2118
for (Formula formula : formulas) {
2219
out.write("文法左侧: " + formula.left + " 文法右侧: " + Arrays.toString(formula.right) + "\n");
2320
}
@@ -28,9 +25,6 @@ static void writeAllIntoFile() {
2825

2926
try {
3027
BufferedWriter out = new BufferedWriter(new FileWriter(Config.terminalPath));
31-
out.write("从文法中解析的终结符结果如下: --------------------\n");
32-
out.write("总共有 " + terminals.size() + " 条数据\n");
33-
out.write("\n");
3428
for (String s : terminals) {
3529
out.write(s + "\n");
3630
}
@@ -41,9 +35,6 @@ static void writeAllIntoFile() {
4135

4236
try {
4337
BufferedWriter out = new BufferedWriter(new FileWriter(Config.nonTerminalPath));
44-
out.write("从文法中解析的非终结符结果如下: --------------------\n");
45-
out.write("总共有 " + nonTerminals.size() + " 条数据\n");
46-
out.write("\n");
4738
for (String s : nonTerminals) {
4839
out.write(s + "\n");
4940
}
@@ -54,9 +45,6 @@ static void writeAllIntoFile() {
5445

5546
try {
5647
BufferedWriter out = new BufferedWriter(new FileWriter(Config.firstTablePath));
57-
out.write("First列表结果如下: --------------------\n");
58-
out.write("总共有 " + firsts.size() + " 条数据\n");
59-
out.write("\n");
6048
for (String s : firsts.keySet()) {
6149
out.write(s + " " + firsts.get(s) + "\n");
6250
}
@@ -67,9 +55,6 @@ static void writeAllIntoFile() {
6755

6856
try {
6957
BufferedWriter out = new BufferedWriter(new FileWriter(Config.followTablePath));
70-
out.write("Follow列表结果如下: --------------------\n");
71-
out.write("总共有 " + follows.size() + " 条数据\n");
72-
out.write("\n");
7358
for (String s : follows.keySet()) {
7459
out.write(s + " " + follows.get(s) + "\n");
7560
}
@@ -80,9 +65,6 @@ static void writeAllIntoFile() {
8065

8166
try {
8267
BufferedWriter out = new BufferedWriter(new FileWriter(Config.predictMapPath));
83-
out.write("预测表结果如下: --------------------\n");
84-
out.write("总共有 " + predictions.size() + " 条数据\n");
85-
out.write("\n");
8668
for (String s : predictions.keySet()) {
8769
out.write(s + " " + "文法: " + predictions.get(s).left + "->" +
8870
Arrays.toString(predictions.get(s).right) + "\n");

0 commit comments

Comments
 (0)