📄 analyzerdlg.cpp
字号:
// analyzerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "analyzer.h"
#include "analyzerDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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)
//}}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)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAnalyzerDlg dialog
CAnalyzerDlg::CAnalyzerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CAnalyzerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAnalyzerDlg)
m_Edit1 = _T("");
m_Edit2 = _T("");
m_Edit3 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
flag=0;
createTable();
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CAnalyzerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAnalyzerDlg)
DDX_Text(pDX, IDC_EDIT1, m_Edit1);
DDX_Text(pDX, IDC_EDIT2, m_Edit2);
DDX_Text(pDX, IDC_EDIT3, m_Edit3);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAnalyzerDlg, CDialog)
//{{AFX_MSG_MAP(CAnalyzerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAnalyzerDlg message handlers
BOOL CAnalyzerDlg::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 CAnalyzerDlg::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 CAnalyzerDlg::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 CAnalyzerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CAnalyzerDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CFileDialog dlg(TRUE, NULL, NULL,
OFN_HIDEREADONLY |OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT,
"C++ source|*.cpp|All files|*.*|*.txt|*.c||");
CString FilePathName;
if(dlg.DoModal()==IDOK)
FilePathName=dlg.GetPathName();
CString str;
str = "";
s_str="";
flag=1;
CStdioFile mFile;
if(!mFile.Open(FilePathName,CFile::modeRead|CFile::typeText,NULL))
{
AfxMessageBox("打开文件失败!");
return;
}
while(mFile.GetPosition()!=mFile.GetLength())
{
mFile.ReadString(str);
str+="\r\n";
s_str+=str;
}
mFile.Close();
//读取的文件存放于s_str中
m_Edit1=s_str;
UpdateData(false);
}
void CAnalyzerDlg::OnButton2()
{
// TODO: Add your control notification handler code here
if(flag==0)
{
AfxMessageBox("尚未打开文件!");
return;
}
if(flag>=2)return;
if(flag<2)flag=2;
bool IsBC;
bool useful;
useful=false;
IsBC=true;/* 标志,表示前一次输入为空格,初始为true保证处理结果不以空格开头*/
n_position=0;/*表示读取位置*/
m_Edit2="";
s_str2="";
CString str;
str="";
while(n_position!=s_str.GetLength())
{
getChar();
if((c_char==' '||c_char=='\t'||c_char=='\n'||c_char=='\r')&&useful==false)
{
if(!IsBC)
{
s_str2+=' ';
IsBC=true;
}
//getBC();
}
else if(c_char=='/')
{
str=c_char;
getChar();
if(c_char=='/')
{
do getChar();
while(c_char!='\n');
}
else if(c_char=='*')
{
while(true)
{
do getChar();
while(c_char!='*');
getChar();
if(c_char=='/')break;
else n_position--;
}
}
else
{
if(c_char=='\"'||c_char=='\'')
{
if(useful)useful=false;
else useful=true;
}
str+=c_char;
s_str2+=str;
IsBC=false;
}
}
else
{
if(c_char=='\"'||c_char=='\'')
{
if(useful)useful=false;
else useful=true;
}
s_str2+=c_char;
IsBC=false;
}
}
//预处理的结果已经存储于s_str2中。
/*本函数以下部分为了实现打印输出的换行*/
int i;
char ss;
int len=s_str2.GetLength();
for(i=0;i<len;)
{
ss=s_str2[i++];
m_Edit2+=ss;
if(i%70==0)
{
m_Edit2+="\r\n";
}
}
//m_Edit2=s_str2;/*用本条指令无法完成换行输出*/
UpdateData(false);
}
void CAnalyzerDlg::OnButton3()
{
// TODO: Add your control notification handler code here
if(flag==0)
{
AfxMessageBox("尚未打开文件!");
return;
}
if(flag==1)
{
AfxMessageBox("尚未预处理!");
return;
}
if(flag==3)return;
if(flag<3)flag=3;
int t;
for(t=0;t<300;t++)
{
constTable[t]=-1;
}
for(t=0;t<200;t++)
{
IDTable[t].note="";
}
CString str;
str=s_str;
s_str=s_str2;
s_str2=str;
bool useful=false;
int code,value;
int length=s_str.GetLength();
n_position=0;
IDTP=0;
cTP=0;
m_Edit3="";
str="";
CString str2;
while(n_position<length)
{
strToken="";
getChar();
if(c_char==' ')
{
/*if(useful)
{
concat();
getChar();
}*/
}
else if(isLetter())
{
while(isLetter()||isDigit())
{
concat();
getChar();
}
retract();
code=isKey();
if(code==0)
{
value=insertID();
str2.Format("(49,%d)",value);
str+=str2;
}
else
{
str2.Format("(%d,-)",code);
str+=str2;
}
}
else if(isDigit())
{
while(isDigit())
{
concat();
getChar();
}
retract();
value=insertConst();
str2.Format("(50,%d)",value);
str+=str2;
}
else if(c_char=='(')
{
str2.Format("(LPAR,-)");
str+=str2;
}
else if(c_char==')')
{
str2.Format("(RPAR,-)");
str+=str2;
}
else if(c_char=='[')
{
str2.Format("( [,-)");
str+=str2;
}
else if(c_char==']')
{
str2.Format("( ],-)");
str+=str2;
}
else if(c_char=='{')
{
str2.Format("( {,-)");
str+=str2;
}
else if(c_char=='}')
{
str2.Format("( },-)");
str+=str2;
}
else if(c_char=='-')
{
//concat();
getChar();
if(c_char=='>')
{
str2.Format("( ->,-)");
str+=str2;
}
else if(c_char=='-')
{
str2.Format("( --,-)");
str+=str2;
}
else if(c_char=='=')
{
str2.Format("( -=,-)");
str+=str2;
}
else
{
retract();
str2.Format("( -,-)");
str+=str2;
}
}
else if(c_char=='.')
{
str2.Format("( .,-)");
str+=str2;
}
else if(c_char==':')
{
getChar();
if(c_char==':')
{
str2.Format("( ::,-)");
str+=str2;
}
else
{
retract();
str2.Format("( :,-)");
str+=str2;
}
}
else if(c_char=='+')
{
getChar();
if(c_char=='+')
{
str2.Format("( ++,-)");
str+=str2;
}
else if(c_char=='=')
{
str2.Format("( +=,-)");
str+=str2;
}
else
{
retract();
str2.Format("( +,-)");
str+=str2;
}
}
else if(c_char=='!')
{
getChar();
if(c_char=='=')
{
str2.Format("( !=,-)");
str+=str2;
}
else
{
retract();
str2.Format("( !,-)");
str+=str2;
}
}
else if(c_char=='~')
{
str2.Format("( ~,-)");
str+=str2;
}
else if(c_char=='*')
{
getChar();
if(c_char=='=')
{
str2.Format("( *=,-)");
str+=str2;
}
else
{
retract();
str2.Format("( *,-)");
str+=str2;
}
}
else if(c_char=='&')
{
getChar();
if(c_char=='&')
{
str2.Format("( &&,-)");
str+=str2;
}
else if(c_char=='=')
{
str2.Format("( &=,-)");
str+=str2;
}
else
{
retract();
str2.Format("( &,-)");
str+=str2;
}
}
else if(c_char=='/')
{
getChar();
if(c_char=='=')
{
str2.Format("( /=,-)");
str+=str2;
}
else
{
retract();
str2.Format("( /,-)");
str+=str2;
}
}
else if(c_char=='%')
{
getChar();
if(c_char=='=')
{
str2.Format("( %=,-)");
str+=str2;
}
else
{
retract();
str2.Format("( %,-)");
str+=str2;
}
}
else if(c_char=='<')
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -