📄 operandanalyzerdlg.cpp
字号:
// OperandAnalyzerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "OperandAnalyzer.h"
#include "OperandAnalyzerDlg.h"
#include "grammar.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()
/////////////////////////////////////////////////////////////////////////////
// COperandAnalyzerDlg dialog
COperandAnalyzerDlg::COperandAnalyzerDlg(CWnd* pParent /*=NULL*/)
: CDialog(COperandAnalyzerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(COperandAnalyzerDlg)
m_subaOPG = _T("");
m_pedit = _T("");
m_sedit = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void COperandAnalyzerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(COperandAnalyzerDlg)
DDX_Control(pDX, IDC_LIST4, m_analyse);
DDX_Control(pDX, IDC_LIST3, m_first_table);
DDX_Control(pDX, IDC_LIST2, m_LastVT);
DDX_Control(pDX, IDC_LIST1, m_firstVT);
DDX_Text(pDX, IDC_EDIT3, m_pedit);
DDX_Text(pDX, IDC_EDIT2, m_sedit);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(COperandAnalyzerDlg, CDialog)
//{{AFX_MSG_MAP(COperandAnalyzerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON3, OnAboutDlg)
ON_BN_CLICKED(IDC_BUTTON1, OnFileOpen)
ON_BN_CLICKED(IDC_BUTTON6, OnFirstVTSet)
ON_BN_CLICKED(IDC_BUTTON5, OnLastVTSet)
ON_BN_CLICKED(IDC_BUTTON2, OnOPGMatrix)
ON_BN_CLICKED(IDC_BUTTON4, OnAnalyzeString)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COperandAnalyzerDlg message handlers
BOOL COperandAnalyzerDlg::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 COperandAnalyzerDlg::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 COperandAnalyzerDlg::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 COperandAnalyzerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void COperandAnalyzerDlg::OnAboutDlg()
{
// TODO: Add your control notification handler code here
CAboutDlg myAboutDlg;
myAboutDlg.DoModal();
}
void COperandAnalyzerDlg::OnFileOpen()
{
// TODO: Add your control notification handler code here
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"Text Files(*.txt, *.src)|*.txt; *.src");
if(dlg.DoModal() == IDOK)
{
m_strfilenamepath = dlg.GetPathName();
m_fileinput.open((char *)m_strfilenamepath.GetBuffer(0), ios::nocreate);
if(m_fileinput.fail())
{
m_pedit = "无法打开!!!\r\n或是错误文件名\r\n或是此软件出现了问题,建议\r\n在编辑框中直接输入测试程序";
UpdateData(false);
}
else
{
m_pedit = "";
char str[61];
do
{
m_fileinput.getline(str,60, '\n');
m_pedit += str;
if(str[strlen(str) - 2] == '\r')
m_pedit += "\n";
else
m_pedit += "\r\n";
}while(!m_fileinput.eof());
UpdateData(false);
m_fileinput.close();
}
}
}
void COperandAnalyzerDlg::OnFirstVTSet()
{
// TODO: Add your control notification handler code here
if(m_pedit.IsEmpty())
::AfxMessageBox("还未读入算符优先文法!");
else
{
UpdateData(true);
Cgrammar grammar(m_pedit);
grammar.delete_list(m_firstVT);
grammar.getFirstVT(m_firstVT);
UpdateData(false);
grammar.~Cgrammar();
}
}
void COperandAnalyzerDlg::OnLastVTSet()
{
// TODO: Add your control notification handler code here
if(m_pedit.IsEmpty())
::AfxMessageBox("还未读入算符优先文法!");
else
{
UpdateData(true);
Cgrammar grammar(m_pedit);
grammar.delete_list(m_LastVT);
grammar.LastVT(m_LastVT);
UpdateData(false);
grammar.~Cgrammar();
}
}
//*************************************************************
//生成算符优先矩阵
//
//*************************************************************
void COperandAnalyzerDlg::OnOPGMatrix()
{
// TODO: Add your control notification handler code here
if(m_pedit.IsEmpty())
::AfxMessageBox("还未读入算符优先文法!");
else
{
UpdateData(true);
Cgrammar grammar(m_pedit);
grammar.add_produce();
grammar.delete_list(m_firstVT);
grammar.delete_list(m_LastVT);
grammar.delete_list(m_first_table);
grammar.getFirstVT(m_firstVT);
grammar.LastVT(m_LastVT);
grammar.first_table_head(m_first_table);
grammar.first_table(m_first_table, m_firstVT, m_LastVT);
UpdateData(false);
grammar.~Cgrammar();
}
}
//*************************************************************
//分析一个输入的待归约串
//
//*************************************************************
void COperandAnalyzerDlg::OnAnalyzeString()
{
// TODO: Add your control notification handler code here
if(m_pedit.IsEmpty())
::AfxMessageBox("还未读入算符优先文法!", MB_OK);
else
{
UpdateData(true);
Cgrammar grammar(m_pedit); //定义文法变量
grammar.add_produce();
grammar.delete_list(m_firstVT); //清空各个列表中的内容
grammar.delete_list(m_LastVT);
grammar.delete_list(m_first_table);
grammar.delete_list(m_analyse);
grammar.getFirstVT(m_firstVT); //构建firstVT,LastVT,first_table(优先表)
grammar.LastVT(m_LastVT);
grammar.first_table_head(m_first_table);
grammar.first_table(m_first_table, m_firstVT, m_LastVT);
grammar.delete_blank(m_sedit); //消去空格
grammar.first_analyse_head(m_analyse, m_sedit); //构建分析表
grammar.first_analyse(m_analyse, m_sedit, m_first_table);
UpdateData(false);
grammar.~Cgrammar();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -