home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OS2-YACC.ZIP / YOTHRS.1C < prev    next >
Text File  |  1989-09-29  |  2KB  |  100 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:     YOTHRS.1C
  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. /* Edits:
  20.  *    06-Dec-80 Original code broken out of y1.c.
  21.  *    18-Dec-80 Add conditional code for Decus for tempfile deletion.
  22.  */
  23.  
  24. #include "y1.h"
  25. #include "y3.h"
  26.  
  27. void others( void )
  28.    {
  29.    /* put out other arrays, copy the parsers */
  30.    register c, i, j;
  31.  
  32.    finput = fopen( PARSER, "r" );
  33.    if( finput == NULL ) error( "cannot find parser %s", PARSER );
  34.  
  35.    warray( "yyr1", levprd, nprod );
  36.  
  37.    aryfil( temp1, nprod, 0 );
  38.    PLOOP(1,i)temp1[i] = prdptr[i+1]-prdptr[i]-2;
  39.    warray( "yyr2", temp1, nprod );
  40.  
  41.    aryfil( temp1, nstate, -1000 );
  42.    TLOOP(i)
  43.       {
  44.       for( j=tstates[i]; j!=0; j=mstates[j] )
  45.      {
  46.      temp1[j] = tokset[i].value;
  47.      }
  48.       }
  49.    NTLOOP(i)
  50.       {
  51.       for( j=ntstates[i]; j!=0; j=mstates[j] )
  52.      {
  53.      temp1[j] = -i;
  54.      }
  55.       }
  56.    warray( "yychk", temp1, nstate );
  57.  
  58.    warray( "yydef", defact, nstate );
  59.  
  60.    /* copy parser text */
  61.  
  62.    while( (c=unix_getc(finput) ) != EOF )
  63.       {
  64.       if( c == '$' )
  65.      {
  66.      if( (c=unix_getc(finput)) != 'A' ) putc( '$', ftable );
  67.      else
  68.         {
  69.         /* copy actions */
  70.         faction = fopen( ACTNAME, "r" );
  71.         if( faction == NULL ) error( "cannot reopen action tempfile" );
  72.         while( (c=unix_getc(faction) ) != EOF ) putc( c, ftable );
  73.         fclose(faction);
  74.         ZAPFILE(ACTNAME);
  75.         c = unix_getc(finput);
  76.         }
  77.      }
  78.  
  79.       putc( c, ftable );
  80.       }
  81.  
  82.    fclose( ftable );
  83.    }
  84.  
  85. static char getbuf[30], *getbufptr = getbuf;
  86.  
  87. int unix_getc(FILE *iop)
  88. {
  89.     if(getbufptr == getbuf)
  90.                 return(getc(iop));
  91.     else
  92.         return(*--getbufptr);
  93. }
  94.  
  95. void uungetc( char c, FILE *iop )
  96. /* WARNING: iop ignored ... uungetc's are multiplexed!!! */
  97. {
  98.     *getbufptr++ = c;
  99. }
  100.