home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / YACCUNX.ZIP / YPRCFT.3C < prev    next >
Encoding:
Text File  |  1983-12-24  |  916 b   |  39 lines

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