算符优先分析法语法分析-编译原理 第2页

算符优先分析法语法分析-编译原理 第2页
  else {  
    switch(tempc1){
    case '+':popc='T';break;
    case '*':popc='F';break;
    case '=':popc='E';
    }
    push(tempc1);
    push(popc);
    k=1;
   }

 }
 else
 {
  if(tempc=='F'){
   tempc2=pop();
    if(tempc1=='*'&&tempc2=='T'){
     push('T');
    }
    else
     right=0;
   }
  else if(tempc=='T'){
   tempc2=pop();
   if(tempc1=='+'&&tempc2=='E'){
     push('E');
    }
   else
   right=0;
  }
        else if(tempc=='E'){
   tempc2=pop();
   if(tempc1=='='&&tempc2=='V'){
     push('A');
    }
   else
   right=0;
  }
  else if(tempc=='A'){
   tempc2=pop();
   if(tempc2!='#'){
    right=0; }
  else if(tempc=='='){
   tempc2=pop();
   if(tempc1=='V'&&tempc2=='E'){
    push('A');
    
   }
   else right=0;
  }
  
    }   
}
void dosome(void)
{
 k=1;
 for(;;)
 {
  curchar=h->char_ch;
  temp=top;
  if(temp->char_ch=='A'){
 break;
  }
  else {
  for(;;)
  {
   if(temp->char_ch=='V'||temp->char_ch=='E'||temp->char_ch=='T'||temp->char_ch=='F'||temp->char_ch=='A'||temp->char_ch=='S')
   {
    temp=temp->next;
    k++;
   }
   else
   {
    curcmp=temp->char_ch;
    break;
   }
  }
  printf("\n%d\t%d\t",table[i][j],k);
  temp=top;
  for(;;)    /*打印栈*/
  {
   printf("%c",temp->char_ch);
   if(temp->char_ch=='#')
    break;
   else
    temp=temp->next;
  }
  printf("\t");
  temp=h;
  for(;;)    /*打印待比较的字符*/
  {
   printf("%c",temp->char_ch);
   
   if(temp->char_ch=='#')
    break;
   else
    temp=temp->next;
  }
  i=changchartoint(curcmp);
  j=changchartoint(curchar);
  if(table[i][j]==0)  /*算符优先值为空*/
  {
   printf("\n%d\t%d\t%c\t%c\terror1",table[i][j],k,curcmp,curchar);
   right=0;
   break;
  }
  else                 /*算符优先值不为空*/
  {
   if(table[i][j]<0)   /*算符优先值为-1,移进*/
   {
    if(curchar=='#')   /*待比较字符为空*/
    {
     if(k==2)          /*当前比较字符在栈的位置为两个元素*/
      break;
     else
     {
      printf("\n%d\t%d\t%c\t%c\terror2",table[i][j],k,curcmp,curchar);
      right=0;
      break;
     }
    }

上一页  [1] [2] [3] 下一页

  • 上一篇文章:
  • 下一篇文章:
  • Copyright © 2007-2012 www.chuibin.com 六维论文网 版权所有