算符优先分析法语法分析-编译原理 第3页
push(curchar);
k=1;
curcmp=curchar;
h=h->next;
}
else /*算符优先值为,归约*/
{
guiyue();
}
}
}
}
}
void main(void)
{
char ch;
right=1;
base=(Lchar*)malloc(sizeof(LLchar));
base->next=NULL;
base->char_ch='#';
top=base;
h=(Lchar*)malloc(sizeof(LLchar));
h->next=NULL;
p=h;
do{ /*输入待比较字符串,以'#'结束*/
ch=getchar();
putchar(ch);
if(ch=='i'||ch=='+'||ch=='='||ch=='*'||ch=='('||ch==')'||ch=='#')
{
temp=(Lchar*)malloc(sizeof(LLchar));
temp->next=NULL;
temp->char_ch=ch;
h->next=temp;
h=h->next;
}
else
{
temp=p->next;
printf("\nInput a wrong char!Input again:\n");
for(;;)
{
if (temp!=NULL)
printf("%c",temp->char_ch);
else
break;
temp=temp->next;
}
}
}while(ch!='#'); /*输入待比较字符串,以'#'结束*/
p=p->next;
h=p;
dosome(); /*开始识别*/
if(right)
printf("\nOK!\n");
else
printf("\nError!\n");
getchar();
getchar();}