1: /*	@(#)yyparse.c	2.2	SCCS id keyword	*/
   2: /* Copyright (c) 1979 Regents of the University of California */
   3: #
   4: /*
   5:  * pi - Pascal interpreter code translator
   6:  *
   7:  * Charles Haley, Bill Joy UCB
   8:  * Version 1.1 February 1978
   9:  *
  10:  *
  11:  * pxp - Pascal execution profiler
  12:  *
  13:  * Bill Joy UCB
  14:  * Version 1.1 February 1978
  15:  */
  16: 
  17: #include "whoami"
  18: #include "0.h"
  19: #include "yy.h"
  20: 
  21: /*
  22:  * Parser for 'yacc' output.
  23:  * Specifially Modified for Berkeley Pascal
  24:  */
  25: 
  26: int yystate;    /* Current parser state */
  27: int *yypv;
  28: unsigned yytshifts = 1; /* Number of "true" shifts */
  29: 
  30: /*
  31:  * Parse Tables
  32:  */
  33: int yygo[];
  34: int yypgo[];
  35: int yyr1[];
  36: int yyr2[];
  37: int yyact[];
  38: int yypact[];
  39: 
  40: /*
  41:  * Parse and parallel semantic stack
  42:  */
  43: int yyv[MAXDEPTH];
  44: int yys[MAXDEPTH];
  45: 
  46: /*
  47:  * This routine parses the input stream, and
  48:  * returns if it accepts, or if an unrecoverable syntax
  49:  * error is encountered.
  50:  */
  51: yyparse()
  52: {
  53:     register int *ps, n, *p;
  54:     int paniced, *panicps, idfail;
  55: 
  56:     yystate = 0;
  57:     yychar = yylex();
  58:     OY.Yychar = -1;
  59:     yyshifts = 3;
  60:     paniced = 0;
  61:     ps = &yys[0]-1;
  62:     yypv = &yyv[0]-1;
  63: #ifdef PXP
  64:     yypw = &yyw[0]-1;
  65: #endif
  66: 
  67: stack:
  68:     /*
  69: 	 * Push new state and value.
  70: 	 */
  71:     if (yypv >= &yyv[MAXDEPTH-1]) {
  72:         yerror("Parse stack overflow");
  73:         pexit(DIED);
  74:     }
  75:     *++ps = yystate;
  76:     *++yypv = yyval;
  77: #ifdef PXP
  78:     yypw++;
  79: #endif
  80: newstate:
  81:     /*
  82: 	 * Locate parsing actions for the
  83: 	 * new parser state.
  84: 	 */
  85:     p = &yyact[ yypact[yystate+1] ];
  86: actn:
  87:     /*
  88: 	 * Search the parse actions table
  89: 	 * for something useful to do.
  90: 	 * While n is non-positive, it is the negation
  91: 	 * of the token we are testing for.
  92: 	 */
  93: #ifdef PI
  94:     if ((n = *p++) <= 0) {
  95:         if (yychar < 0)
  96:             yychar = yylex();
  97:         do
  98:             if ((n += yychar) != 0)
  99:                 p++;
 100:         while ((n = *p++) <= 0);
 101:     }
 102: #else
 103:     while ((n = *p++) <= 0)
 104:         if ((n += yychar) != 0)
 105:             p++;
 106: #endif
 107:     switch (n >> 12) {
 108: 
 109:         /*
 110: 		 * Shift.
 111: 		 */
 112:         case 2:
 113: #ifdef PXP
 114:             yypw[1].Wseqid = yyseqid;
 115:             yypw[1].Wcol = yycol;
 116: #endif
 117:             OYcopy();
 118:             yystate = n & 07777;
 119:             yyval = yylval;
 120: #ifdef PI
 121:             yychar = -1;
 122: #else
 123:             yychar = yylex();
 124: #endif
 125:             yyshifts++;
 126:             yytshifts++;
 127:             goto stack;
 128: 
 129:         /*
 130: 		 * Reduce.
 131: 		 */
 132:         case 3:
 133:             n &= 07777;
 134:             N = yyr2[n];
 135:             if (N == 1 && OY.Yychar == YID && !yyEactr(n, yypv[0])) {
 136:                 idfail = 1;
 137:                 goto errin;
 138:             }
 139:             OY.Yychar = -1;
 140:             ps -= N;
 141:             yypv -= N;
 142: #ifdef PXP
 143:             yypw -= N;
 144: #endif
 145:             yyval = yypv[1];
 146:             yyactr(n);
 147:             /*
 148: 			 * Use goto table to find next state.
 149: 			 */
 150:             p = &yygo[yypgo[yyr1[n]]];
 151:             while (*p != *ps && *p >= 0)
 152:                 p += 2;
 153:             yystate = p[1];
 154:             goto stack;
 155: 
 156:         /*
 157: 		 * Accept.
 158: 		 */
 159:         case 4:
 160:             return;
 161: 
 162:         /*
 163: 		 * Error.
 164: 		 */
 165:         case 1:
 166:             idfail = 0;
 167: errin:
 168:             if ((paniced || yyshifts != 0) && yyrecover(ps, idfail)) {
 169:                 paniced = 0;
 170:                 ps = Ps;
 171:                 yystate = *ps;
 172:                 goto newstate;
 173:             }
 174:             /*
 175: 			 * Find a state where 'error' is a
 176: 			 * legal shift action.
 177: 			 */
 178:             if (paniced && yyshifts <= 0 && ps >= panicps) {
 179:                 yypv -= (ps - panicps) + 1;
 180: #ifdef PXP
 181:                 yypw -= (ps - panicps) + 1;
 182: #endif
 183:                 ps = panicps - 1;
 184:             }
 185:             while (ps >= yys) {
 186:                 for (p = &yyact[ yypact[*ps+1] ] ; *p <= 0; p+= 2)
 187:                     if (*p == -256) {
 188:                         panicps = ps;
 189:                         yystate= p[1] & 07777;
 190:                         yyOshifts = yyshifts;
 191:                         yyshifts = 0;
 192:                         paniced = 1;
 193:                         goto stack;
 194:                     }
 195:                 --ps;
 196:                 --yypv;
 197: #ifdef PXP
 198:                 --yypw;
 199: #endif
 200: #ifdef PI
 201:                 if (OY.Yychar != YID)
 202:                     syneflg++;
 203: #endif
 204:                 OY.Yychar = -1;
 205:             }
 206:             if (yychar == YEOF)
 207:                 yyunexeof();
 208:             if (yystate == 1)
 209:                 yyexeof();
 210:             yerror("Unrecoverable syntax error - QUIT");
 211:             return;
 212:     }
 213:     panic("yyparse");
 214: }

Defined functions

yyparse defined in line 51; used 1 times

Defined variables

yyact defined in line 37; used 2 times
yygo defined in line 33; used 2 times
yypact defined in line 38; used 2 times
yypgo defined in line 34; used 2 times
yypv defined in line 27; used 9 times
yyr1 defined in line 35; used 2 times
yyr2 defined in line 36; used 2 times
yys defined in line 44; used 2 times
yystate defined in line 26; used 8 times
yytshifts defined in line 28; used 1 times
yyv defined in line 43; used 2 times
Last modified: 1986-06-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2543
Valid CSS Valid XHTML 1.0 Strict