void Forecast() { while (true) { string serial; serial.resize(100); printf("请输入序列:"); scanf("%s", &serial[0]); vector<string> stack; stack.push_back("$"); stack.push_back("E"); string strs(serial.c_str()); string w = strs + "$"; int
时间: 2024-04-26 19:24:25 浏览: 80
ZuiXiaoErCheng.rar_forecast_point target_site:www.pudn.com_坐标预测_
void Forecast() {
while (true) {
string serial;
serial.resize(100);
printf("请输入序列:");
scanf("%s", &serial[0]);
vector<string> stack;
stack.push_back("$");
stack.push_back("E");
string strs(serial.c_str());
string w = strs + "$";
int ip = 0;
string X = stack[stack.size() - 1];
TreeNode root = new Node();
root->name = X;
vector<Node*> tree_stack;
tree_stack.push_back(root);
tree_stack.push_back(root);
TreeNode parent = root;
TreeNode node;
string a = NextFlag(ip, w);
bool isSuc = true;
do {
if (IfStringIn(listTerminal, X)) {
if (X == a) {
tree_stack.pop_back();
parent = tree_stack[tree_stack.size() - 1];
stack.pop_back();
X = stack[stack.size() - 1];
a = NextFlag(ip, w);
} else {
printf("语法错误行:“%s”,错误位置列索引:“%d”", serial.c_str(), ip - 1);
isSuc = false;
break;
}
} else {
int nStart = 0;
if (NextFlag(nStart, M[X][a]) == X) {
tree_stack.pop_back();
stack.pop_back();
vector<string> stack2;
string strTemp = NextFlag(nStart, M[X][a]);
while (strTemp != "") {
if (strTemp != "ε") {
stack2.push_back(strTemp);
}
strTemp = NextFlag(nStart, M[X][a]);
}
while (stack2.size() > 0) {
node = new Node();
node->name = stack2[stack2.size() - 1];
tree_stack.push_back(node);
parent->child.push_back(node);
stack.push_back(stack2[stack2.size() - 1]);
stack2.pop_back();
}
parent = tree_stack[tree_stack.size() - 1];
X = stack[stack.size() - 1];
} else {
printf("语法错误行:“%s”,错误位置列索引:“%d”", serial.c_str(), ip - 1);
isSuc = false;
break;
}
}
} while (X != "$" || a != "$");
if (isSuc) {
PrintTree(root);
printf("\r\n语法分析成功\r\n\r\n");
} else {
printf("\r\n\r\n");
}
}
}
以上是经过格式化后的代码,没有进行实质性的修改。
阅读全文