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

📄 grammeranalyzeview.cpp

📁 这是一个司法分析程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// GrammerAnalyzeView.cpp : implementation of the CGrammerAnalyzeView class
//

#include "stdafx.h"
#include "GrammerAnalyze.h"

#include "GrammerAnalyzeDoc.h"
#include "GrammerAnalyzeView.h"
#include "Show.h"

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

/////////////////////////////////////////////////////////////////////////////
// CGrammerAnalyzeView

IMPLEMENT_DYNCREATE(CGrammerAnalyzeView, CEditView)

BEGIN_MESSAGE_MAP(CGrammerAnalyzeView, CEditView)
	//{{AFX_MSG_MAP(CGrammerAnalyzeView)
	ON_COMMAND(ID_BUTTON_ENTER, OnButtonEnter)
	ON_COMMAND(ID_BUTTON_START, OnButtonStart)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CGrammerAnalyzeView construction/destruction

CGrammerAnalyzeView::CGrammerAnalyzeView()
{
	
	word=0;
	error=0;
	Source="";
	flag=-1;
	is_Enter=false;


}

CGrammerAnalyzeView::~CGrammerAnalyzeView()
{
}

BOOL CGrammerAnalyzeView::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;
}

/////////////////////////////////////////////////////////////////////////////
// CGrammerAnalyzeView drawing

void CGrammerAnalyzeView::OnDraw(CDC* pDC)
{
	CGrammerAnalyzeDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CGrammerAnalyzeView printing

BOOL CGrammerAnalyzeView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default CEditView preparation
	return CEditView::OnPreparePrinting(pInfo);
}

void CGrammerAnalyzeView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// Default CEditView begin printing.
	CEditView::OnBeginPrinting(pDC, pInfo);
}

void CGrammerAnalyzeView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// Default CEditView end printing
	CEditView::OnEndPrinting(pDC, pInfo);
}

/////////////////////////////////////////////////////////////////////////////
// CGrammerAnalyzeView diagnostics

#ifdef _DEBUG
void CGrammerAnalyzeView::AssertValid() const
{
	CEditView::AssertValid();
}

void CGrammerAnalyzeView::Dump(CDumpContext& dc) const
{
	CEditView::Dump(dc);
}

