本文章介绍如何在C语言中实现SLR(0)分析程序,涵盖其基本概念、构造方法及具体应用实例。适合对编译原理感兴趣的读者深入理解语法分析技术。
```c++
#include
#include
#include
#include
using namespace std;
#include
#include
#define size 200
struct word {
char data[20];
char sign[10];
int aa;
int bb;
float num;
};
typedef struct node {
int style;
int data;
struct node *next;
} linkstack;
linkstack *top;
string analysis[55][30];
char V[31]={m,(,),{,},;,,,a,c,t,f,l,i,w,d,=,+,-,*,
/,#, T, X, Y, Z, S, E , L ,A ,F ,P};
char act[24]={P, T, T, X, Y,Y,Y,Y,Z,Z,S,
S,S,S,L, L, E, E, E,
A ,A ,A ,F , F};
int act1[24]={8,1,3,2,1,1,1,1,1,3,4,
3,5,6,1,2,3,3 , 1 , 3 , 3 ,
1 , 3 };
struct word w[size];
string s[40]={auto,break,case,char,const,
continue,default,do, double,
else ,enum ,extern ,float,
for ,goto ,if ,int,
long , register, return,
short , signed, sizeof,
static,struct,switch,
typedef,union,unsigned,void,
volatile,while};
```