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

📄 slr.cpp

📁 编译原理课程试验
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	fout.close();
	switch(g)
	{
	case 1:
		POP(stk);
		return paser[TOP(stk)][19].num;
	case 2:
		POP(stk);POP(stk);
		return paser[TOP(stk)][20].num;
	case 3:
		POP(stk);
		return paser[TOP(stk)][20].num;
	case 4:
		POP(stk);POP(stk);POP(stk);POP(stk);
		return paser[TOP(stk)][21].num;
	case 5:
		POP(stk);POP(stk);POP(stk);POP(stk);POP(stk);POP(stk);POP(stk);
		return paser[TOP(stk)][21].num;
	case 6:
		POP(stk);
		return paser[TOP(stk)][22].num;
	case 7:
		POP(stk);POP(stk);POP(stk);
		return paser[TOP(stk)][23].num;
	case 8:
		POP(stk);
		return paser[TOP(stk)][23].num;
	case 9:
		POP(stk);POP(stk);POP(stk);
		return paser[TOP(stk)][24].num;
	case 10:
		POP(stk);
		return paser[TOP(stk)][24].num;
	case 11:
		POP(stk);
		return paser[TOP(stk)][25].num;
	case 12:
		POP(stk);POP(stk);POP(stk);
		return paser[TOP(stk)][25].num;
	case 13:
		POP(stk);
		return paser[TOP(stk)][25].num;
	case 14:
		POP(stk);POP(stk);POP(stk);
		return paser[TOP(stk)][26].num;
	case 15:
		POP(stk);
		return paser[TOP(stk)][26].num;
	case 16:
		POP(stk);POP(stk);POP(stk);
		return paser[TOP(stk)][27].num;
	case 17:
		POP(stk);POP(stk);POP(stk);
		return paser[TOP(stk)][27].num;
	case 18:
		POP(stk);
		return paser[TOP(stk)][27].num;
	case 19:
		POP(stk);POP(stk);
		return paser[TOP(stk)][28].num;
	case 20:
		POP(stk);
		return paser[TOP(stk)][28].num;
	case 21:
		POP(stk);POP(stk);POP(stk);
		return paser[TOP(stk)][29].num;
	case 22:
		POP(stk);POP(stk);POP(stk);POP(stk);
		return paser[TOP(stk)][29].num;
	case 23:
		POP(stk);POP(stk);POP(stk);POP(stk);POP(stk);
		return paser[TOP(stk)][29].num;
	case 24:
		POP(stk);POP(stk);POP(stk);POP(stk);POP(stk);
		return paser[TOP(stk)][29].num;
	case 25:
		POP(stk);POP(stk);POP(stk);POP(stk);POP(stk);POP(stk);POP(stk);
		return paser[TOP(stk)][29].num;
    default:
		exit(0);
	}
}
void output()//输出文件------------------------------------------------
{
	ofstream outfile1("symbol.txt",ios::out);
	if(!outfile1)
	{
		cout<<"can not open symbol.txt"<<endl;
		exit(1);
	}
	symbolist *l=s_head;
	l=l->next;
	while(l!=NULL)
	{
		outfile1<<l->number<<"          "<<l->id<<"          ";//输出符号表
		outfile1<<l->name<<endl;
		l=l->next;
	}
	outfile1.close();
	cout<<"symbollist has done"<<endl;
	ofstream outfile2("token.txt",ios::out);
	if(!outfile2)
	{
		cout<<"can not open token.txt"<<endl;
		exit(1);
	}
	token *m=t_head;
	m=m->next;
	while(m!=NULL)
	{
		outfile2<<"          "<<m->id<<"          ";//输出token字
		if(m->name!=32)
			outfile2<<m->name<<endl;
		else 
			outfile2<<"          "<<endl;
		m=m->next;
	}
	cout<<"token has been generated!"<<endl;
	outfile2.close();
	return;
}
void main()
{
	MAKENULL(stk);
	PUSH(0,stk);
	scaner();
	output();
	cout<<"=============================================================="<<endl;
    t_head=t_head->next;
	int flag=0;
	while(t_head!=NULL)
	{
		flag=0;
		switch(paser[TOP(stk)][t_head->id].ch)
		{
		case 'R':
			PUSH(Goto(paser[TOP(stk)][t_head->id].num),stk);
			flag=1;
			break;
		case 'S':
			PUSH((paser[TOP(stk)][t_head->id].num),stk);
			break;
		case 'E':
			cout<<"grammer error!"<<endl;
			return;
		case 'A':
			if (t_head->next==NULL)
			{
				cout<<"the source file you write is right!"<<endl;
				return;
			}
			else cout<<"grammer error!still symbol not read.";
		}
		if(flag==0)
		t_head=t_head->next;
	}
}

⌨️ 快捷键说明

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