pc.cpp
来自「编译课程设计」· C++ 代码 · 共 53 行
CPP
53 行
// PL0 Compiler
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include "pl0.h"
void main(int argc,char *argv[])
{
char filename[256];
printf("pl/0 compiler version 1.0\n, 2002-11-1\n");
if (argc!=2)
{
printf("source file:");
gets(filename);
}
else
strcpy(filename,argv[1]);
CPlCompiler pl(filename);
char ch;
if (pl.FileEmpty())
{
printf("source file cannot be opened!\n");
return;
}
printf("list source file?(y/n): ");
ch=getch();
while (ch!='y'&&ch!='n') ch=getch();
printf("%c\n",ch);
if (ch=='y') pl.DisplaySrcfile();
printf("compiling...\n\n");
pl.Compile();
if (pl.ErrorNumber())
{
pl.DisplayErrors();
printf("continue?(y/n): ");
ch=getch();
while (ch!='y'&&ch!='n') ch=getch();
printf("%c\n",ch);
if (ch=='n') return;
}
printf("list object code?(y/n): ");
ch=getch();
while (ch!='y'&&ch!='n') ch=getch();
printf("%c\n",ch);
if (ch=='y') pl.ListCode();
printf("start\n");
pl.Interpret();
}