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

📄 phrase_check.cpp

📁 开发虚拟的被控对象及虚拟的PLC,模似PLC的工作过程进行实验。用户可根据具体的实验,确定其输入和输出的控制条件,用虚拟的连线和虚拟的PLC连接,用户利用梯形图的编程方式编写PLC程序控制被控对象的动
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	if (place==k)
		return(0);
	if(tidystr[i][place]!='\0')
		return(0);
	else
	{
		int m;
		m=accountnumber(i,place,k);
		if (m==-1)
			return(0);
        instructionstore[i].register1number=m;
	}
	return(1);
}

int Storeandcheckinstruction(int i,int j)//将指令存入,分析指令
{                                         //有无语法错误 
 	instructionstore[i].instructionname=j;
	if (((j==1)||(j==5))||(j==7))//指令1 (ST)(AN)(OR)
	{
		switch (tidystr[i][3])
		{
		case'X':instructionstore[i].relaysort='X';break;
        case'Y':instructionstore[i].relaysort='Y';break;
		case'R':instructionstore[i].relaysort='R';break;
		case'T':instructionstore[i].relaysort='T';break;
		default: return (1);
		}
        int l=countnumber(i,4);
	    if(l==4)
			return(9);
		int theNO=accountnumber(i,l,4);
		if (theNO==-1)
			return(2);
		if((instructionstore[i].relaysort=='X')||
			(instructionstore[i].relaysort=='Y'))
		{
			if(theNO>256)
				return(3);
		}
		if(instructionstore[i].relaysort=='R')
		{
			if(theNO>1000)
				return(3);
		}
		if(instructionstore[i].relaysort=='T')
		{
			if(theNO>100)
				return(3);
		}
		instructionstore[i].relaynumber=theNO;		
	}
	
	else if (((j==2)||(j==6))||(j==8))//指令2 (ST/)(AN/)(OR/)
	{
		switch (tidystr[i][4])
		{
		case'X':instructionstore[i].relaysort='X';break;
        case'Y':instructionstore[i].relaysort='Y';break;
		case'R':instructionstore[i].relaysort='R';break;
		case'T':instructionstore[i].relaysort='T';break;
		default: return (1);
		}
		int l=countnumber(i,5);
		if(l==5)
			return(9);
		int theNO=accountnumber(i,l,5);
		if (theNO==-1)
			return(2);
		if((instructionstore[i].relaysort=='X')||
			(instructionstore[i].relaysort=='Y'))
		{
			if(theNO>256)
				return(3);
		}
		if(instructionstore[i].relaysort=='R')
		{
			if(theNO>1000)
				return(3);
		}
		if(instructionstore[i].relaysort=='T')
		{
			if(theNO>100)
				return(3);
		}
		instructionstore[i].relaynumber=theNO;
		
	  }
	else if ((j==3)||(j==19))//指令3  (OT)(KP)
	{
		switch (tidystr[i][3])
		{
		case'X':return(4);
        case'Y':instructionstore[i].relaysort='Y';break;
		case'R':instructionstore[i].relaysort='R';break;
		case'T':return(4);
		default: return (1);
		}
		int l=countnumber(i,4);
		if(l==4)
			return(9);
		int theNO=accountnumber(i,l,4);
		if (theNO==-1)
			return(2);
		if(instructionstore[i].relaysort=='Y')
		{
			if(theNO>256)
				return(3);
		}
		if(instructionstore[i].relaysort=='R')
		{
			if(theNO>1000)
				return(3);
		}
		instructionstore[i].relaynumber=theNO;
	}
	else if ((j==16)||(j==17))//指令16  (SET)(RET)
	{
		switch (tidystr[i][4])
		{
		case'X':return(5);
        case'Y':instructionstore[i].relaysort='Y';break;
		case'R':instructionstore[i].relaysort='R';break;
		case'T':return(5);
		default: return (1);
		}
		int l=countnumber(i,5);
		if(l==5)
			return(9);
		int theNO=accountnumber(i,l,5);
		if (theNO==-1)
			return(2);
		if(instructionstore[i].relaysort=='Y')
		{
			if(theNO>256)
				return(3);
		}
		if(instructionstore[i].relaysort=='R')
		{
			if(theNO>1000)
				return(3);
		}
		instructionstore[i].relaynumber=theNO;
	}
	else	if (j==20)//指令1 (TMX)
	{
		int theNO;
        switch(tidystr[i][4])
		{
		case'0':theNO=0;break;
	    case'1':theNO=1;break;
        case'2':theNO=2;break;
		case'3':theNO=3;break;
		case'4':theNO=4;break;
		case'5':theNO=5;break;
		case'6':theNO=6;break;
		case'7':theNO=7;break;
		case'8':theNO=8;break;
		case'9':theNO=9;break;
		default:return(2);
		}	
		instructionstore[i].relaynumber=theNO;
    	if ((tidystr[i][5]!=' ')&&(tidystr[i][6]!='K'))
			return(10);
	    int 	place=7;
		int place1=0;
		while(tidystr[i][place+place1]!='\0')
			place1+=1;
		theNO=0;
		for(int nn=0;nn<place1;nn++)
		{
			int check=switchint(tidystr[i][place+nn]);
			if ( check==10)
				return(7);
			else
		  theNO=10*theNO+switchint(tidystr[i][place+nn]);
		}
		instructionstore[i].thenumber=theNO;
	}
  else	if ((j==21)||(j==23))//指令1 ( MC,JP)
  {
		int theNO;
        switch(tidystr[i][3])
		{
		case'0':theNO=0;break;
	    case'1':theNO=1;break;
        case'2':theNO=2;break;
		case'3':theNO=3;break;
		case'4':theNO=4;break;
		case'5':theNO=5;break;
		case'6':theNO=6;break;
		case'7':theNO=7;break;
		case'8':theNO=8;break;
		case'9':theNO=9;break;
		default:return(2);
		}
		if (tidystr[i][4]!='\0')
			return(6);
		instructionstore[i].thenumber=theNO;
	}	
  else if ((j==22)||(j==24))//指令1 (LBL)(MCE)	
  {
	  int theNO;
      switch(tidystr[i][4])
	  {
	  case'0':theNO=0;break;
	  case'1':theNO=1;break;
      case'2':theNO=2;break;
	  case'3':theNO=3;break;
	  case'4':theNO=4;break;
	  case'5':theNO=5;break;
	  case'6':theNO=6;break;
	  case'7':theNO=7;break;
	  case'8':theNO=8;break;
	  case'9':theNO=9;break;
	  default:return(2);
	  }
	  if (tidystr[i][5]!='\0')
		  return(6);
	  instructionstore[i].thenumber=theNO;
  }
			//以下为特殊指令

	else if(((((j==26)||(j==27))||((j==28)||(j==32)))||
			(((j==33)||(j==34))||
			((j==38)||(j==39))))||(j==40))
	{
		int n=differ1register(i,4);
		if (n==0)
			return(9);
	}
	else if((((((j==29)||(j==30))||((j==31)||(j==35)))||
			(((j==36)||(j==37))||
			((j==41)||(j==42))))||(j==43))||
			(((((j==44)||(j==45))||((j==46)||(j==50)))||
			(((j==51)||(j==52))||
			((j==56)||(j==57))))||(j==58)))
	{
		int n=differ1register(i,5);
		if (n==0)		
			return(9);
	}
	else if(((((j==47)||(j==48))||((j==49)||(j==53)))||
			(((j==54)||(j==55))||
			((j==59)||(j==60))))||(j==61))
	{
		int n=differ1register(i,6);
		if (n==0)
			return(9);
	}
	else if (((j==62)||(j==63))||((j==64)||(j==65)))
	{
		int n=differ1register(i,3);
		if (n==0)
			return(9);
	}
	else if((j==66)||(j==67))
	{
		int n=differ2register(i,4);
		if (n==0)
			return(9);
	}
	else if((j==68)||(j==69))
	{
		int n=differ1register(i,4);
		if (n==0)
			return(9);
	}
	else if(j==70)
	{
		int n=differ3register(i,4);
		if (n==0)
			return(9);
	}
		//数据传输指令
	else if(((j==71)||(j==72))||((j==75)||(j==76)))
	{
		int n=differ1register(i,4);
		if (n==0)
			return(9);
	}  
	else if((((j==73)||(j==74))||((j==77)||(j==78)))||
		   (((j==79)||(j==80))||((j==81)||(j==82))))
	{
		int n=differ2register(i,4);
		if (n==0)
			return(9);
	}
    else if(((j==83)||(j==84))||((j==85)||(j==86)))
	{
		int n=differ3register(i,4);
		if (n==0)
			return(9);
   }
	   //BIN 算术运算指令
   else if((j==87)||(j==88))
   {
	   int n=differ1register(i,4);
	   if (n==0)
			return(9);
   }
	   //数据比较指令
   else if(((j==89)||(j==90))||((j==91)||(j==92)))
   {
	   int n=differ2register(i,4);
	   if (n==0)
			return(9);
   }
	   //逻辑运算指令
	    
   else if((((j==94)||(j==95))||((j==98)||(j==99)))||
		            ((j==100)||(j==101)))
   {
	   int n=differ1register(i,5);
	   if (n==0)
		   return(9);
   }	   
   else if((j==96)||(j==97))
   {
	   int n=differ3register(i,5);
	   if (n==0)
		   return(9);
   }
	   //数据移位指令
   else if(((j==102)||(j==103))||((j==104)||(j==105)))
   {
	   int n=differ1register(i,5);
	   if (n==0)
		   return(9);
   }
	   //数据循环移位指令
   else if((((j==106)||(j==107))||((j==108)||(j==109)))||
                  ((j==110)||(j==111)))
   {
	   int n=differ1register(i,5);
	   if (n==0)
		   return(9);
   }
	   //位操作指令
   else if(j==112)
   {
	   int n=differ3register(i,3);
	   if (n==0)
		   return(9);
   }
   else if(j==113)
   {
	   int theNO=switchint(tidystr[i][5]);
	   instructionstore[i].thenumber=theNO;
	   int n=differ3register(i,7);
	   if (n==0)
			return(9);
   }
   else if(j==114)
   {
		int theNO;
        switch(tidystr[i][5])
		{
		case'0':theNO=0;break;
	    case'1':theNO=1;break;
        case'2':theNO=2;break;
		case'3':theNO=3;break;
		case'4':theNO=4;break;
		case'5':theNO=5;break;
		case'6':theNO=6;break;
		case'7':theNO=7;break;
		case'8':theNO=8;break;
		case'9':theNO=9;break;
		default:return(2);
		}	
		instructionstore[i].thenumber=theNO;
		if(tidystr[i][6]!='\0')
			return(2);
   }
   else if(j==115)
   {
	   int theNO;
	   switch(tidystr[i][4])
	   {
	   case'0':theNO=0;break;
	   case'1':theNO=1;break;
       case'2':theNO=2;break;
	   case'3':theNO=3;break;
	   case'4':theNO=4;break;
	   case'5':theNO=5;break;
	   case'6':theNO=6;break;
	   case'7':theNO=7;break;
	   case'8':theNO=8;break;
	   case'9':theNO=9;break;
	   default:return(2);
	   }	
	   instructionstore[i].thenumber=theNO;
	   if(tidystr[i][5]!='\0')
		   return(2);
   }
   else if(j==116)
   {
	   int theNO;
       switch(tidystr[i][4])
	   {
	   case'0':theNO=0;break;
	   case'1':theNO=1;break;
       case'2':theNO=2;break;
	   case'3':theNO=3;break;
	   case'4':theNO=4;break;
	   case'5':theNO=5;break;
	   case'6':theNO=6;break;
	   case'7':theNO=7;break;
	   case'8':theNO=8;break;
	   case'9':theNO=9;break;
	   default:return(2);
	   }	
	   instructionstore[i].thenumber=theNO;
	   if(tidystr[i][5]!='\0')
		   return(2);
   }
return(0);
}	 

⌨️ 快捷键说明

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