-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrammatical_analyze_fun.cpp
More file actions
124 lines (124 loc) · 4.32 KB
/
grammatical_analyze_fun.cpp
File metadata and controls
124 lines (124 loc) · 4.32 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include"compile.h"
int Grammatical_Analyze::program()//程序
{
int tmp=return_type();
if(!tmp)
{
tmp=function();
if(!tmp)
{
return program();
}
else
{
tmp=main_function();
if(!tmp) return 0;
else return 1;
}
}
else
{
return tmp;
}
}
int Grammatical_Analyze::function()//函数
{
int tmp=11;
Symbol_Tabel function_tabel;//产生函数符号表
function_tabel.fill_start_offset();
if(now_token.code==0)
{
now_token=get_next_token();
if(now_token.code==24)
{
now_token=get_next_token();
if(now_token.code==25)
{
now_token=get_next_token();
if(now_token.code==29)
{
now_token=get_next_token();
tmp=varible_declar(function_tabel);
if(!tmp)
{
tmp=compound_statement(function_tabel);
if(!tmp)
{
if(now_token.code==30)
{
now_token=get_next_token();
return 0;
}
}else return tmp;
}else return tmp;
}else return tmp;
}else return tmp;
}else return tmp;
}else return tmp;
}
int Grammatical_Analyze::main_function()//主函数
{
int tmp=1;
if(now_token.code==7)//是main
{
now_token=get_next_token();
if(now_token.code==24)//是(
{
now_token=get_next_token();
if(now_token.code==25)//是)
{
now_token=get_next_token();
if(now_token.code==29)//是{
{
Symbol_Tabel main_function_tabel;//产生符号表
main_function_tabel.fill_start_offset();
QT_program_output();//程序开始四元式
now_token=get_next_token();
tmp=varible_declar(main_function_tabel);
if(!tmp)
{
tmp=1;
tmp=compound_statement(main_function_tabel);
if(!tmp)
{
tmp=1;
if(now_token.code==14)//是return
{
now_token=get_next_token();
if(now_token.code==3)//是常数
{
now_token=get_next_token();
if(now_token.code==32)//是;
{
now_token=get_next_token();
if(now_token.code==30)
{
QT_program_end_output();//程序结束四元式
code_optimization_output(main_function_tabel,1);
/*change_output_tabel(1);
insert();//优化
recombine_QT();
fill_tmp_variable_tabel(main_function_tabel);
test(main_function_tabel);//测试*/
return 0;
}else return 1;
}else return 1;
}else return 1;
}else return 1;
}else return tmp;
} else return tmp;
}else return tmp;
}else return tmp;
}else return tmp;
}
else return tmp;
}
int Grammatical_Analyze::return_type()//返回类型
{
if(now_token.code==4||now_token.code==5||now_token.code==6)
{
now_token=get_next_token();
return 0;
}
else return 2;
}