#include<stdio.h>
#include<string>
#include<iostream>
#include<algorithm>
#include<stack>
using namespace std;
int num;
stack<char> A;
stack<char> B;
int f(char x,char y)
{
if(x == 'E')
{
cout<<num<<" "<<"E-->TG"<<endl;
A.pop();
A.push('G');
A.push('T');
num++;
return 1;
}
else if(x == 'G'&&y=='+')
{
cout<<num<<" "<<"G-->+TG"<<endl;
A.pop();
A.push('G');
A.push('T');
A.push('+');
num++;
return 1;
}
else if(x == 'G'&&y!='+')
{
cout<<num<<" "<<"G-->&"<<endl;
A.pop();
num++;
return 1;
}
else if(x == 'T')
{
cout<<num<<" "<<"T-->FS"<<endl;
A.pop();
A.push('S');
A.push('F');
num++;
ret
2016年秋季《编译原理》课程实验(2014级)表达式语法分析——递归子程序法
最新推荐文章于 2025-10-12 14:25:37 发布
本文介绍了一种使用递归子程序法进行表达式语法分析的方法,通过C++实现。代码中定义了栈操作和核心的判断函数f,实现了从输入的表达式字符逆序遍历并进行匹配的过程,最终判断表达式是否符合预设的语法规则。

最低0.47元/天 解锁文章
1010





