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