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

  1.  
  2. # include "y3.h" 
  3.  
  4. /*
  5.  * yapack.3c
  6.  *
  7.  * Modified to make debug code conditionally compile.
  8.  * 28-Aug-81
  9.  * Bob Denny
  10.  */
  11. apack( p, n )
  12. int * p;
  13. {
  14.   /* pack state i from temp1 into amem */
  15.   int        off;
  16.   register * pp,
  17.            * qq,
  18.            * rr;
  19.   int      * q,
  20.            * r;
  21.  
  22.   /* we don't need to worry about checking because we
  23.                   we will only look entries known to be there... */
  24.  
  25.   /* eliminate leading and trailing 0's */
  26.  
  27.   q = p + n;
  28.   for ( pp = p, off = 0; *pp == 0 && pp <= q; ++pp, --off ) /* VOID */
  29.     ;
  30.   if ( pp > q )
  31.     return ( 0 ); /* no actions */
  32.   p = pp;
  33.  
  34.   /* now, find a place for the elements from p to q, inclusive */
  35.  
  36.   r = &amem[ ACTSIZE - 1 ];
  37.   for ( rr = amem; rr <= r; ++rr, ++off )
  38.     {
  39.       /* try rr */
  40.       for ( qq = rr, pp = p; pp <= q; ++pp, ++qq )
  41.         {
  42.           if ( *pp != 0 )
  43.             {
  44.               if ( *pp != *qq && *qq != 0 )
  45.                 goto nextk;
  46.             }
  47.         }
  48.  
  49.       /* we have found an acceptable k */
  50.  
  51.       # ifdef debug
  52.       if ( foutput != NULL )
  53.         fprintf( foutput, "off = %d, k = %d\n", off, rr - amem );
  54.         # endif 
  55.       for ( qq = rr, pp = p; pp <= q; ++pp, ++qq )
  56.         {
  57.           if ( *pp )
  58.             {
  59.               if ( qq > r )
  60.                 error( "action table overflow" );
  61.               if ( qq > memp )
  62.                 memp = qq;
  63.               *qq = *pp;
  64.             }
  65.         }
  66.       # ifdef debug
  67.       if ( foutput != NULL )
  68.         {
  69.           for ( pp = amem; pp <= memp; pp += 10 )
  70.             {
  71.               fprintf( foutput, "\t" );
  72.               for ( qq = pp; qq <= pp + 9; ++qq )
  73.                 fprintf( foutput, "%d ", *qq );
  74.               fprintf( foutput, "\n" );
  75.             }
  76.         }
  77.         # endif 
  78.       return ( off );
  79.  
  80.       nextk : ;
  81.     }
  82.   error( "no space in action table" );
  83.   /* NOTREACHED */
  84. }
  85.