⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mfcpl0view.cpp

📁 这个是我用mfc写的一个pl0的编译器
💻 CPP
字号:
// MFCpl0View.cpp : implementation of the CMFCpl0View class
//

#include "stdafx.h"
#include "MFCpl0.h"
#include "openfile.h"
#include "MFCpl0Doc.h"
#include "MFCpl0View.h"
#include "execute.h"
#include "propersheet.h"
#include "propersheet2.h"
#include "propersheetbrowse.h"
#include <stdio.h>
#include <conio.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMFCpl0View

IMPLEMENT_DYNCREATE(CMFCpl0View, CView)

BEGIN_MESSAGE_MAP(CMFCpl0View, CView)
	//{{AFX_MSG_MAP(CMFCpl0View)
	ON_COMMAND(ID_VIEW_TOOLBAR, OnViewToolbar)
	ON_COMMAND(IDW_comple, Oncomple)
	ON_COMMAND(ID_browse, Onbrowse)
	ON_COMMAND(ID_openother, Onopenother)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMFCpl0View construction/destruction

CMFCpl0View::CMFCpl0View()
{
	// TODO: add construction code here
	filename="";
	fileopenon=false;
	havecompile=false;
	msgtable=(char**)malloc(sizeof(char*)*100);
	for(int i=0;i<100;i++)
	{
		msgtable[i]=(char*)malloc(50*sizeof(char));
	}

}

CMFCpl0View::~CMFCpl0View()
{
}

BOOL CMFCpl0View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMFCpl0View drawing

