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

📄 caoyutingdlg.cpp

📁 实现了简单的Simple语言的编辑器,包括词法分析,语法分析,生成四元式,以及生成符号表功能,在符号表中还可以进行查询与删除.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// caoyutingDlg.cpp : implementation file
//

#include "stdafx.h"
#include "caoyuting.h"
#include "caoyutingDlg.h"
#include"Dialog1.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CCaoyutingApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();
	
// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	virtual void OnOK();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCaoyutingDlg dialog

CCaoyutingDlg::CCaoyutingDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCaoyutingDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCaoyutingDlg)
	m_cStateBar = _T("");
	m_str = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CCaoyutingDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCaoyutingDlg)
	DDX_Control(pDX, IDC_OUTCTRL, m_cOut);
	DDX_Control(pDX, IDC_INCTRL, m_cIn);
	DDX_Text(pDX, IDC_STATEBAR, m_cStateBar);
	DDX_Text(pDX, IDC_OUTCTRL, m_str);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCaoyutingDlg, CDialog)
	//{{AFX_MSG_MAP(CCaoyutingDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_COMMAND(ID_MENUITEM_OPEN, OnMenuitemOpen)
	ON_COMMAND(ID_MENUITEM_SAVE, OnMenuitemSave)
	ON_COMMAND(ID_MENUITEM_EXIT, OnMenuitemExit)
	ON_COMMAND(ID_MENUITEM_ABOUT, OnMenuitemAbout)
	ON_COMMAND(ID_MENUITEM_CIFA, OnMenuitemCifa)
	ON_COMMAND(ID_MENUITEM_YUFA, OnMenuitemYufa)
	ON_COMMAND(ID_MENUITEM_YUYI, OnMenuitemYuyi)
	ON_COMMAND(ID_MENUITEM_XIANSHI, OnMenuitemXianshi)
	ON_COMMAND(ID_MENUITEM_SAVEAS, OnMenuitemSaveas)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCaoyutingDlg message handlers

BOOL CCaoyutingDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CCaoyutingDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CCaoyutingDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CCaoyutingDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CCaoyutingDlg::OnMenuitemOpen() 
{
	// TODO: Add your command handler code here
		if (m_cIn.GetModify())
	{
		switch (AfxMessageBox("要保存修改吗?!",MB_YESNOCANCEL|MB_ICONQUESTION))
		{
		case IDYES:
			OnMenuitemSave();
			break;
		case IDCANCEL:
			return;
		default:
			;
		}
	}
	CFileDialog fdlg(TRUE,"pl0",NULL,OFN_FILEMUSTEXIST,
		"源程序文件(*.txt)|*.txt|所有文件(*.*)|*.*||",this);
    fdlg.m_ofn.lpstrTitle="打开源程序文件";
	if (fdlg.DoModal()==IDOK)
	{
		m_strCurFile=fdlg.GetPathName();
		CFile f;
		f.Open(m_strCurFile,CFile::modeRead);
		char buf[30001];
		int sz=f.Read(buf,30000);
		buf[sz]=0;
		m_cIn.SetWindowText(buf);
		m_cIn.SetSel(0,0);
		f.Close();
		char a[255];
		::strcpy(a,"编译器  当前源文件:");
		::strcat(a,m_strCurFile.GetBuffer(0));
		SetWindowText(a);
		m_cIn.SetModify(FALSE);
	}
}

void CCaoyutingDlg::OnMenuitemSave() 
{
	// TODO: Add your command handler code here
		if (m_strCurFile!="")
	{
		char buf[30001];
		int sz=m_cIn.GetWindowText(buf,30000);
		CFile f;
	    f.Open(m_strCurFile,CFile::modeWrite|CFile::modeCreate);
	    f.Write(buf,sz);
	    f.Close();
		char a[255];
		::strcpy(a,"编译器  当前源文件:");
		::strcat(a,m_strCurFile.GetBuffer(0));
		SetWindowText(a);
		m_cIn.SetModify(FALSE);
	}
		else
	{
		OnMenuitemSaveas();
	}
}

void CCaoyutingDlg::OnMenuitemExit() 
{
	// TODO: Add your command handler code here
	OnClose();
}

void CCaoyutingDlg::OnClose()
{
	if (m_cIn.GetModify())
	{
		switch (AfxMessageBox("要保存修改吗?!",MB_YESNOCANCEL|MB_ICONQUESTION))
		{
		case IDYES:
			OnMenuitemSave();
			break;
		case IDCANCEL:
			return;
		default:
			;
		}
	}
	if (IDNO==AfxMessageBox("真的要退出吗?",MB_YESNO|MB_ICONQUESTION))
	{
		return;
	}
	EndDialog(IDCANCEL);
	CDialog::OnClose();
}

void CCaoyutingDlg::OnMenuitemAbout() 
{
	CAboutDlg dlgAbout;
	dlgAbout.DoModal();
	// TODO: Add your command handler code here
	
}

void CCaoyutingDlg::OnMenuitemCifa() 
{
// TODO: Add your command handler code here
char buf[30003];
	int sz=m_cIn.GetWindowText(buf,30000);
	buf[sz]=0;
	::strcpy(m_Compiler.GetTable()->SourseBuffer,buf);
	m_Compiler.CiFaFengXi();
	CifaResult * * p=m_Compiler.GetTable()->LexicalDuad;
	int s=0;
	int a=p[s]->type;
	CString str1;
	while ((p[s]->type)>=0)
		s++;
	char (*ep)[100];
	ep=m_Compiler.GetTable()->ErrorMessageTable;
	//result to : p,s,ep
	m_cOut.SetWindowText("");

⌨️ 快捷键说明

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