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

📄 fun.h

📁 我前一段时间,做的一个编译原理实验的作业 请大家为我多提意见
💻 H
字号:
#include "iostream.h"
#include "stdio.h"
#include "stdlib.h"
#include "windows.h"
#include "conio.h"
void setcolor(unsigned short ForeColor=4,unsigned short BackGroundColor=0) 
{ 
HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE); //本例以输出为例 
SetConsoleTextAttribute(hCon,BackGroundColor); //ForeColor,
};
//setcolor(10,9);//蓝色 //setcolor(10,14);//黄色
typedef struct word{
        char name;
        struct word *next;
		int flag;
		
}wordlist; 
void listM(char  M[9][9])//列出分析表M
{
	int i=0,j=0;
	cout<<"分析表M如下所示:"<<endl;
	for(i=0;i<9;i++)
	 {		 
		 for(j=0;j<9;j++)
			 if(M[i][j]!=NULL)
				 cout<<setiosflags(ios::left)<<setw(5)<<M[i][j]<<"  ";
	 cout<<endl;
	}	 
}
void creatstack(wordlist *stack)//建一个栈
{
	 wordlist *p;
	 p=(wordlist *)malloc(sizeof(wordlist));
	 p->next=NULL;
	 p->name='$';
	 stack->next=p;
}
void creatword(wordlist *in)//新建单词序列
{
   char str[64];   
   wordlist *p,*temp;
   temp=(wordlist *)malloc(sizeof(wordlist));  
   temp=in;
   cout<<"请输入你要语句,并以“$”结束!"<<endl;
   cin.getline(str,20);
   for(int i=0;i<64;i++)
   {  
	  p=(wordlist *)malloc(sizeof(wordlist));
      p->next=NULL;
      p->name=str[i];
      temp->next=p;
	  temp=temp->next;
	  if(str[i]=='$')
	  	  break;	   
   }
}
void listword(wordlist *out)//列出单词信息
{
	wordlist *p;
	p=(wordlist *)malloc(sizeof(wordlist));
	p=out;
	if(p->next==NULL)
	{
		setcolor(6,12);
		cout<<"没有输入信息!"<<endl;
		setcolor(20,10);
	}
	else
	{			
		p=out->next;
		while(p!=NULL)
		{		  
			  cout<<p->name<<"   ";				  
		   	  p=p->next;			  
		}	  
		  cout<<endl;
	}
}
wordlist  *Gethead(wordlist *p)//得到第一个单词
{
	wordlist *temp;
	temp=(wordlist *)malloc(sizeof(wordlist));
	temp->next=NULL;
	//strcpy(temp->name,p->next->name);
	temp->name=p->next->name;
	return temp;
}
wordlist  *Getend(wordlist *stack)//得到最后一个单词
{
	wordlist *temp,*p;
	p=stack;
	temp=(wordlist *)malloc(sizeof(wordlist));
	temp->next=NULL;
		while(p->next!=NULL)
			p=p->next;
		//strcpy(temp->name,p->name);	
		temp->name=p->name;	
	return temp;
}
char Search(char M[9][9],char x,char y)//查找要入栈的字符
{
	 char temp;
	 int i=0,j=0;	 
	 for(i=0;i<8;i++)	 
		if(M[i][0]==x)
			break;
	 for(j=0;j<8;j++)
		if(M[0][j]==y)
			break;		
	 temp=M[i][j];
	 cout<<"temp: "<<temp<<endl;
	 if(temp=='#')
		cout<<"ERRORS!"<<endl;
	return temp;
}
void Instack(wordlist *stack,char in)//M[i][j]入栈
{
	 wordlist *temp;
	 temp=(wordlist *)malloc(sizeof(wordlist));
     temp->next=NULL;	 
     while(stack->next!=NULL)		
		stack=stack->next;	
	 temp->name=in;
	 cout<<"in: "<<in<<endl;
	 stack->next=temp;
}
char ChangeStack(wordlist *stack,char *Buf)//转换我的栈
{
   char bu;
   wordlist *temp;
   temp=(wordlist *)malloc(sizeof(wordlist));  
   temp=stack;
   if(strcmp(Buf,"bAb")==0)
	   bu='S';
   else if(strcmp(Buf,"(B")==0||strcmp(Buf,"a")==0)
	   bu='S';
   else if(strcmp(Buf,"Aa")==0)
	   bu='B';
   else
	   cout<<"Buf出错!"<<endl;
   return bu;
}
void Outstack(wordlist *stack)//相同时出栈
{
	/////////////////////////
	//去栈底
	wordlist *temp,*p;
    p=(wordlist *)malloc(sizeof(wordlist));
	temp=stack;
	while(stack->next!=NULL)
	{
		p=stack;
		stack=stack->next;
	}
}
void Outhead(wordlist *in)//去除此时(出错的)第一个输入
{
	in->next=in->next->next;
}

⌨️ 快捷键说明

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