高分求LL(1)语法分析设计原理与实现技术
1个回答

#include

#include

#include

#define Vtn 8

#define Vnn 5

#define Pn 10

#define Pmaxlen 20

#define MaxStLength 50

#define MaxStackDepth 50

char Vn[Vnn]={'E','e','T','t','F'};

char Vt[Vtn]={'i','+','-','*','/','(',')','$'};

char Pstr[Pn][Pmaxlen]=

{

"E->Te",

"e->+Te",

"e->-Te",

"e->ε",

"T->Ft",

"t->*Ft",

"t->/Ft",

"t->ε",

"F->(E)",

"F->i"

};

int Prlen[Pn]={2,3,3,1,2,3,3,1,3,1};

int Pint[Pn][3]=

{

{102,101},

{1,102,101},

{2,102,101},

{-1},

{104,103},

{3,104,103},

{4,104,103},

{-1},

{5,100,6},

{0}

};

int analyseTable[Vnn][Vtn+1];

int analyseStack[MaxStackDepth+1];

int topAnalyse;

char st[MaxStLength];//要分析的符号串

/* ----------------------初始化----------------------------*/

void InitanalyseTable()

{

/*---预测分析表存放各个产生式的编号,-1表示找不到相匹配的产生式---*/

for(int i=0;i