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