📄 scannerview.cpp
字号:
// scannerView.cpp : implementation of the CScannerView class
//
#include "stdafx.h"
#include "scanner.h"
//#include "DemoView.h"
//#include "CompileWord.h"
#include "scannerView.h"
#include "SimpleCompiler.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CScannerApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CScannerView
IMPLEMENT_DYNCREATE(CScannerView, CEditView)
BEGIN_MESSAGE_MAP(CScannerView, CEditView)
//{{AFX_MSG_MAP(CScannerView)
ON_COMMAND(ID_COMPILE_WORD, OnCompileWord)
ON_COMMAND(ID_FILE_SAVE, OnFileSave)
ON_COMMAND(ID_COMPILE_GRAMMER, OnCompileGrammer)
ON_COMMAND(ID_COMPILE_MEANING, OnCompileMeaning)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_UPDATE_COMMAND_UI(ID_COMPILE_GRAMMER, OnUpdateCompileGrammer)
ON_UPDATE_COMMAND_UI(ID_COMPILE_MEANING, OnUpdateCompileMeaning)
ON_UPDATE_COMMAND_UI(ID_COMPILE_WORD, OnUpdateCompileWord)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CEditView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CEditView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CEditView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CScannerView construction/destruction
CScannerView::CScannerView()
{
// TODO: add construction code here
m_SCompiler=new CSimpleCompiler();
this->m_readySC=false;
}
CScannerView::~CScannerView()
{
delete m_SCompiler;
}
BOOL CScannerView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
BOOL bPreCreated = CEditView::PreCreateWindow(cs);
cs.style &= ~(ES_AUTOHSCROLL|WS_HSCROLL); // Enable word-wrapping
return bPreCreated;
}
/////////////////////////////////////////////////////////////////////////////
// CScannerView drawing
void CScannerView::OnDraw(CDC* pDC)
{
CScannerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CScannerView printing
BOOL CScannerView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default CEditView preparation
return CEditView::OnPreparePrinting(pInfo);
}
void CScannerView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// Default CEditView begin printing.
CEditView::OnBeginPrinting(pDC, pInfo);
}
void CScannerView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// Default CEditView end printing
CEditView::OnEndPrinting(pDC, pInfo);
}
/////////////////////////////////////////////////////////////////////////////
// CScannerView diagnostics
#ifdef _DEBUG
void CScannerView::AssertValid() const
{
CEditView::AssertValid();
}
void CScannerView::Dump(CDumpContext& dc) const
{
CEditView::Dump(dc);
}
CScannerDoc* CScannerView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CScannerDoc)));
return (CScannerDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CScannerView message handlers
void CScannerView::OnCompileWord()
{
//CDemoView *pWnd;
//pWnd=(CDemoView *)m_wndSplitter.GetPane(1,0);
//pWnd->OnPrin();
// TODO: Add your command handler code here
//如果做了修改就保存源程序
//ModifySave();
if (!ModifySave()) return;
//PTokenNode pTokenFile; //token串头指针
//PErrorNode pErrorCollection; //错误信息头指针
this->m_SCompiler->SetSourceFile(((CScannerDoc *)this->GetDocument())->GetPathName());
this->m_SCompiler->RunMorpheme();
//pTokenFile = this->m_SCompiler->GetTokenFile();
//pErrorCollection = this->m_SCompiler->GetErrorCollection();
//在相应分割视图中显示
CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
pFrame->m_pWnd->MyDrawing(m_SCompiler->GetErrorCollection());
pFrame->m_pWnd1->MyDrawing(m_SCompiler->GetTokenFile());
//pFrame->m_pWnd2->MyDrawing(m_SCompiler->GetErrorCollection());
// strName.SetAt(strName.GetLength()+1,'a');
// str=pDoc->GetTitle();
// str=pDoc->GetPathName();
// this->GetDC()->TextOut(10,10,str1.Left(6)+str);
// str=CScannerDoc::GetTitle();
//CString strErrorOut;
//strErrorOut.Empty();
// strName=scanner.IntoStr(54343);
// MessageBox(strName,strPathName);
/* CCompileWord scanner;
scanner.WordScanner(strName,strPathName);
CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
pFrame->m_pWnd->MyDrawing(scanner.GetError());
*/
// strErrorOut=scanner.GetError();
// if(!scanner.GetError().IsEmpty())
// MessageBox(scanner.GetError(),"compiler infomation!");
// else
// MessageBox("Success!","compiler infomation!");
// MessageBox(strError,strPathName);
// OnDraw(this->GetDC());
// MessageBox("源文件未保存或不能打开!","Error");
}
void CScannerView::OnCompileGrammer()
{
// TODO: Add your command handler code here
//如果做了修改就保存源程序
//ModifySave();
if (!ModifySave()) return;
//执行语法分析
this->m_SCompiler->SetSourceFile(((CScannerDoc *)this->GetDocument())->GetPathName());
CString str;
str.Empty();
this->m_SCompiler->RunParsing();
CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
pFrame->m_pWnd->MyDrawing(m_SCompiler->GetErrorCollection());
pFrame->m_pWnd1->MyDrawing(m_SCompiler->GetTokenFile());
pFrame->m_pWnd2->MyDrawingResult(str);
}
void CScannerView::OnCompileMeaning()
{
// TODO: Add your command handler code here
//如果做了修改就保存源程序
if(!ModifySave())return;
//执行语义分析
//
this->m_SCompiler->SetSourceFile(((CScannerDoc *)this->GetDocument())->GetPathName());
CString str;
str.Empty();
this->m_SCompiler->RunSemantic();
CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
pFrame->m_pWnd->MyDrawing(m_SCompiler->GetErrorCollection());
pFrame->m_pWnd1->MyDrawing(m_SCompiler->GetTokenFile());
pFrame->m_pWnd2->MyDrawingFourElement(m_SCompiler->GetFSymbol());
}
void CScannerView::OnFileSave()
{
// TODO: Add your command handler code here
//m_isChange=false; //保存后设定已更新源文件,可以开始分析
CScannerDoc *pDoc=(CScannerDoc *)this->GetDocument();
if (!pDoc->GetPathName().IsEmpty())
{
pDoc->OnSaveDocument(pDoc->GetPathName());
return;
}
CString strPathName;
CFileDialog fd(false,"txt",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"文本文档(*.txt)|*.txt|所有文件(*.*)|*.*|");
fd.m_ofn.lpstrTitle="保存";
if(fd.DoModal()==IDOK)
{
pDoc->SetPathName((LPCTSTR)(strPathName=fd.GetPathName()));
pDoc->OnSaveDocument(strPathName);
}
}
bool CScannerView::ModifySave()
{
/*
CScannerDoc* pDoc = GetDocument();
CString strName=pDoc->GetTitle();
CString strPathName=pDoc->GetPathName();
if(strName.IsEmpty()||strPathName.IsEmpty()||m_isChange)
{
OnFileSave();
}
*/
CScannerDoc *pDoc=(CScannerDoc *)this->GetDocument();
CString strPathName=pDoc->GetPathName();
if (strPathName.IsEmpty())
{
if (pDoc->IsModified())
{
if (this->MessageBox("是否保存源程序!","错误操作",MB_ICONWARNING | MB_OKCANCEL)==IDCANCEL)
{
return false;
}
else
{
CFileDialog fd(false,"txt",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"文本文档(*.txt)|*.txt|所有文件(*.*)|*.*|");
fd.m_ofn.lpstrTitle="请选择你要保存的文件";
if(fd.DoModal()==IDOK)
{
pDoc->SetPathName((LPCTSTR)(strPathName=fd.GetPathName()));
}
else
{
return false;
}
}
}
else
{
this->MessageBox("请输入或打开源程序!","错误操作",MB_ICONWARNING | MB_OK);
return false;
}
}
pDoc->OnSaveDocument((LPCTSTR)strPathName);
return true;
}
void CScannerView::OnFileOpen()
{
// TODO: Add your command handler code here
CScannerDoc *pDoc=(CScannerDoc *)this->GetDocument();
CString strPathName;
CFileDialog fd(true,"txt",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"文本文档(*.txt)|*.txt|所有文件(*.*)|*.*|");
fd.m_ofn.lpstrTitle="打开";
if(fd.DoModal()==IDOK)
{
pDoc->SetPathName((LPCTSTR)(strPathName=fd.GetPathName()));
pDoc->OnOpenDocument(strPathName);
}
}
void CScannerView::OnUpdateCompileWord(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
char strTemp[10];
if (this->GetEditCtrl().GetLine(0,strTemp,9)>0 || this->GetEditCtrl().GetLineCount()>1)
{
this->m_readySC=true;
}
else
{
this->m_readySC=false;
}
pCmdUI->Enable(this->m_readySC);
}
void CScannerView::OnUpdateCompileGrammer(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(this->m_readySC);
}
void CScannerView::OnUpdateCompileMeaning(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(this->m_readySC);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -