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

📄 82.txt

📁 词法分析判定输入的为数字或是字符
💻 TXT
字号:
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#define sz 50
int deside(char str[sz],int &pos)
{
	pos=1;
	for(int i=0;i<sz;i++)
	{
		if(pos==1){
			if(str[i]=='x')pos=2;
			else if(str[i]=='y')pos=3;
			else if(str[i]=='\0')return pos;
			else return 0;
		}
		else if(pos==2){
			if(str[i]=='y')pos=4;
			else if(str[i]=='\0') return pos;
			else return 0;

		}







		else if(pos==4){
		
			if(str[i]=='y')pos=8;
			else if(str[i]=='x')pos=6;
			else if(str[i]=='\0')return pos;
			else return 0;
		}
		else if(pos==3){
		
			if(str[i]=='x')pos=3;
			else if(str[i]=='y')pos=6;
			else if(str[i]=='\0')return pos;//`erfdoi
			else return 0;

		}
		else if(pos==6){
			if(str[i]=='\0')return pos;
			else return 0;
		
		}
		else if(pos==8){
			if(str[i]=='y')pos=8;
			else if(str[i]=='\0')return pos;
			else return 0;
		}
//	return 0;
}
}
int apply()
{
	char str[sz];int pos=1; char ch;
	while(1){
		cout<<" $ 输入待测字符串: ";
		cin>>str;
		if(deside(str,pos)==2||deside(str,pos)==4||deside(str,pos)==6||deside(str,pos)==8)
			cout<<"  * 分析结果为:  是xy*|yx*y|xyx的句子"<<endl<<endl;
		else cout<<"  @分析结果为: 不是xy*|yx*y|xyx的句子 "<<endl<<endl;
		

		cout<<" --是否继续此项工作?(y/n) ";
		cin>>ch;
		switch(ch){
		
		case'y': break;
		case'n':return 0;
		default: 
			cout<<"input erro! input again!"<<endl; 
			cin>>ch;
		}
	
	}	
}
void test(){
	ifstream in; char str[sz]; int pos=1;  
	in.open("test.txt");
	cout<<"___________________测试结果____________________"<<endl;
	cout<<"待测字符串"<<"\t\t\t    结果   "<<endl;
	while(strcmp(str,"结束"))
	{
		in>>str;
		if(deside(str,pos)==2||deside(str,pos)==4||deside(str,pos)==6||deside(str,pos)==8)
			cout<<str<<"\t\t\t 是xy*|yx*y|xyx的句子"<<endl;
		else cout<<str<<"\t\t\t不是xy*|yx*y|xyx的句子 "<<endl;
	}
	cout<<"_______________________________________________"<<endl;
	in.close();
}
void printmeun(){

	cout<<'\t'<<"_______词法分析器2.0功能菜单 ________"<<endl;
	cout<<'\t'<<"1。软件测试(被测文件:test.txt)。"<<endl;
	cout<<'\t'<<"2。软件应用(手工输入)。"<<endl;
	cout<<'\t'<<"3.退出。"<<endl;
	cout<<'\t'<<"_____________________________________"<<endl;
}
main()
{
	char ch1,ch2;

	while(1){
		printmeun();
		cout<<"   输入选择:";
		cin>>ch1;
		switch(ch1){
		
		case'1':test();break;
		case'2':apply();break;
		case'3':return 0;
		default:
			{
				cout<<" input erro ,input again! "<<endl;
				printmeun();
				cout<<"   输入选择:";
				cin>>ch1;
			}
		}
	cout<<"是否继续使用该软件(y/n)?";
	cin>>ch2;
	switch(ch2){
	
	case'y':break;
	case'n':return 0;
	default:{
				cout<<" input erro ,input again! "<<endl;
				cout<<"   输入选择:";
				cin>>ch2;
			}
		}
	}


}

⌨️ 快捷键说明

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