?? get.cpp
字號:
#include "global.h"
/*-----------------------------------------
To get grammer from the standard input
stream.
avoid file processing :P
------------------------------------------*/
string choice; // for user's decision
int lineno = 0;
list<string> production[MAXLINE];
void showMessage()
{
cout << " LL(1) parsing machine @ Math Frog && FLower @ " << endl;
cout << endl;
cout << " ** Please input the grammer you want to process ** \n";
cout << "\n ** REMIND : Just type a space after entering a symbol **";
cout << "\n ** press # to end inputing production **";
cout << "\n ** press $ to end inputing grammer **" << endl;
cout << "***********************************" << endl;
}
void getGrammer()
{
while(true){
showMessage();
string tmp; // holding input string temporily
for(;lineno < MAXLINE;){
cout << "line " << lineno << ": ";
cin >> tmp;
while(tmp != "#" && tmp != "$"){
production[lineno].push_back(tmp);
cin >> tmp;
}
if(tmp == "$") break; // end inputing grammer
lineno++;
}
cout << "***********************************" << endl;
cout << endl;
for(int j = 0;j < lineno;j++)
print(production[j]);
cout << endl;
cout << "***********************************" << endl;
cout << endl;
cout << "\nIs the grammer you want to anlysis ? " << endl;
cout << endl;
cout << "(Type Y for yes and N for no)" << endl;
cin >> choice;
if(choice == "Y")
break;
for(int i = 0;i < lineno;i++) // everything just begins
production[i].erase(production[i].begin(),production[i].end());
lineno = 0;
}
}
void getCoGrammer()
{
list<string> hold;
for(int line = 0;line < lineno;line++){
list<string>::iterator iter = production[line].begin();
iter++; // to the ->
iter++; // to the first on the right of the production
while(iter != production[line].end()){
hold.push_back(production[line].front());
hold.push_back("->");
if(iter == --production[line].end())
hold.push_back(*iter);
else{
while(*iter != "|" && iter != production[line].end()){
hold.push_back(*iter);
if(iter == --production[line].end()) break;
iter++;
}
}
coProduction[colineno++] = hold; // just use the overloaded =
hold.erase(hold.begin(),hold.end()); // make hold empty list
iter++;
}
}
}
bool isLeftRecursion()
{
return false;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -