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

📄 3.cpp

📁 一个很好的编译原理课程设计
💻 CPP
字号:
/*文法表达式为
E->TE'
E'->+TE'|^
T->FT'
T'->+TF'|^
F->(E)|i
*/
#include <iostream.h>
//#include <stdlib.h>
//#include <iomanip.h>
//#include <fstream.h>
char token[50];
int current_pos=0;
int sign;
void e();
void e1();
void t();
void t1();
void f();
void main()
{
	sign=1;
	cout<<"请输入您要分析的字符串以#结束"<<endl;
	cin>>token;
	e();
	if((token[current_pos]=='#')&&sign)
		cout<<"分析成功"<<endl;
	else
		cout<<"分析失败"<<endl;
}
void e()
{
	cout<<"E=>TE'"<<endl;
	t();
	e1();
}
void e1()
{
	if(token[current_pos]=='+')
	{
		cout<<"E'=>+TE'"<<endl;
		current_pos++;
		t();
		e1();
	}
	else
		cout<<"T'=>^"<<endl;
}
void t()
{
	cout<<"T=>FT'"<<endl;
	f();
	t1();
}
void f()
{
	if(token[current_pos]=='i')
	{
		cout<<"F=>i"<<endl;
		current_pos++;
	}
	else
	{
		if(token[current_pos]=='(')
		{
			cout<<"F=>(E)"<<endl;
			current_pos++;
			e();
		}
		else if(token[current_pos]==')')
		{
			cout<<"F=>(E)"<<endl;
			current_pos++;
		}
		else
			sign=0;
	}
}
void t1()
{
	if(token[current_pos]=='*')
	{
		cout<<"T'=>*FT'"<<endl;
		current_pos++;
		f();
		t1();
	}
	else
		cout<<"T'=>^"<<endl;
}

⌨️ 快捷键说明

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