📄 main.cpp
字号:
/************************************************************************/
/* 文件名:main.cpp */
/* 功 能:主函数 */
/* 创建时间:2008-1-7 */
/* 最后修改时间:2008-1-11 */
/************************************************************************/
#include "lexer.h"
#include "parser.h"
#include "execute.h"
using namespace std;
//-----------------------------欢迎信息-----------------------------------//
void welcom()
{
cout<<"________________欢迎使用simple语言编译器_________________"<<endl;
cout<<"______________________________________________________________________"<<endl;
}
//-----------------------------查看符号表内容-----------------------------//
void looksingtable()
{
ifstream fin("lexer.txt");
if (!fin)
{
cout<<"抱歉,打开文件lexer.txt失败!请检查后重试。"<<endl;
exit(-1);
}
cout<<"种别码\t类型码"<<endl;
int type, value;
char temp;
while (!fin.eof())
{
fin>>type>>temp>>value;
cout<<type<<"\t"<<value<<endl;
}
fin.close();
}
//--------------------查看四元式内容----------------------//
void lookfourth()
{
cout<<"行号\t运算符\t参数1\t参数2\t结果"<<endl;
for (int i=0; i<codetab; i++)
{
cout<<i<<"\t"<<code[i].op<<"\t"<<code[i].ag1<<"\t"<<code[i].ag2<<"\t"<<code[i].result<<endl;
}
}
//------------------------------------主函数-----------------------------//
int main()
{
string choose;
welcom();
if (lexmain() == 1)//词法分析
exit(-1);
cout<<"______________________________________________________________________"<<endl;
while (1)
{
cout<<"已完成词法分析,现在你可以:1.查看符号表内容 | 2.继续语法分析"<<endl;
cout<<"请选择:";
cin>>choose;
if (choose == "1")
{
looksingtable();//查看内容
cout<<"______________________________________________________________________"<<endl;
}
else
break;
}
cout<<"______________________________________________________________________"<<endl;
cout<<"正在进行语法分析......"<<endl;
if (parsermain() == 1)//语法与语义分析
exit(-1);
cout<<"______________________________________________________________________"<<endl;
while (1)
{
cout<<"已完成语法分析,现在你可以:1.查看生成的四元式 | 2.查看生成的符号表内容 | 3.继续解释执行程序"<<endl;
cout<<"请选择:";
cin>>choose;
if (choose == "1")
{
lookfourth();//查看生成的四元式
cout<<"______________________________________________________________________"<<endl;
}
else if (choose == "2")
{
looksingtable();//查看内容
cout<<"______________________________________________________________________"<<endl;
}
else
break;
}
cout<<"______________________________________________________________________"<<endl;
execute();//解释执行
cout<<"成功解释执行!"<<endl;
cout<<"______________________________________________________________________"<<endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -