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

📄 4rdview.cpp

📁 编译原理实验
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			break;
		}
		m_num++;
		if(m_num>=number)
			break;
		p=p->next;
	}
}

void CMy4rdView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	move=true;
	m_point=point;
//	::SetCursor(AfxGetApp()->LoadCursor(IDC_HND));

	CScrollView::OnLButtonDown(nFlags, point);
}

void CMy4rdView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	move=false;

	CScrollView::OnLButtonUp(nFlags, point);
}

void CMy4rdView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	for(int i=0;i<100;i++)
	{
		if(Pos[i]!=NULL)
			break;
	}
	if(i>=100)
		return;
	if(move==true)
	{
		m_x=m_x+point.x-m_point.x;
		m_y=m_y+point.y-m_point.y;
		m_point=point;
		/////要重新计算所有结点的坐标//////////////////////////////
		for(i=0;i<100;i++)
			Pos[i]=NULL;
		xy *p=new xy;
		p->x=m_x;
		p->y=m_y;
		Pos[root->No]=p;
		ZuoBiao(root->left,root,0);	//把所以结点的坐标算出来,储存在xy[]数组中
		ZuoBiao(root->right,root,0);
		////////////////////////////////////////////////////////////
		Invalidate();
	}

	CScrollView::OnMouseMove(nFlags, point);
}

