# 2.11BSD#431 - /usr/src/ucb/pascal/pi/yypanic.c

##### Functions

    yyPerror          X

##### Variables

    oldpos            X

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

#### Defined functions

yyPerror defined in line 39; used 10 times

- in /usr/src/ucb/pascal/pi/pas.y line 142, 171, 222, 244, 266, 446, 474, 535, 624, 642

#### Defined variables

oldpos defined in line 21; used 3 times

- in line 45(2), 139

Last modified: 1981-07-10 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 603 |