home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OS2-YACC.ZIP / YAPACK.3C < prev    next >
Text File  |  1989-09-29  |  2KB  |  93 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:      YAPACK.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. /*
  23.  * yapack.3c
  24.  *
  25.  * Modified to make debug code conditionally compile.
  26.  * 28-Aug-81
  27.  * Bob Denny
  28.  */
  29. int apack( int *p, int n )
  30.    {
  31.    /* pack state i from temp1 into amem */
  32.    int off;
  33.    register *pp, *qq, *rr;
  34.    int *q, *r;
  35.  
  36.    /* we don't need to worry about checking because we
  37.                    we will only look entries known to be there... */
  38.  
  39.    /* eliminate leading and trailing 0's */
  40.  
  41.    q = p+n;
  42.    for( pp=p,off=0 ; *pp==0 && pp<=q; ++pp,--off ) /* VOID */ ;
  43.    if( pp > q ) return(0);  /* no actions */
  44.    p = pp;
  45.  
  46.    /* now, find a place for the elements from p to q, inclusive */
  47.  
  48.    r = &amem[ACTSIZE-1];
  49.    for( rr=amem; rr<=r; ++rr,++off )
  50.       {
  51.       /* try rr */
  52.       for( qq=rr,pp=p ; pp<=q ; ++pp,++qq)
  53.          {
  54.          if( *pp != 0 )
  55.             {
  56.             if( *pp != *qq && *qq != 0 ) goto nextk;
  57.             }
  58.          }
  59.  
  60.       /* we have found an acceptable k */
  61.  
  62. #ifdef debug
  63.       if(foutput!=NULL) fprintf(foutput,"off = %d, k = %d\n",off,rr-amem);
  64. #endif
  65.       for( qq=rr,pp=p; pp<=q; ++pp,++qq )
  66.          {
  67.          if( *pp )
  68.             {
  69.             if( qq > r ) error( "action table overflow" );
  70.             if( qq>memp ) memp = qq;
  71.             *qq = *pp;
  72.             }
  73.          }
  74. #ifdef debug
  75.       if( foutput!=NULL )
  76.          {
  77.          for( pp=amem; pp<= memp; pp+=10 )
  78.             {
  79.             fprintf( foutput, "\t");
  80.             for( qq=pp; qq<=pp+9; ++qq ) fprintf( foutput, "%d ", *qq );
  81.             fprintf( foutput, "\n");
  82.             }
  83.          }
  84. #endif
  85.       return( off );
  86.  
  87. nextk: 
  88.       ;
  89.       }
  90.    error("no space in action table" );
  91.    /* NOTREACHED */
  92.    }
  93.