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: struct yytok oldpos;
  19: /*
  20:  * The routine yyPerror coordinates the panic when
  21:  * the correction routines fail. Three types of panics
  22:  * are possible - those in a declaration part, those
  23:  * in a statement part, and those in an expression.
  24:  *
  25:  * Declaration part panics consider insertion of "begin",
  26:  * expression part panics will stop on more symbols.
  27:  * The panics are otherwise the same.
  28:  *
  29:  * ERROR MESSAGE SUPPRESSION STRATEGY: August 11, 1977
  30:  *
  31:  * If the parser has not made at least 2 moves since the last point of
  32:  * error then we want to suppress the supplied error message.
  33:  * Otherwise we print it.
  34:  * We then skip input up to the next solid symbol.
  35:  */
  36: yyPerror(cp, kind)
  37:     char *cp;
  38:     register int kind;
  39: {
  40:     register int ishifts, brlev;
  41: 
  42:     copy(&oldpos, &Y, sizeof oldpos);
  43:     brlev = 0;
  44:     if (yychar < 0)
  45:         yychar = yylex();
  46:     for (ishifts = yyshifts; ; yychar = yylex(), yyshifts++)
  47:         switch (yychar) {
  48:             case YILLCH:
  49:                 yerror("Illegal character");
  50:                 if (ishifts == yyshifts)
  51:                     yyOshifts = 0;
  52:                 continue;
  53:             case YEOF:
  54:                 goto quiet;
  55:             case ';':
  56:                 if (kind == PPROG)
  57:                     continue;
  58:                 if (kind == PDECL)
  59:                     yychar = yylex();
  60:                 goto resume;
  61:             case YEND:
  62:                 if (kind == PPROG)
  63:                     continue;
  64:             case YPROCEDURE:
  65:             case YFUNCTION:
  66:                 goto resume;
  67:             case YLABEL:
  68:             case YTYPE:
  69:             case YCONST:
  70:             case YVAR:
  71:                 if (kind == PSTAT) {
  72:                     yerror("Declaration found when statement expected");
  73:                     goto quiet;
  74:                 }
  75:             case YBEGIN:
  76:                 goto resume;
  77:             case YFOR:
  78:             case YREPEAT:
  79:             case YWHILE:
  80:             case YGOTO:
  81:             case YIF:
  82:                 if (kind != PDECL)
  83:                     goto resume;
  84:                 yerror("Expected keyword begin after declarations, before statements");
  85:                 unyylex(&Y);
  86:                 yychar = YBEGIN;
  87:                 yylval = nullsem(YBEGIN);
  88:                 goto quiet;
  89:             case YTHEN:
  90:             case YELSE:
  91:             case YDO:
  92:                 if (kind == PSTAT) {
  93:                     yychar = yylex();
  94:                     goto resume;
  95:                 }
  96:                 if (kind == PEXPR)
  97:                     goto resume;
  98:                 continue;
  99:             case ')':
 100:             case ']':
 101:                 if (kind != PEXPR)
 102:                     continue;
 103:                 if (brlev == 0)
 104:                     goto resume;
 105:                 if (brlev > 0)
 106:                     brlev--;
 107:                 continue;
 108:             case '(':
 109:             case '[':
 110:                 brlev++;
 111:                 continue;
 112:             case ',':
 113:                 if (brlev != 0)
 114:                     continue;
 115:             case YOF:
 116:             case YTO:
 117:             case YDOWNTO:
 118:                 if (kind == PEXPR)
 119:                     goto resume;
 120:                 continue;
 121: #ifdef PI
 122:             /*
 123: 			 * A rough approximation for now
 124: 			 * Should be much more lenient on suppressing
 125: 			 * warnings.
 126: 			 */
 127:             case YID:
 128:                 syneflg++;
 129:                 continue;
 130: #endif
 131:         }
 132: resume:
 133:     if (yyOshifts >= 2) {
 134:         if (yychar != -1)
 135:             unyylex(&Y);
 136:         copy(&Y, &oldpos, sizeof Y);
 137:         yerror(cp);
 138:         yychar = yylex();
 139:     }
 140: quiet:
 141:     if (yyshifts - ishifts > 2 && opt('r')) {
 142:         setpfx('r');
 143:         yerror("Parsing resumes");
 144:     }
 145:     /*
 146: 	 * If we paniced in the statement part,
 147: 	 * and didn't stop at a ';', then we insert
 148: 	 * a ';' to prevent the recovery from immediately
 149: 	 * inserting one and complaining about it.
 150: 	 */
 151:     if (kind == PSTAT && yychar != ';') {
 152:         unyylex(&Y);
 153:         yyshifts--;
 154:         yytshifts--;
 155:         yychar = ';';
 156:         yylval = nullsem(';');
 157:     }
 158: }

Defined functions

yyPerror defined in line 36; used 10 times

Defined variables

oldpos defined in line 18; used 3 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2071
Valid CSS Valid XHTML 1.0 Strict