void CMy4rdView::Caculate(CDC *pDC)		//单步计算输出
{
	listnode *p;
	node *temp;
	CString str;
	p=q.front->next;
	while(p!=NULL)
	{
		temp=p->data;
		switch((int)temp->code){
		case 1:
			pDC->TextOut(Pos[temp->No]->x,Pos[temp->No]->y,"+");
			if(temp->left!=NULL&&temp->right!=NULL)
			{
				pDC->MoveTo(Pos[temp->No]->x+3,Pos[temp->No]->y+15);
				pDC->LineTo(Pos[temp->left->No]->x+5,Pos[temp->left->No]->y);
				pDC->MoveTo(Pos[temp->No]->x+3,Pos[temp->No]->y+15);
				pDC->LineTo(Pos[temp->right->No]->x+5,Pos[temp->right->No]->y);
			}
			break;
		case 2:
			pDC->TextOut(Pos[temp->No]->x,Pos[temp->No]->y,"-");
			if(temp->left!=NULL&&temp->right!=NULL)
			{
				pDC->MoveTo(Pos[temp->No]->x+3,Pos[temp->No]->y+15);
				pDC->LineTo(Pos[temp->left->No]->x+5,Pos[temp->left->No]->y);
				pDC->MoveTo(Pos[temp->No]->x+3,Pos[temp->No]->y+15);
				pDC->LineTo(Pos[temp->right->No]->x+5,Pos[temp->right->No]->y);
			}
			break;
		case 3:
			pDC->TextOut(Pos[temp->No]->x,Pos[temp->No]->y,"*");
			if(temp->left!=NULL&&temp->right!=NULL)
			{
				pDC->MoveTo(Pos[temp->No]->x+3,Pos[temp->No]->y+15);
				pDC->LineTo(Pos[temp->left->No]->x+5,Pos[temp->left->No]->y);
				pDC->MoveTo(Pos[temp->No]->x+3,Pos[temp->No]->y+15);
				pDC->LineTo(Pos[temp->right->No]->x+5,Pos[temp->right->No]->y);
			}
			break;
		case 4:
			pDC->TextOut(Pos[temp->No]->x,Pos[temp->No]->y,"/");
			if(temp->left!=NULL&&temp->right!=NULL)
			{
				pDC->MoveTo(Pos[temp->No]->x+3,Pos[temp->No]->y+15);
				pDC->LineTo(Pos[temp->left->No]->x+5,Pos[temp->left->No]->y);
				pDC->MoveTo(Pos[temp->No]->x+3,Pos[temp->No]->y+15);
				pDC->LineTo(Pos[temp->right->No]->x+5,Pos[temp->right->No]->y);
			}
			break;
		case 7:
			if(table[temp->entry].evaluated==true)
			{
				pDC->SetTextColor(RGB(255,0,0));
				CString str;
				str.Format("=%.2f",table[temp->entry].value);
				pDC->TextOut(Pos[temp->No]->x,Pos[temp->No]->y,table[temp->entry].name+str);
				pDC->SetTextColor(RGB(0,0,0));
			}
			else
			{
				pDC->SetTextColor(RGB(0,0,255));
				pDC->TextOut(Pos[temp->No]->x,Pos[temp->No]->y,CString(table[temp->entry].name));
				pDC->SetTextColor(RGB(0,0,0));
			}
			break;
		case 8:
			str.Format("%.2f",temp->value);
			pDC->TextOut(Pos[temp->No]->x,Pos[temp->No]->y,str);
			break;
		case 9:
			pDC->TextOut(Pos[temp->No]->x,Pos[temp->No]->y,"DIV");
			if(temp->left!=NULL&&temp->right!=NULL)
			{
				pDC->MoveTo(Pos[temp->No]->x+3,Pos[temp->No]->y+15);
				pDC->LineTo(Pos[temp->left->No]->x+5,Pos[temp->left->No]->y);
				pDC->MoveTo(Pos[temp->No]->x+3,Pos[temp->No]->y+15);
				pDC->LineTo(Pos[temp->right->No]->x+5,Pos[temp->right->No]->y);
			}
			break;
		case 10:
			pDC->TextOut(Pos[temp->No]->x,Pos[temp->No]->y,"MOD");
			if(temp->left!=NULL&&temp->right!=NULL)
			{
				pDC->MoveTo(Pos[temp->No]->x+3,Pos[temp->No]->y+15);
				pDC->LineTo(Pos[temp->left->No]->x+5,Pos[temp->left->No]->y);
				pDC->MoveTo(Pos[temp->No]->x+3,Pos[temp->No]->y+15);
				pDC->LineTo(Pos[temp->right->No]->x+5,Pos[temp->right->No]->y);
			}
			break;
		case 11:
			pDC->TextOut(Pos[temp->No]->x,Pos[temp->No]->y,"+=");
			if(temp->left!=NULL&&temp->right!=NULL)
			{
				pDC->MoveTo(Pos[temp->No]->x+3,Pos[temp->No]->y+15);
				pDC->LineTo(Pos[temp->left->No]->x+5,Pos[temp->left->No]->y);
				pDC->MoveTo(Pos[temp->No]->x+3,Pos[temp->No]->y+15);
				pDC->LineTo(Pos[temp->right->No]->x+5,Pos[temp->right->No]->y);
			}
			break;
		case 12:
			pDC->TextOut(Pos[temp->No]->x,Pos[temp->No]->y,"-=");
			if(temp->left!=NULL&&temp->right!=NULL)
			{
				pDC->MoveTo(Pos[temp->No]->x+3,Pos[temp->No]->y+15);
				pDC->LineTo(Pos[temp->left->No]->x+5,Pos[temp->left->No]->y);
				pDC->MoveTo(Pos[temp->No]->x+3,Pos[temp->No]->y+15);
				pDC->LineTo(Pos[temp->right->No]->x+5,Pos[temp->right->No]->y);
			}
			break;
		case 13:
			pDC->TextOut(Pos[temp->No]->x,Pos[temp->No]->y,"*=");
			if(temp->left!=NULL&&temp->right!=NULL)
			{
				pDC->MoveTo(Pos[temp->No]->x+3,Pos[temp->No]->y+15);
				pDC->LineTo(Pos[temp->left->No]->x+5,Pos[temp->left->No]->y);
				pDC->MoveTo(Pos[temp->No]->x+3,Pos[temp->No]->y+15);
				pDC->LineTo(Pos[temp->right->No]->x+5,Pos[temp->right->No]->y);
			}
			break;
		case 14:
			pDC->TextOut(Pos[temp->No]->x,Pos[temp->No]->y,"/=");
			if(temp->left!=NULL&&temp->right!=NULL)
			{
				pDC->MoveTo(Pos[temp->No]->x+3,Pos[temp->No]->y+15);
				pDC->LineTo(Pos[temp->left->No]->x+5,Pos[temp->left->No]->y);
				pDC->MoveTo(Pos[temp->No]->x+3,Pos[temp->No]->y+15);
				pDC->LineTo(Pos[temp->right->No]->x+5,Pos[temp->right->No]->y);
			}
			break;
		}
		p=p->next;
	}
}

void CMy4rdView::initial()	//初始化各个参数
{
	input=true;
	m_count=1;
	m_tree=false;
	m_cal=false;
	ptree=false;
	m_x=400;
	m_y=50;
	m_inVar=false;
	move=false;
	first=false;
	out_cal=false;
	m_id=false;
	isok=true;
	ptree=false;
	q.Clear();
	qe.Clear();
	sl.Clear();
	m_result=false;
	for(int i=0;i<100;i++)
		Pos[i]=NULL;
	f_error=true;
}