void CMFCpl0View::OnDraw(CDC* pDC)
{
	pDC->SetTextColor(::GetSysColor(COLOR_WINDOWTEXT));   
    pDC->SetBkMode(TRANSPARENT);   
	TEXTMETRIC tm;
	pDC->GetTextMetrics (&tm);
	int height;
	height=tm.tmHeight;
	int y=0;
	CString temp;
	char buffer[20];

	if(havecompile==false)
	{
		pDC->TextOut(0,y,"还没有编译");
	}
	else
	{
		if(errnum!=0)
		{
			pDC->TextOut(10,y,"程序中存在错误请及时修改!!");
			return;
		}

		pDC->TextOut(10,y,"对应的输出结果是:");
		for(int i=0;i<hang;i++)
		{
			int j=0;
		
			y=y+height;			
			while(msgtable[i][j]>0)
			{
				_itoa( msgtable[i][j], buffer, 10 );	
				temp.Format("%s",buffer);
				j++;
			}
			if(msgtable[i][0]<0)
			{
				return ;
			}
			pDC->TextOut(130,y,temp);
			
		}
	}


	CMFCpl0Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CMFCpl0View printing

BOOL CMFCpl0View::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CMFCpl0View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CMFCpl0View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CMFCpl0View diagnostics

#ifdef _DEBUG
void CMFCpl0View::AssertValid() const
{
	CView::AssertValid();
}

void CMFCpl0View::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CMFCpl0Doc* CMFCpl0View::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCpl0Doc)));
	return (CMFCpl0Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMFCpl0View message handlers

void CMFCpl0View::OnViewToolbar() 
{
	// TODO: Add your command handler code here
	
}



void CMFCpl0View::Oncomple() 
{
	// TODO: Add your command handler code here
	if(!fileopenon)
	{
	Copenfile file(TRUE, "", NULL, 
		OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT, 
		"PL0文本(*.pl0)|*.pl0|所有文件(*.*)|*.*||",
		AfxGetMainWnd());
	CString strFile;
	int count=0;
	while(file.DoModal () != IDOK)
	{
		count++;
		if(count==1)
		{
			return;
		}
	}
	fileopenon=true;
	
	POSITION pos = file.GetStartPosition();
	strFile = file.GetNextPathName(pos);
	filename=strFile;
	//AfxMessageBox(strFile);
	///////下面将对打开的文件进行编译
	}
	
	Cexecute compile1;

	compile1.fin=fopen(filename,"r");

	if(compile1.fin)
	{
	
		Cpropersheet propersheet1("功能表");
		propersheet1.SetWizardMode();

		if(propersheet1.DoModal()==ID_WIZFINISH)
		{
			
				if(1==propersheet1.prop3.m_table)
				{
					compile1.tableswitch=false;
				}
				else
				{
					compile1.tableswitch=true;
				}
				if(1==propersheet1.prop4.m_list)
				{
					compile1.listswitch=false;
				}
				else
				{
					compile1.listswitch=true;
				}
		}
		else
		{
			return;
		}


		compile1.fa1=fopen("fa1.tmp","w");
		fprintf(compile1.fa1,"input pl/0 file?");
		fprintf(compile1.fa1,"%s\n",filename);
		compile1.init();
		compile1.err=0;
		compile1.cc=compile1.cx=compile1.ll=0;
		compile1.ch=' ';
		if(-1!=compile1.getsym())
		{
			compile1.fa=fopen("fa.tmp","w");
			compile1.fas=fopen("fas.tmp","w");
			compile1.addset(compile1.nxtlev,compile1.declbegsys,compile1.statbegsys,symnum);
			compile1.nxtlev[period]=true;
			if(-1==compile1.block(0,0,compile1.nxtlev))
			{
				fclose(compile1.fa);
				fclose(compile1.fa1);
				fclose(compile1.fas);
				fclose(compile1.fin);
			//	printf("\n");
	
			}
			fclose(compile1.fa);
			fclose(compile1.fa1);
			fclose(compile1.fas);
			if(compile1.sym!=period)
			{
				compile1.error(9,1);
			}
			Cpropersheet2 propersheet2("table and code");
			propersheet2.Addtable(compile1.table);
			propersheet2.Addcode(compile1.code);
			propersheet2.Adderrmsg(compile1.allerrmsg,compile1.err);
			propersheet2.DoModal();
			
			if(compile1.err==0)
			{
				compile1.fa2=fopen("fa2.tmp","w");
				compile1.interpret(msgtable);
				//msgtable=compile1.outputresult();
				hang=compile1.outputhang();
				lie=compile1.outputlie();
				fclose(compile1.fa2);
			}
			else
			{
				MessageBox("程序中存在错误,请作修改!");
			}
		}
		fclose(compile1.fin);


	}//if open the file
	else
	{
		printf("Can't open the file!");
	}



	havecompile=true;
	hang=compile1.outputhang();
	lie=compile1.outputlie();
	errnum=compile1.err;
	Invalidate();
}

void CMFCpl0View::Onbrowse() 
{
	if(fileopenon)
	{
		Cpropersheetbrowse propsheet("浏览文件");
		propsheet.getadd(filename);
		propsheet.DoModal();
	}
	else
	{
		Copenfile file(TRUE, "", NULL, 
		OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT, 
		"PL0文本(*.pl0)|*.pl0|所有文件(*.*)|*.*||",
		AfxGetMainWnd());
		CString strFile;
		int count=0;
		while(file.DoModal () != IDOK)
		{
			count++;
			if(count==1)
			{
				return;
			}
		}
		fileopenon=true;
		POSITION pos = file.GetStartPosition();
		strFile = file.GetNextPathName(pos);
		filename=strFile;
	//	AfxMessageBox(strFile);
		Cpropersheetbrowse propsheet("浏览文件");
		propsheet.getadd(filename);
		//propsheet.SetWizardMode();
		propsheet.DoModal();
	}


}

void CMFCpl0View::Onopenother() 
{
		Copenfile file(TRUE, "", NULL, 
		OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT, 
		"PL0文本(*.pl0)|*.pl0|所有文件(*.*)|*.*||",
		AfxGetMainWnd());
		CString strFile;
		int count=0;
		while(file.DoModal () != IDOK)
		{
			count++;
			if(count==1)
			{
				return;
			}
		}
		fileopenon=true;
		POSITION pos = file.GetStartPosition();
		strFile = file.GetNextPathName(pos);
		filename=strFile;
		Onbrowse();	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -