-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path主函数.cpp
118 lines (113 loc) · 2.4 KB
/
主函数.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
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
#include <iostream>
#include <string>
#include "define.h"
#include "token.h"
#include "do_int.h"
#include "do_out.h"
#include "do_real.h"
#include "do_string.h"
#define stack_size 500;
using namespace std;
#pragma warning(disable:4996)
#include <map>
map<string, string> VariableName;
token get_token();
char hang_[20];
char c_;
int weightmax; //最高权值。
int weight; //当前识别字符的权值。
typedef enum
{
left2right,
right2left
}associativity;
typedef struct
{
int number_;//操作数
int icp; //优先级
int isp; //优先级
associativity ass; //结合性
token op; //操作符
}OPERATOR;
static const OPERATOR operators[] =
{
{ 2, 17, 1, left2right, LPRAEN }, // 左括号
{ 2, 17, 17, left2right, RPRAEN }, // 右括号
{ 2, 12, 12, left2right, OP_plus }, // 加
{ 2, 12, 12, left2right, OP_minus }, // 减
{ 2, 13, 13, left2right, OP_multiply }, // 乘
{ 2, 13, 13, left2right, OP_divide }, // 除
{ 2, 13, 13, left2right, OP_mod }, // 模
{ 2, 10, 10, left2right, OP_lt }, // 小于
{ 2, 10, 10, left2right, OP_gt }, // 大于
{ 2, 9, 9, left2right, OP_eq }, // 等于
{ 2, 9, 9, left2right, OP_ne }, // 不等于
{ 2, 10, 10, left2right, OP_le }, // 小于等于
{ 2, 10, 10, left2right, OP_ge }, // 大于等于
/* 逻辑运算 */
{ 2, 5, 5, left2right, OP_and }, // 与
{ 2, 4, 4, left2right, OP_or }, // 或
{ 1, 15, 15, right2left, OP_not }, // 非
/* 赋值 */
// BASIC 中赋值语句不属于表达式!
//{ 2, 2, 2, right2left, oper_assignment }, // 赋值
/* 最小优先级 */
//{ 2, 0, 0, right2left, oper_min } // 栈底
};
char token_buffer[200];
void do_int();
int main()
{
freopen("in.txt","r",stdin);
while (!feof(stdin))
{
weightmax = 0;
while ((c_ = getchar()) !=EOF)
{
ungetc(c_, stdin);
switch (get_token())
{
case key_out:
{
do_out();
break;
}
case key_in:
{
//do_in();
break;
}
case key_if:
{
//do_if();
break;
}
case key_while:
{
//do_while();
break;
}
case key_int:
{
do_int();
break;
}
case key_real:
{
do_real();
break;
}
case key_string:
{
do_string();
break;
}
}
}
}
map<string, string>::iterator iter;
for (iter = VariableName.begin(); iter != VariableName.end(); iter++)
cout << iter->first << ' ' << iter->second << endl;
system("pause");
return 0;
}