Start development on BSD 2
[unix-history] / .ref-BSD-1 / pxp / yypanic.c
CommitLineData
8ca692a3
CH
1#
2/*
3 * pi - Pascal interpreter code translator
4 *
5 * Charles Haley, Bill Joy UCB
6 * Version 1.0 August 1977
7 *
8 *
9 * pxp - Pascal execution profiler
10 *
11 * Bill Joy UCB
12 * Version 1.0 August 1977
13 */
14
15#include "whoami"
16#include "0.h"
17#include "yy.h"
18
19
20/*
21 * The routine yyPerror coordinates the panic when
22 * the correction routines fail. Three types of panics
23 * are possible - those in a declaration part, those
24 * in a statement part, and those in an expression.
25 *
26 * Declaration part panics consider insertion of "begin",
27 * expression part panics will stop on more symbols.
28 * The panics are otherwise the same.
29 *
30 * ERROR MESSAGE SUPPRESSION STRATEGY: August 11, 1977
31 *
32 * If the parser has not made at least 2 moves since the last point of
33 * error then we want to suppress the supplied error message.
34 * Otherwise we print it.
35 * We then skip input up to the next solid symbol.
36 */
37yyPerror(cp, kind)
38 char *cp;
39 int kind;
40{
41 struct yytok oldpos;
42 int ishifts, brlev;
43
44 copy(&oldpos, &Y, sizeof oldpos);
45 brlev = 0;
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 }
132resume:
133 if (yyOshifts >= 2) {
134 if (yychar != -1)
135 unyylex(&Y);
136 copy(&Y, &oldpos, sizeof Y);
137 yerror(cp);
138 yychar = yylex();
139 }
140quiet:
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}