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