CGrammerAnalyzeDoc* CGrammerAnalyzeView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGrammerAnalyzeDoc)));
	return (CGrammerAnalyzeDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CGrammerAnalyzeView message handlers

void CGrammerAnalyzeView::OnButtonEnter() 
{
	Source="";
	is_Enter=true;
	CGrammerAnalyzeApp*app=(CGrammerAnalyzeApp*)AfxGetApp();
	app->error_list.DeleteAllItems();
	app->word_list.DeleteAllItems();

	this->Invalidate();

	CFileDialog fileDlg(TRUE);
	if(IDOK != fileDlg.DoModal())
		return;
	CFile file(fileDlg.GetFileName(),CFile::modeRead);
	Source.GetBufferSetLength(file.GetLength());
	file.Read(Source.GetBuffer(file.GetLength()), file.GetLength());
	
	//char *text=new char[strlen(Source)+1];
//	strcpy(text,Source);
	this->SetWindowText(Source);

	//CRect rect;
//	GetClientRect(rect);
//	rect.left=rect.left+10;;

//	CDC *p=GetDC();
    //p->DrawText(text,rect,0);
	
}


void CGrammerAnalyzeView::OnButtonStart() 
{
	word=0;
	error=0;
	flag=-1;
    CString m_source;
    this->GetWindowText(m_source);
	if(m_source!=Source)
	{
		is_Enter=false;
	
	}

	if(!is_Enter)
	{
		Source="";
		this->GetWindowText(Source);
		
	}
	else
	{
		is_Enter=false;
	
	}

	CGrammerAnalyzeApp*app=(CGrammerAnalyzeApp*)AfxGetApp();
	app->error_list.DeleteAllItems();
	app->word_list.DeleteAllItems();

	Start();
	
}


void CGrammerAnalyzeView::Start()
{
	CGrammerAnalyzeApp*app=(CGrammerAnalyzeApp*)AfxGetApp();
	char *text=new char[strlen(Source)+1];
	strcpy(text,Source);

	

    char str[50];//用语存放单词
	char *point;//记录单词的起始位置
	char *pre_point;//向前试探的指针
	char *r_pre;//记录pre_point的前一字符

	point =text;
	while(*point==32||*point==13||*point==10)
		point++;//跳过空格,回车换行

	pre_point=point+1;
	r_pre=pre_point-1;
	
	bool ifdo=false;
    unsigned len=1;
	while(len<strlen(text))
	{
	    
		if(*pre_point!=32&&*pre_point!=13&&*pre_point!=10&&*pre_point!='('
			&&*pre_point!=')'&&*pre_point!='+'&&*pre_point!='-'&&*pre_point!='>'
			&&*pre_point!='='&&*pre_point!='<'&&*pre_point!=','&&*pre_point!=';'
			&&*pre_point!='{'&&*pre_point!='}')
		{
			r_pre=pre_point;
			pre_point++;
			len++;
			ifdo=true;
		
		}
		else
		{
			if(*pre_point==13)//跳过回车符号
			{
				
				len=len+2;
				pre_point=pre_point+2;
				
				if(!ifdo)//跳过回车
				{
					point=pre_point;	
					continue;
				}
			
			
			}

			if(*pre_point==32)
			{
				len++;
				pre_point=pre_point+1;
			
				if(!ifdo)//跳过空格
				{
					point=pre_point;	
					continue;
				}
			
			}

			if(*pre_point=='(')
			{
				len++;
				pre_point=pre_point+1;

				for(int i=0;i<word;i++)//在列表中找"("
				{
					CString find=app->word_list.GetItemText(i,0);
					if(strcmp(find,"(")==0)
						break;
			
				}
				if(i==word)
				{
					app->word_list.InsertItem(word,"(");
					app->word_list.SetItemText(word,1,"15");
					app->word_list.SetItemText(word,2,"左括号");
					word++;
				}
			
			}

			if(*pre_point==')')
			{
				len++;
				pre_point=pre_point+1;

				for(int i=0;i<word;i++)//在列表中找")"
				{
					CString find=app->word_list.GetItemText(i,0);
					if(strcmp(find,")")==0)
						break;
			
				}
				if(i==word)
				{
					app->word_list.InsertItem(word,")");
					app->word_list.SetItemText(word,1,"16");
					app->word_list.SetItemText(word,2,"右括号");
					word++;
				}
			
			}

			if(*pre_point==',')
			{
				len++;
				pre_point=pre_point+1;
				for(int i=0;i<word;i++)
				{
					CString find=app->word_list.GetItemText(i,0);
					if(strcmp(find,",")==0)
						break;
			
				}
				if(i==word)
				{
					app->word_list.InsertItem(word,",");
					app->word_list.SetItemText(word,1,"16");
					app->word_list.SetItemText(word,2,"逗号");
					word++;
				}
			
			}

			if(*pre_point=='{')
			{
				len++;
				pre_point=pre_point+1;

				for(int i=0;i<word;i++)
				{
					CString find=app->word_list.GetItemText(i,0);
					if(strcmp(find,"{")==0)
						break;
			
				}
				if(i==word)
				{
					app->word_list.InsertItem(word,"{");
					app->word_list.SetItemText(word,1,"18");
					app->word_list.SetItemText(word,2,"函数体开始符号");
					word++;
				}

				if(!ifdo)
				{
					point=pre_point;	
					continue;
				}
			
			}

			if(*pre_point=='}')
			{
				len++;
				pre_point=pre_point+1;
				for(int i=0;i<word;i++)
				{
					CString find=app->word_list.GetItemText(i,0);
					if(strcmp(find,"}")==0)
						break;
			
				}
				if(i==word)
				{
					app->word_list.InsertItem(word,"}");
					app->word_list.SetItemText(word,1,"18");
					app->word_list.SetItemText(word,2,"函数体结束符号");
					word++;
				}

				if(!ifdo)
				{
					point=pre_point;	
					continue;
				}
			
			}


			if(*pre_point==';')
			{
				len++;
				pre_point=pre_point+1;
				for(int i=0;i<word;i++)
				{
					CString find=app->word_list.GetItemText(i,0);
					if(strcmp(find,";")==0)
						break;
			
				}
				if(i==word)
				{
					app->word_list.InsertItem(word,";");
					app->word_list.SetItemText(word,1,"16");
					app->word_list.SetItemText(word,2,"分号结束符");
					word++;
				}
			
			}


			if(*pre_point=='+')
			{
				len++;
				pre_point=pre_point+1;
				for(int i=0;i<word;i++)
				{
					CString find=app->word_list.GetItemText(i,0);
					if(strcmp(find,"+")==0)
						break;
			
				}
				if(i==word)
				{
					app->word_list.InsertItem(word,"+");
					app->word_list.SetItemText(word,1,"18");
					app->word_list.SetItemText(word,2,"加号");
					word++;
				}
			
			}

			if(*pre_point=='-')
			{
				len++;
				pre_point=pre_point+1;
				for(int i=0;i<word;i++)
				{
					CString find=app->word_list.GetItemText(i,0);
					if(strcmp(find,"-")==0)
						break;
			
				}
				if(i==word)
				{
					app->word_list.InsertItem(word,"-");
					app->word_list.SetItemText(word,1,"18");
					app->word_list.SetItemText(word,2,"减号");
					word++;
				}
			
			}

			if(*pre_point=='>')
			{
				len++;
				pre_point=pre_point+1;
				if(*pre_point=='=')
				{
					len++;
				    pre_point=pre_point+1;
					for(int i=0;i<word;i++)
					{
						CString find=app->word_list.GetItemText(i,0);
						if(strcmp(find,">=")==0)
							break;
			
					}
					if(i==word)
					{
						app->word_list.InsertItem(word,">=");
						app->word_list.SetItemText(word,1,"17");
						app->word_list.SetItemText(word,2,"大于等于号");
						word++;
					}

				
				}
				else
				{
					for(int i=0;i<word;i++)
					{
						CString find=app->word_list.GetItemText(i,0);
						if(strcmp(find,">")==0)
							break;
			
					}
					if(i==word)
					{
						app->word_list.InsertItem(word,">");
						app->word_list.SetItemText(word,1,"18");
						app->word_list.SetItemText(word,2,"大于号");
						word++;
					}
				
				
				}
				
			
			}
			

			if(*pre_point=='=')
			{
				len++;
				pre_point=pre_point+1;
				if(*pre_point=='=')
				{
					len++;
				    pre_point=pre_point+1;
					for(int i=0;i<word;i++)
					{
						CString find=app->word_list.GetItemText(i,0);
						if(strcmp(find,"==")==0)
							break;
			
					}
					if(i==word)
					{
						app->word_list.InsertItem(word,"==");
						app->word_list.SetItemText(word,1,"17");
						app->word_list.SetItemText(word,2,"大于等于号");
						word++;
					}

				
				}
				else
				{
					for(int i=0;i<word;i++)
					{
						CString find=app->word_list.GetItemText(i,0);
						if(strcmp(find,"=")==0)
							break;
			
					}
					if(i==word)
					{
						app->word_list.InsertItem(word,"=");
						app->word_list.SetItemText(word,1,"18");
						app->word_list.SetItemText(word,2,"等于号");
						word++;
					}
				
				
				}
				
			
			}


			if(*pre_point=='<')
			{
				len++;
				pre_point=pre_point+1;
				if(*pre_point=='=')
				{
					len++;
				    pre_point=pre_point+1;
					for(int i=0;i<word;i++)
					{
						CString find=app->word_list.GetItemText(i,0);
						if(strcmp(find,"<=")==0)
							break;
			
					}
					if(i==word)
					{
						app->word_list.InsertItem(word,"<=");
						app->word_list.SetItemText(word,1,"17");
						app->word_list.SetItemText(word,2,"小于等于号");
						word++;
					}

				
				}
				else
				{
					for(int i=0;i<word;i++)
					{
						CString find=app->word_list.GetItemText(i,0);
						if(strcmp(find,"<")==0)
							break;
			
					}
					if(i==word)
					{
						app->word_list.InsertItem(word,"<");
						app->word_list.SetItemText(word,1,"18");
						app->word_list.SetItemText(word,2,"小于号");
						word++;
					}
				
				
				}
				
			
			}


			int t1=-10;
			int t2=-10;
			int t3=-10;

            if(ifdo)
			{
				ifdo=false;
				int i=0;
				while(point<=r_pre)
				{
					str[i]=*point;
					i++;
					point++;
			
				}
				str[i]='\0';//记录当前的单词
				point=pre_point;//移动当前指针#include
				//AfxMessageBox(str);
				bool is_include=false;
				if(str[0]=='#'&&str[1]=='i'&&str[2]=='n'&&str[3]=='c'
					&&str[4]=='l'&&str[5]=='u'&&str[6]=='d'&&str[7]=='e')
					  is_include=true;

				if(!(str[0]=='"'||is_include
					||str[0]=='_'||(str[0]>=65&&str[0]<=90)

⌨️ 快捷键说明

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