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

📄 example.cpp

📁 PASCAL编译器
💻 CPP
字号:
// example.cpp : implementation file
//

#include "stdafx.h"
#include "pascalcompiler.h"
#include "example.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// Cexample dialog


Cexample::Cexample(CWnd* pParent /*=NULL*/)
	: CDialog(Cexample::IDD, pParent)
{
	//{{AFX_DATA_INIT(Cexample)
	m_m1 = _T("");
	m_m = _T("");
	//}}AFX_DATA_INIT
}


void Cexample::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Cexample)
	DDX_Text(pDX, IDC_EDIT2, m_m1);
	DDX_Text(pDX, IDC_EDIT1, m_m);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(Cexample, CDialog)
	//{{AFX_MSG_MAP(Cexample)
	ON_BN_CLICKED(IDC_anayles, Onanayles)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Cexample message handlers

void Cexample::Onanayles()
{
	// TODO: Add your control notification handler code here
	sigmar = 0;sigmar1 = 0;
	UpdateData(true);
	m_m1 = "";
	ST = m_m;
	int j = ST.GetLength();
	for(int k = 0;k <j;)
	{
		if((ST.GetAt(k) >= 'A' && ST.GetAt(k) <= 'Z')
			|| (ST.GetAt(k) >= 'a' && ST.GetAt(k) <= 'z')
			|| ST.GetAt(k) == '('
			|| (ST.GetAt(k) >='0' && ST.GetAt(k) <= '9'))
		{
			break;
		}
		else
		{
			m_m1 += "最前面不能直接用:";
			m_m1 += ST.GetAt(0);
			m_m1 += "\r";
			m_m1 += "\n";
			ST.Delete(0);
			j--;
		}
	}
	for(i = 0;i < j-1;)
	{
		if((ST.GetAt(i) >='A' && ST.GetAt(i) <='Z')
			||(ST.GetAt(i) >='a' && ST.GetAt(i) <='z')
			|| (ST.GetAt(i) >=0x30 && ST.GetAt(i) <= 0x39))
		{
			if(ST.GetAt(i+1) == '+' ||ST.GetAt(i+1) == '-'
				|| ST.GetAt(i+1) == '*' || ST.GetAt(i+1) == '/')
			{
				i++;
				continue;
			}
			else
			{
				if(ST.GetAt(i+1) == ')')
				{
					i++;
					continue;
				}
				else
				{
					if((ST.GetAt(i+1) >= 'A' && ST.GetAt(i+1) <= 'Z')
						||(ST.GetAt(i+1) >= 'a' && ST.GetAt(i+1) <= 'z')
						|| (ST.GetAt(i+1) >=0x30 && ST.GetAt(i+1) <= 0x39))
					{
						i++;
						continue;
					}
					else
					{
						Cexample::errormark();///出错处理
						i++;i++;
						continue;
					}
				}
			}
		}
		else if(ST.GetAt(i) == '(')
		{
			if((ST.GetAt(i+1) >= 'A' && ST.GetAt(i+1) <= 'Z')
				||(ST.GetAt(i+1) >= 'a' && ST.GetAt(i+1) <= 'z')
				|| (ST.GetAt(i+1) >=0x30 && ST.GetAt(i+1) <= 0x39))
			{
				i++;
				continue;
			}
			else
			{
				if(ST.GetAt(i+1) == '(')
				{
					i++;
					continue;
				}
				else
				{
					Cexample::errormark();///出错处理
					i++;i++;
					continue;
				}
				
			}
		}
		else if(ST.GetAt(i) == '+' || ST.GetAt(i) == '-'
			|| ST.GetAt(i) == '*' || ST.GetAt(i) == '/')
		{
			if((ST.GetAt(i+1) >= 'A' && ST.GetAt(i+1) <= 'Z')
				||(ST.GetAt(i+1) >= 'a' && ST.GetAt(i+1) <= 'z')
				|| (ST.GetAt(i+1) >=0x30 && ST.GetAt(i+1) <= 0x39))
			{
				i++;
				continue;
			}
			else
			{
				if(ST.GetAt(i+1) == '(')
				{
					i++;
					continue;
				}
				else
				{
					Cexample::errormark();///出错处理
					i++;i++;
					continue;
				}
			}
		}
		else if(ST.GetAt(i) == ')')
		{
			if(ST.GetAt(i+1) == '+' || ST.GetAt(i+1) == '-'
				|| ST.GetAt(i+1) == '*' || ST.GetAt(i+1) == '/')
			{
				i++;
				continue;
			}
			else
			{
				if(ST.GetAt(i+1) == ')')
				{
					i++;
					continue;
				}
				else
				{
					Cexample::errormark();///出错处理
					i++;i++;
					continue;
				}
			}
		}
		else
		{
		}
	}
	//////////////////////////////////////////
	while(j)
	{
		j--;
		if(ST.GetAt(j) == ')')
		{
			sigmar += 1;
		}
		if(ST.GetAt(j) == '(')
		{
			sigmar1 += 1;
		}
	}
	if(sigmar != sigmar1)
	{
		if(sigmar > sigmar1)
		{
			m_m1 += "少写了一个 '(' 或多了一了 ')'";
			m_m1 += "\r";
			m_m1 += "\n";
		}
		else
		{
			m_m1 +="多写了一个 '(' 或少了一了 ')'";
			m_m1 += "\r";
			m_m1 += "\n";
		}
	}
	//////////////////////////////////////////////////
	if(m_m1 == "")
	{
		m_m1 = "没有错误";
	}
	UpdateData(false);
}

void Cexample::OnOK() 
{
	// TODO: Add extra validation here
	
	CDialog::OnOK();
}

void Cexample::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

void Cexample::errormark()
{
	m_m1 += ST.GetAt(i+1);
	m_m1 += "  error";
	m_m1 += "\r";
	m_m1 += "\n";
}

⌨️ 快捷键说明

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