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

📄 递归下降分析法.txt

📁 利用高级语言的递归过程为给定文法的每个非终结符构造对应的递归函数
💻 TXT
字号:
#include "fstream.h"
#include "iostream.h"
#include "stdlib.h"
struct code_val{
	char code;char val[20];
} t; //定义临时结构变量,存放单词二元式。
ifstream cinf("lex_r.txt",ios::in); 		//从文件lex_r.txt输入数据
ofstream coutf("par_r.txt",ios::out);		//结果输出至文件par_r.txt
void E(void);
void F(void)		//F→(E)|i|x|y
{
	if(t.code=='i'||t.code=='x'||t.code=='y')
    { 
		cinf>>t.code>>t.val;coutf<<t.code; 	//读一个单词的二元式并输出单词种别
    }
	else 
		if(t.code=='(')
		{
			cinf>>t.code>>t.val;coutf<<t.code;  	//读一个单词的二元式并输出单词种别
			E( );
			if(t.code==')')
			{
				cinf>>t.code>>t.val;coutf<<t.code;	//读一个单词的二元式并输出单词种别
			}
			else{
				coutf<<"Err in F1>"<<t.code<<endl;exit(0);
			}
		}
		else{
			coutf<<endl<<"Err in F2>"<<t.code<<endl;exit(0);
		}
}
void T1(void)		//T'→*FT'|ε
{
	if(t.code=='*')
	{
		cinf>>t.code>>t.val;coutf<<t.code; 	//读一个单词的二元式并输出单词种别
		F( );T1( );
	}
	else 
		if(!(t.code=='#'||t.code==')'||t.code=='+'))
        { 
			coutf<<endl<<"Err in T1()>"<<t.code<<endl;exit(0);
		}
}
void T(void)		//T→FT'
{
	if(t.code=='i'||t.code=='x'||t.code=='y'||t.code=='(')
	{
		F( );T1( );
	}
	else{
		coutf<<endl<<"Err in T()>"<<t.code<<endl;exit(0);
	}
}
void E1(void)		//E'→+TE'|ε
{
   if(t.code=='+')
   {
	   cinf>>t.code>>t.val;coutf<<t.code; 	//读一个单词的二元式并输出单词种别
	   T( );E1( );
   }
   else 
      if(!(t.code=='#'||t.code==')'))
		  coutf<<endl<<"Err in E1()>"<<endl<<t.code;
}
void E(void)	                        	//E→T E'
{	
	if(t.code=='i'||t.code=='x'||t.code=='y'||t.code=='(')
	{
		T( );E1( );
	}
	else
	{
		coutf<<endl<<"Err in E()>"<<t.code<<endl;exit(0); 
	}
}
void main(void)
{
	cinf>>t.code>>t.val;coutf<<t.code; 		//读一个单词的二元式并输出单词种别
	E( );
	if(t.code=='#')
		coutf<<endl<<"ok"<<endl;
	else
		coutf<<endl<<"err in main()"<<endl;
}

⌨️ 快捷键说明

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