-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
72 lines (65 loc) · 1.61 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "lexer.h"
#include "parser.h"
#include "format.h"
void openfile(FILE *(*fp), char filename[30]); //打开一个源码文件
char filename[30];
FILE *fp;
int main()
{
int ch = 1;
while (ch)
{
system("clear");
printf("高级语言源程序格式处理菜单\n");
printf("1. 词法分析\n");
printf("2. 语法分析\n");
printf("3. 格式化源文件\n");
printf("0. 退出程序\n");
printf("\n");
printf("请进行选择:");
scanf("%d", &ch);
system("clear");
switch (ch)
{
case 1:
{
openfile(&fp, filename);
printf("已经进入词法分析!\n");
word_analyse(fp);
getchar();getchar();
break;
}
case 2:
{
openfile(&fp, filename);
printf("已经进入语法分析!\n");
syntax_analyse();
getchar();getchar();
break;
}
case 3:
{
openfile(&fp, filename);
printf("已经进入格式化!\n");
format();
getchar();getchar();
break;
}
default:
return 0;
}
}
}
void openfile(FILE *(*fp), char filename[30])
{
system("clear");
printf("输入文件名:");
scanf("%s", filename);
if (!((*fp) = fopen(filename, "r")))
{
printf("文件打开失败!\n");
printf("请重新输入有效文件名...");
getchar();getchar();
openfile(fp, filename);
} //打开文件并验证是否成功
}