void CMy4rdView::OnExample1()	//测试例子1
{
	// TODO: Add your command handler code here
	initial();
	m_Instring="测试例子 1:  0.85*first+(1-first)/second";
	m_tree=true;
	first=true;
	m_input=false;
	HideCaret();
	Invalidate();
	buffer[1]='0';
	buffer[2]='.';
	buffer[3]='8';
	buffer[4]='5';
	buffer[5]='*';
	buffer[6]='f';
	buffer[7]='i';
	buffer[8]='r';
	buffer[9]='s';
	buffer[10]='t';
	buffer[11]='+';
	buffer[12]='(';
	buffer[13]='1';
	buffer[14]='-';
	buffer[15]='f';
	buffer[16]='i';
	buffer[17]='r';
	buffer[18]='s';
	buffer[19]='t';
	buffer[20]=')';
	buffer[21]='/';
	buffer[22]='s';
	buffer[23]='e';
	buffer[24]='c';
	buffer[25]='o';
	buffer[26]='n';
	buffer[27]='d';
	buffer[28]='#';
}

void CMy4rdView::OnExample2()	//测试例子2
{
	// TODO: Add your command handler code here2*3+4*5
	initial();
	m_Instring="测试例子 2:  2*3+4*5";
	m_tree=true;
	first=true;
	m_input=false;
	HideCaret();
	Invalidate();
	buffer[1]='2';
	buffer[2]='*';
	buffer[3]='3';
	buffer[4]='+';
	buffer[5]='4';
	buffer[6]='*';
	buffer[7]='5';
	buffer[8]='#';
}

void CMy4rdView::OnExample3() 
{
	// TODO: Add your command handler code herea+(b+3)/2*3-4
	initial();
	m_Instring="测试例子 3:  a+(b+3)/2*3-4";
	m_tree=true;
	first=true;
	m_input=false;
	HideCaret();
	Invalidate();
	buffer[1]='a';
	buffer[2]='+';
	buffer[3]='(';
	buffer[4]='b';
	buffer[5]='+';
	buffer[6]='3';
	buffer[7]=')';
	buffer[8]='/';
	buffer[9]='2';
	buffer[10]='*';
	buffer[11]='3';
	buffer[12]='-';
	buffer[13]='4';
	buffer[14]='#';
}

void CMy4rdView::OnExample4() 
{
	// TODO: Add your command handler code here
	initial();
	m_Instring="测试例子 4:  2+(first+=5)/3*5-second";
	m_tree=true;
	first=true;
	m_input=false;
	HideCaret();
	Invalidate();
	buffer[1]='2';
	buffer[2]='+';
	buffer[3]='(';
	buffer[4]='f';
	buffer[5]='i';
	buffer[6]='r';
	buffer[7]='s';
	buffer[8]='t';
	buffer[9]='+';
	buffer[10]='=';
	buffer[11]='5';
	buffer[12]=')';
	buffer[13]='/';
	buffer[14]='3';
	buffer[15]='*';
	buffer[16]='5';
	buffer[17]='-';
	buffer[18]='s';
	buffer[19]='e';
	buffer[20]='c';
	buffer[21]='o';
	buffer[22]='n';
	buffer[23]='d';
	buffer[24]='#';
}

void CMy4rdView::OnExample5() 
{
	// TODO: Add your command handler code here
	initial();
	m_Instring="测试例子 5:  first DIV second MOD third";
	m_tree=true;
	first=true;
	m_input=false;
	HideCaret();
	Invalidate();
	buffer[1]='f';
	buffer[2]='i';
	buffer[3]='r';
	buffer[4]='s';
	buffer[5]='t';
	buffer[6]=' ';
	buffer[7]='D';
	buffer[8]='I';
	buffer[9]='V';
	buffer[10]=' ';
	buffer[11]='s';
	buffer[12]='e';
	buffer[13]='c';
	buffer[14]='o';
	buffer[15]='n';
	buffer[16]='d';
	buffer[17]=' ';
	buffer[18]='M';
	buffer[19]='O';
	buffer[20]='D';
	buffer[21]=' ';
	buffer[22]='t';
	buffer[23]='h';
	buffer[24]='i';
	buffer[25]='r';
	buffer[26]='d';
	buffer[27]='#';
}

void CMy4rdView::OnExample6() 
{
	// TODO: Add your command handler code here
	initial();
	m_Instring="测试例子 6:  1+2-3*4/5+a-b*c/d";
	m_tree=true;
	first=true;
	m_input=false;
	HideCaret();
	Invalidate();
	buffer[1]='1';
	buffer[2]='+';
	buffer[3]='2';
	buffer[4]='-';
	buffer[5]='3';
	buffer[6]='*';
	buffer[7]='4';
	buffer[8]='/';
	buffer[9]='5';
	buffer[10]='+';
	buffer[11]='a';
	buffer[12]='-';
	buffer[13]='b';
	buffer[14]='*';
	buffer[15]='c';
	buffer[16]='/';
	buffer[17]='d';
	buffer[18]='#';
}

⌨️ 快捷键说明

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