📄 main.cpp
字号:
#include <iomanip>
#include "parse.h"
#include "read.h"
#include "make.h"
ifstream grammarfile;
DVec_str productions;
vector<string> terminals;
vecNter nonterminals;
DVec_int table;
vector< string> vec ;
stack<string> parseStack;
vector<string> inputStr;
int main()
{
ofstream outf( "set.txt" );
if( !outf )cout << "Cannot open the file : first.txt\n ";
else{
readGrammar();
makeFirstSet();
outf<<"The First Set:\n";
for(size_t i = 0;i < nonterminals.size();i++)
{
outf << "First( "<<nonterminals[i].token<<" )" << "= { ";
size_t j;
for( j = 0;j < nonterminals[i].first.size() - 1;j++)
outf << nonterminals[i].first[j]<<",";
outf<<nonterminals[i].first[j]<<" }\n";
}
makeFollowSet();
outf<<"\n\n\nThe Follow Set:\n";
for(size_t i = 0;i < nonterminals.size();i++)
{
outf << "Follow( "<<nonterminals[i].token<<" )" << "= { ";
size_t j;
for( j = 0;j < nonterminals[i].follow.size() - 1;j++)
outf << nonterminals[i].follow[j]<<",";
outf<<nonterminals[i].follow[j]<<" }\n";
}
makeTable();
cout<<setw(10)<<"M[N,T]";
for(int i = 0;i < (int)terminals.size();i++ )
{
if(terminals[i] != "ε" )cout<<setw(8)<<terminals[i];
}
cout<<setw(8)<<"$";
cout <<endl;
for( int i = 0;i < (int)table.size();i++ )
{
cout<<setw(10)<<nonterminals[i].token;
for( int j = 0;j < (int)table[i].size();j++ )
{
if( table[i][j] != -1 )
cout<<setw(8)<<table[i][j];
else
cout<<setw(8)<<" ";
}
cout<<endl;
}
parseTable();
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -