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

Defined functions

yyparse defined in line 48; used 1 times

Defined variables

yyact defined in line 34; used 2 times
yygo defined in line 30; used 2 times
yypact defined in line 35; used 2 times
yypgo defined in line 31; used 2 times
yypv defined in line 24; used 9 times
yyr1 defined in line 32; used 2 times
yyr2 defined in line 33; used 2 times
yys defined in line 41; used 2 times
yystate defined in line 23; used 8 times
yytshifts defined in line 25; used 1 times
yyv defined in line 40; used 2 times
Last modified: 1986-06-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2214
Valid CSS Valid XHTML 1.0 Strict