-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharithmetic_expression.cpp
More file actions
121 lines (121 loc) · 2.98 KB
/
arithmetic_expression.cpp
File metadata and controls
121 lines (121 loc) · 2.98 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
#include"compile.h"
void Grammatical_Analyze::G()
{
if(now_token.code==3)
{
//******************bug************************
QString tmp_val=tmp_symbol_tabel.s3.at(now_token.num);
quaternary_stack.push(tmp_val);
now_token=get_next_token();
}
else if(now_token.code==0)
{
QString tmp_name=tmp_symbol_tabel.s0.at(now_token.num).name;
quaternary_stack.push(tmp_name);
now_token=get_next_token();
if(now_token.code==27)
{
now_token=get_next_token();
if(now_token.code==3)
{
QString tmp_val=tmp_symbol_tabel.s3.at(now_token.num);
quaternary_stack.push(tmp_val);
now_token=get_next_token();
if(now_token.code==28)
{
now_token=get_next_token();
QT_Arithmetic_output('a');
}
}
}
}
else if(now_token.code==24)
{
now_token=get_next_token();
E();
if(now_token.code==25)
{
now_token=get_next_token();
}
else printf("bracket wrong!\n");
}
else printf("illegality character!\n");
}
void Grammatical_Analyze::F()
{
G();
do
{
if(now_token.code==22)
{
now_token=get_next_token();
G();
QT_Arithmetic_output('*');
}
else if(now_token.code==23)
{
now_token=get_next_token();
G();
QT_Arithmetic_output('/');
}
else return ;
}while(now_token.code==22||now_token.code==23);
}
void Grammatical_Analyze::T()
{
F();
do
{
if(now_token.code==19)
{
now_token=get_next_token();
F();
QT_Arithmetic_output('+');
}
else if(now_token.code==20)
{
now_token=get_next_token();
F();
QT_Arithmetic_output('-');
}
else return ;
}while(now_token.code==19||now_token.code==20);
}
void Grammatical_Analyze::E()
{
T();
do
{
if(now_token.code==15)
{
now_token=get_next_token();
T();
QT_Arithmetic_output('l');//<=
}
else if(now_token.code==16)
{
now_token=get_next_token();
T();
QT_Arithmetic_output('h');//>=
}
else if(now_token.code==17)
{
now_token=get_next_token();
T();
QT_Arithmetic_output('e');//==
}
else if(now_token.code==36)
{
now_token=get_next_token();
T();
QT_Arithmetic_output('<');//<
}
else if(now_token.code==37)
{
now_token=get_next_token();
T();
QT_Arithmetic_output('>');//>=
}
else return;
}while(now_token.code==15||now_token.code==16||now_token.code==17||now_token.code==36||now_token.code==37);
}