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

  1. /* Edits:
  2.  *      06-Dec-80 Original code broken out of y1.c.
  3.  *      18-Dec-80 Add conditional code for Decus for tempfile deletion.
  4.  *      26-Apr-91 Changed function ungetc to yacc_ungetc because of
  5.  *                conflict with Turbo-C macro for ungetc
  6.  */
  7.  
  8. # include "y1.h" 
  9.  
  10. void others( )
  11. {
  12.   /* put out other arrays, copy the parsers */
  13.   register c,
  14.            i,
  15.            j;
  16.  
  17.   finput = fopen( PARSER, "r" );
  18.   if ( finput == NULL )
  19.     error( "cannot find parser %s", PARSER );
  20.  
  21.   warray( "yyr1", levprd, nprod );
  22.  
  23.   aryfil( temp1, nprod, 0 );
  24.   PLOOP( 1, i )
  25.     temp1[ i ] = prdptr[ i + 1 ] - prdptr[ i ] - 2;
  26.   warray( "yyr2", temp1, nprod );
  27.  
  28.   aryfil( temp1, nstate, -1000 );
  29.   TLOOP( i )
  30.     {
  31.       for ( j = tstates[ i ]; j != 0; j = mstates[ j ] )
  32.         {
  33.           temp1[ j ] = tokset[ i ].value;
  34.         }
  35.     }
  36.   NTLOOP( i )
  37.     {
  38.       for ( j = ntstates[ i ]; j != 0; j = mstates[ j ] )
  39.         {
  40.           temp1[ j ] = -i;
  41.         }
  42.     }
  43.   warray( "yychk", temp1, nstate );
  44.  
  45.   warray( "yydef", defact, nstate );
  46.  
  47.   /* copy parser text */
  48.  
  49.   while ( ( c = unix_getc( finput ) ) != EOF )
  50.     {
  51.       if ( c == '$' )
  52.         {
  53.           if ( ( c = unix_getc( finput ) ) != 'A' )
  54.             putc( '$', ftable );
  55.           else
  56.             {
  57.               /* copy actions */
  58.               faction = fopen( ACTNAME, "r" );
  59.               if ( faction == NULL )
  60.                 error( "cannot reopen action tempfile" );
  61.               while ( ( c = unix_getc( faction ) ) != EOF )
  62.                 putc( c, ftable );
  63.               fclose( faction );
  64.               ZAPFILE( ACTNAME );
  65.               c       = unix_getc( finput );
  66.             }
  67.         }
  68.       putc( c, ftable );
  69.     }
  70.  
  71.   fclose( ftable );
  72. }
  73.  
  74. static char getbuf[ 30 ],
  75.           * getbufptr = getbuf;
  76.  
  77. int unix_getc( iop )
  78. FILE * iop;
  79. {
  80.   if ( getbufptr == getbuf )
  81.     return ( getc( iop ) );
  82.   else
  83.     return ( *--getbufptr );
  84. }
  85.  
  86. int yacc_ungetc( int c )
  87. {
  88.   return ( *getbufptr++ = c );
  89. }
  90.