语法分析代码2 LR分析器C语言实现
#include"status_stack.h"
#include"symbol_instr_stack.h"#include"lr.h"
//打印LR分析器的工作程过过
void print(status *status_p,symbol_instr *symbol_p,symbol_instr *instr_p)
{
int i;
out_stack(status_p);
for(i=0;i<20-status_p->top;i++)
printf(" ");
out_stack1(symbol_p);
for(i=0;i<20;i++)
printf(" ");
out_stack2(instr_p);
printf("\n");
}
//状函数过过过过过
int goto_char(status *status_p,symbol_instr *instr_p)
{
char x;
int y,z;
x = get_top(instr_p);
y = get_top(status_p);
z = get_index_char(x);
return table[y][z];
}
//移,,函数过过过过过过过
void action(status *status_p,symbol_instr *symbol_p,symbol_instr *instr_p)
{
int i,j,x;
char a;
i = goto_char(status_p,instr_p);
//过过过出
if(i == -1)
printf("\n===============过过过出!================\n");
//过过成功
if(i == 12)
printf("\n===============过过成功!================\n");
//移作过过过
if(i>=0 && i<=11)
{
push(status_p,i);
a = pop(instr_p);
push(symbol_p,a);
print(status_p,symbol_p,instr_p);
action(status_p,symbol_p,instr_p);
}
//过过过作
if(i>=21 && i<=26)
{
x = r[i-21].y;
for(j=0;j
表
关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf
达式
printf("\n过过过过过过过过过过过过过过过过过过过过过入要的入串,各字符之不能有空格,以'#'字符束过过!\n");printf("===========Expression =");//先将入串符号过过过过过过过过
do{
scanf("%c",&x);
push(symbol_p,x);
}while(x != '#');
//然后由符号出,入过过过过过过过过过
while( symbol_p->top != 0)
{
x = pop(symbol_p);
push(instr_p,x);
}
printf("\n\n");
//打印框架
printf("\n状过过==============符号过==============过入串\n");print(status_p,symbol_p,instr_p);//打印初始分析表
//移,,并打印过过过过过过过过过过过过过过一分析程每步
action(status_p,symbol_p,instr_p);return 0;
}