home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / yaccsrc2 / yprcft.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-19  |  1.1 KB  |  51 lines

  1.  
  2. # include "y3.h" 
  3.  
  4. void precftn( r, t, s )
  5. {
  6.   /* decide a shift/reduce conflict by precedence.*/
  7.   /* r is a rule number, t a token number */
  8.   /* the conflict is in state s */
  9.   /* temp1[t] is changed to reflect the action */
  10.  
  11.   int lp,
  12.       lt,
  13.       action;
  14.  
  15.   lp = levprd[ r ];
  16.   lt = toklev[ t ];
  17.   if ( PLEVEL( lt ) == 0 || PLEVEL( lp ) == 0 )
  18.     {
  19.       /* conflict */
  20.       if ( foutput != NULL )
  21.         fprintf( foutput,
  22.                  "\n%d: shift/reduce conflict (shift %d, red'n %d) on %s",
  23.                  s,
  24.                  temp1[ t ],
  25.                  r,
  26.                  symnam( t ) );
  27.       ++zzsrconf;
  28.       return;
  29.     }
  30.   if ( PLEVEL( lt ) == PLEVEL( lp ) )
  31.     action = ASSOC( lt );
  32.   else
  33.     if ( PLEVEL( lt ) > PLEVEL( lp ) )
  34.       action = RASC; /* shift */
  35.     else
  36.       action = LASC; /* reduce */
  37.  
  38.   switch ( action )
  39.     {
  40.  
  41.       case BASC : /* error action */
  42.         temp1[ t ] = ERRCODE;
  43.         return;
  44.  
  45.       case LASC : /* reduce */
  46.         temp1[ t ] = -r;
  47.         return;
  48.  
  49.     }
  50. }
  51.