test.cpp
来自「pl0文法编译器」· C++ 代码 · 共 73 行
CPP
73 行
#include "SymSet.h"
#include "LexAnalyze.h"
#include "PL0Compiler.h"
#include "GramAnalyze.h"
#include "SymbolTable.h"
#include "CCode.h"
#include "Errors.h"
#include<iostream>
#include <conio.h>
#include <fstream>
#include <string>
using namespace std;
void main()
{
cout<<"PL/0 compiler version1.0 \nwriten by 33060406 马永焘 2006/3\n";
string inFileName, outFileName;
cout<<"source file: ";
cin>>inFileName;
outFileName = inFileName.substr(0,inFileName.find_last_of('.'));
outFileName = outFileName + ".pl0";
PL0Compiler pl0(inFileName, outFileName);
char ch;
cout<<"list the source file? (y/n): ";
ch = getch();
while (ch!='y'&&ch!='n') ch = getch();
cout<<ch<<endl;
if (ch=='y')
pl0.displayScript();
cout<<endl<<"compiling..."<<endl<<endl;
pl0.compile();
cout<<endl;
bool flag = pl0.listError();
if(flag)
{
cout<<endl<<"continue?(y/n): ";
ch=getch();
while (ch!='y'&&ch!='n') ch=getch();
cout<<ch<<endl;
if (ch=='n')
{
cout<<endl<<"failed to make the object file, for errors have been found in source file"
<<endl<<"please check your source file"<<endl<<endl;
return;
}
}
cout<<endl<<"list object code?(y/n): ";
ch=getch();
while (ch!='y'&&ch!='n') ch=getch();
cout<<ch<<endl;
if (ch=='y')
pl0.listCode();
cout<<endl<<endl;
if(flag)
{
cout<<endl<<"failed to make the object file, for errors have been found in source file"
<<"please check your source file"<<endl<<endl;
}
else
{
pl0.wrtToFile();
cout<<"the object file: "<<outFileName<<" has been made already"
<<endl<<"run the PL0Interpreter to run the program"<<endl<<endl;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?