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

📄 zhong.cpp

📁 编译原理课程实验要求做的语法分析
💻 CPP
字号:
#include"bianyi.h"
void yufa(const int Forecast[][36],struct Word *Hptr,const int Ruleright[][7])
{
	

	
	int r(0);
	int a;
	
	SqStack Sqstack;
	InitStack(Sqstack);
	struct EElemType *e;
	int flag(1);
	struct Word *word;

	Hptr=getsym();
	if(Hptr)
	{
		cout<<"//////////////////////////////////语法分析////////////////////////////////////"<<endl;
		e=(struct EElemType *)(malloc(sizeof(EElemType)));
	    word=Hptr;
	    e->kind=0;
	    e->arrange=Hptr->arrage;
	    e->Line=Hptr->row;
	    e->Mark=Hptr->Ltrace;
	    e->next=NULL;
	    Hptr=Hptr->next;
	    free(word);
     	Rpush(35,0,Sqstack);
	    Rpush(128,0,Sqstack);
	    int Rtrace,Rptr;
	    int Fortrace;
	    Rpop(Fortrace,a,Sqstack);
	    while(e->Mark!=35)
		{
			if(Fortrace>=128)
			{///////////////////////1
				if(Forecast[Fortrace-128][e->Mark]!=-1&&Forecast[Fortrace-128][e->Mark]!=100)
				{
					Rtrace=Forecast[Fortrace-128][e->Mark];
				    Rptr=0;
				    while(Ruleright[Rtrace][Rptr]!=0)
						Rptr++;
				    while(Rptr!=0)
					{
						Rpush(Ruleright[Rtrace][Rptr-1],0,Sqstack);
					    Rptr--;
					}
					Rpop(Fortrace,a,Sqstack);
				}
				
				else
				{/////////////////////////////////////2
					if(Forecast[Fortrace-128][e->Mark]==-1)
					{
						cout<<e->Line<<"行  "<<e->arrange<<"列  "<<"有多余的字符内码为: "<<e->Mark<<endl;
	                    e->kind=0;
	                    e->arrange=Hptr->arrage;
	                    e->Line=Hptr->row;
                       	e->Mark=Hptr->Ltrace;
	                    e->next=NULL;
						word=Hptr;
						Hptr=Hptr->next;
						free(word);
						flag*=0;
						
					
					
					}
					else
					{
						if(Forecast[Fortrace-128][e->Mark]==100)
						{
							
							cout<<e->Line<<"行  "<<e->arrange<<"列  "<<"在内码为:"<<e->Mark <<"存在句型错误问题"<<endl;
	                        e->kind=0;
	                        e->next=NULL;
					        Rpop(Fortrace,a,Sqstack);
							flag*=0;
						}
					}

				}////////////////////////////2
			}
			
			else
			{
				if(Fortrace==e->Mark)
				{
					
                    e->kind=0;
	                e->arrange=Hptr->arrage;
	                e->Line=Hptr->row;
                    e->Mark=Hptr->Ltrace;
	                e->next=NULL;
					word=Hptr;
					Hptr=Hptr->next;
					free(word);
					Rpop(Fortrace,a,Sqstack);
				}
				
				else
				{
					if(Fortrace!=35)
					{
					    
					    cout<<e->Line<<"行  "<<e->arrange<<"列  "<<"在内码为:"<<e->Mark <<"之前缺字符"<<endl;
	                    e->kind=0;
	                    e->next=NULL;
						Rpop(Fortrace,a,Sqstack);
						flag*=0;
					}
					

					else
						break;
				}
			}
		}



		if(Fortrace==35&&e->Mark==35)
		{
			if(flag)
				cout<<"恭喜!语法检查正确"<<endl;
		   if(Hptr)
		   {
			   while(Hptr)
			   {
				   word=Hptr;
				   Hptr=Hptr->next;
				   free(word);
			   }
		   }
		  if(!Rempty(Sqstack))
		  {
			Epop(Sqstack);
		  }
		   
		}
			
		}

	
		
			
			
			

			
}
	

⌨️ 快捷键说明

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