home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OS2-YACC.ZIP / YCPUNI.2C < prev    next >
Text File  |  1989-09-29  |  2KB  |  62 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:      YCPUNI.2C
  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 "y2.h"
  21.  
  22. void cpyunion( void )
  23.    {
  24.    /* copy the union declaration to the output, and the define file if present */
  25.  
  26.    int level, c;
  27.    fprintf( ftable, "\n# line %d\n", lineno );
  28.    fprintf( ftable, "\n#define UNION 1\n");
  29.    fprintf( ftable, "typedef union " );
  30.    if( fdefine ) fprintf( fdefine, "\ntypedef union " );
  31.  
  32.    level = 0;
  33.    for(;;)
  34.       {
  35.       if( (c=unix_getc(finput)) < 0 ) error( "EOF encountered while processing %%union" );
  36.       putc( c, ftable );
  37.       if( fdefine ) putc( c, fdefine );
  38.  
  39.       switch( c )
  40.          {
  41.  
  42.       case '\n':
  43.          ++lineno;
  44.          break;
  45.  
  46.       case '{':
  47.          ++level;
  48.          break;
  49.  
  50.       case '}':
  51.          --level;
  52.          if( level == 0 ) 
  53.             {
  54.             /* we are finished copying */
  55.             fprintf( ftable, " YYSTYPE;\n" );
  56.             if( fdefine ) fprintf( fdefine, " YYSTYPE;\nextern YYSTYPE yylval;\n" );
  57.             return;
  58.             }
  59.          }
  60.       }
  61.    }
  62.