home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OS2-YACC.ZIP / YGIN.4C < prev    next >
Text File  |  1989-09-30  |  2KB  |  74 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:      YGIN.4C
  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 "y4.h"
  21.  
  22. void gin( int i )
  23.    {
  24.  
  25.    register *p, *r, *s, *q1, *q2;
  26.  
  27.    /* enter gotos on nonterminal i into array a */
  28.  
  29.    ggreed[i] = 0;
  30.  
  31.    q2 = mem0+ yypgo[i+1] - 1;
  32.    q1 = mem0 + yypgo[i];
  33.  
  34.    /* now, find a place for it */
  35.  
  36.    for( p=a; p < &a[ACTSIZE]; ++p )
  37.       {
  38.       if( *p ) continue;
  39.       for( r=q1; r<q2; r+=2 )
  40.          {
  41.          s = p + *r +1;
  42.          if( *s ) goto nextgp;
  43.          if( s > maxa )
  44.             {
  45.             if( (maxa=s) > &a[ACTSIZE] ) error( "a array overflow" );
  46.             }
  47.          }
  48.       /* we have found a spot */
  49.  
  50.       *p = *q2;
  51.       if( p > maxa )
  52.          {
  53.          if( (maxa=p) > &a[ACTSIZE] ) error( "a array overflow" );
  54.          }
  55.       for( r=q1; r<q2; r+=2 )
  56.          {
  57.          s = p + *r + 1;
  58.          *s = r[1];
  59.          }
  60.  
  61.       pgo[i] = p-a;
  62.       if( adb>1 ) fprintf( ftable, "Nonterminal %d, entry at %d\n" , i, pgo[i] );
  63.       goto nextgi;
  64.  
  65. nextgp:  
  66.       ;
  67.       }
  68.  
  69.    error( "cannot place goto %d\n", i );
  70.  
  71. nextgi:  
  72.    ;
  73.    }
  74.