home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OS2-YACC.ZIP / YPRCFT.3C < prev    next >
Text File  |  1989-09-30  |  2KB  |  58 lines

  1. /*
  2.   HEADER: CUG     nnn.nn;
  3.   TITLE:     YACC - Yet Another Compilier-Compilier
  4.   VERSION:     1.0 for IBM-PC
  5.   DATE:      JAN 28, 1985
  6.   DESCRIPTION:     LALR(1) Parser Generator. From UNIX
  7.   KEYWORDS:     Parser Generator Compilier-Compilier YACC
  8.   SYSTEM:     IBM-PC and Compatiables
  9.   FILENAME:      YPRCFT.3C
  10.   WARNINGS:     This program is not for the casual user. It will
  11.          be useful primarily to expert developers.
  12.   CRC:         N/A
  13.   SEE-ALSO:     LEX and PREP
  14.   AUTHORS:     Scott Guthery 11100 leafwood lane Austin, TX 78750
  15.   COMPILERS:     DESMET-C
  16.   REFERENCES:     UNIX Systems Manuals
  17. */
  18.  
  19. #include "y1.h"
  20. #include "y3.h"
  21.  
  22. void precftn( int r, int t, int s )
  23.    {
  24.    /* decide a shift/reduce conflict by precedence.*/
  25.    /* r is a rule number, t a token number */
  26.    /* the conflict is in state s */
  27.    /* temp1[t] is changed to reflect the action */
  28.  
  29.    int lp,lt, action;
  30.  
  31.    lp = levprd[r];
  32.    lt = toklev[t];
  33.    if( PLEVEL(lt) == 0 || PLEVEL(lp) == 0 ) 
  34.       {
  35.       /* conflict */
  36.       if( foutput != NULL ) fprintf( foutput, "\n%d: shift/reduce conflict (shift %d, red'n %d) on %s",
  37.       s, temp1[t], r, symnam(t) );
  38.       ++zzsrconf;
  39.       return;
  40.       }
  41.    if( PLEVEL(lt) == PLEVEL(lp) ) action = ASSOC(lt);
  42.    else if( PLEVEL(lt) > PLEVEL(lp) ) action = RASC;  /* shift */
  43.    else action = LASC;  /* reduce */
  44.  
  45.    switch( action )
  46.       {
  47.  
  48.    case BASC:  /* error action */
  49.       temp1[t] = ERRCODE;
  50.       return;
  51.  
  52.    case LASC:  /* reduce */
  53.       temp1[t] = -r;
  54.       return;
  55.  
  56.       }
  57.    }
  58.