Ejemplo n.º 1
0
void precftn(int r,int t,int s)
   {
   /* decide a shift/reduce conflict by precedence.*/
   /* r is a rule number, t a token number */
   /* the conflict is in state s */
   /* temp1[t] is changed to reflect the action */

   int lp,lt, action;

   lp = levprd[r];
   lt = toklev[t];
   if( PLEVEL(lt) == 0 || PLEVEL(lp) == 0 )
      {
      /* conflict */
      if( foutput != NULL ) fprintf( foutput, "\n%d: shift/reduce conflict (shift %d, red'n %d) on %s",
      s, temp1[t], r, symnam(t) );
      ++zzsrconf;
      return;
      }
   if( PLEVEL(lt) == PLEVEL(lp) ) action = ASSOC(lt);
   else if( PLEVEL(lt) > PLEVEL(lp) ) action = RASC;  /* shift */
   else action = LASC;  /* reduce */

   switch( action )
      {

   case BASC:  /* error action */
      temp1[t] = ERRCODE;
      return;

   case LASC:  /* reduce */
      temp1[t] = -r;
      return;

      }
}
Ejemplo n.º 2
0
Archivo: ey4.c Proyecto: dank101/2BSD
output(){ /* print the output for the states */

  int i, j, k, c;

  settab();
  arrset("yyact");

  for( i=0; i<nstate; ++i ){ /* output the stuff for state i */
    nolook = (tystate[i]==0);
    closure(i);
    /* output actions */
    aryfil( temp1, nterms+1, 0 );
    for( j=0; j<cwset; ++j ){ /* look at the items */
      c = *( wsets[j].pitem );
      if( c>0 && c<NTBASE && temp1[c]==0 ) temp1[c] = go2(i,c);
      }

    if( i == 1 ) temp1[1] = ACCEPTCODE;

    /* now, we have the shifts; look at the reductions */

    lastred = 0;
    for( j=0; j<cwset; ++j ){
      c = *( wsets[j].pitem );
      if( c<=0 ){ /* reduction */
        lastred = -c;
        for( k=1; k<=nterms; ++k ){
          if( ((wsets[j].ws[k>>4])&(1<<(k&017))) != 0 ) {
            if( temp1[k] == 0 ) temp1[k] = c;
            else if( temp1[k]<0 ){ /* reduce/reduce conflict */
              settty();
              printf("\n%d: reduce/reduce conflict (red'ns %d and %d ) on %s",
                i, -temp1[k], lastred, symnam(k) );
              if( -temp1[k] > lastred ) temp1[k] = -lastred;
              ++zzrrconf;
              settab();
              }
            else { /* potential shift/reduce conflict */
              switch( precftn( lastred, k ) ) {

            case 0: /* precedence does not apply */

                settty();
                printf("\n%d: shift/reduce conflict (shift %d, red'n %d) on %s", i,
			temp1[k], lastred, symnam(k) );
                ++zzsrconf;
                settab();
                break;

            case 1: /*  reduce */

                temp1[k] = -lastred;
                break;

            case 2: /* error, binary operator */

                temp1[k] = ERRCODE;
                break;

            case 3: /* shift ... leave the entry alone */

                break;
                }
              }
            }
          }
        }
      }
    wract(i);
    }