Commit | Line | Data |
---|---|---|
d503ec6c BJ |
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.2 January 1979 | |
8 | * | |
9 | * | |
10 | * pxp - Pascal execution profiler | |
11 | * | |
12 | * Bill Joy UCB | |
13 | * Version 1.2 January 1979 | |
14 | */ | |
15 | ||
16 | #include "0.h" | |
17 | #include "yy.h" | |
18 | ||
19 | /* | |
20 | * Parser for 'yacc' output. | |
21 | * Specifially Modified for Berkeley Pascal | |
22 | */ | |
23 | ||
24 | int yystate; /* Current parser state */ | |
25 | int *yypv; | |
26 | unsigned yytshifts 1; /* Number of "true" shifts */ | |
27 | ||
28 | /* | |
29 | * Parse Tables | |
30 | */ | |
31 | int yygo[]; | |
32 | int yypgo[]; | |
33 | int yyr1[]; | |
34 | int yyr2[]; | |
35 | int yyact[]; | |
36 | int yypact[]; | |
37 | ||
38 | /* | |
39 | * Parse and parallel semantic stack | |
40 | */ | |
41 | int yyv[MAXDEPTH]; | |
42 | int 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 | */ | |
49 | yyparse() | |
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 | ||
65 | stack: | |
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 | |
78 | newstate: | |
79 | /* | |
80 | * Locate parsing actions for the | |
81 | * new parser state. | |
82 | */ | |
83 | p = &yyact[ yypact[yystate+1] ]; | |
84 | actn: | |
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 | #ifdef PI | |
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 | #else | |
101 | while ((n = *p++) <= 0) | |
102 | if ((n =+ yychar) != 0) | |
103 | p++; | |
104 | #endif | |
105 | switch (n >> 12) { | |
106 | ||
107 | /* | |
108 | * Shift. | |
109 | */ | |
110 | case 2: | |
111 | #ifdef PXP | |
112 | yypw[1].Wseqid = yyseqid; | |
113 | yypw[1].Wcol = yycol; | |
114 | #endif | |
115 | OYcopy(); | |
116 | yystate = n & 07777; | |
117 | yyval = yylval; | |
118 | #ifdef PI | |
119 | yychar = -1; | |
120 | #else | |
121 | yychar = yylex(); | |
122 | #endif | |
123 | yyshifts++; | |
124 | yytshifts++; | |
125 | goto stack; | |
126 | ||
127 | /* | |
128 | * Reduce. | |
129 | */ | |
130 | case 3: | |
131 | n =& 07777; | |
132 | N = yyr2[n]; | |
133 | if (N == 1 && OY.Yychar == YID && !yyEactr(n, yypv[0])) { | |
134 | idfail = 1; | |
135 | goto errin; | |
136 | } | |
137 | OY.Yychar = -1; | |
138 | ps =- N; | |
139 | yypv =- N; | |
140 | #ifdef PXP | |
141 | yypw =- N; | |
142 | #endif | |
143 | yyval = yypv[1]; | |
144 | yyactr(n); | |
145 | /* | |
146 | * Use goto table to find next state. | |
147 | */ | |
148 | p = &yygo[yypgo[yyr1[n]]]; | |
149 | while (*p != *ps && *p >= 0) | |
150 | p =+ 2; | |
151 | yystate = p[1]; | |
152 | goto stack; | |
153 | ||
154 | /* | |
155 | * Accept. | |
156 | */ | |
157 | case 4: | |
158 | return; | |
159 | ||
160 | /* | |
161 | * Error. | |
162 | */ | |
163 | case 1: | |
164 | idfail = 0; | |
165 | errin: | |
166 | if ((paniced || yyshifts != 0) && yyrecover(ps, idfail)) { | |
167 | paniced = 0; | |
168 | ps = Ps; | |
169 | yystate = *ps; | |
170 | goto newstate; | |
171 | } | |
172 | /* | |
173 | * Find a state where 'error' is a | |
174 | * legal shift action. | |
175 | */ | |
176 | if (paniced && yyshifts <= 0 && ps >= panicps) { | |
177 | yypv =- (ps - panicps) + 1; | |
178 | #ifdef PXP | |
179 | yypw =- (ps - panicps) + 1; | |
180 | #endif | |
181 | ps = panicps - 1; | |
182 | } | |
183 | while (ps >= yys) { | |
184 | for (p = &yyact[ yypact[*ps+1] ] ; *p <= 0; p=+ 2) | |
185 | if (*p == -256) { | |
186 | panicps = ps; | |
187 | yystate= p[1] & 07777; | |
188 | yyOshifts = yyshifts; | |
189 | yyshifts = 0; | |
190 | paniced = 1; | |
191 | goto stack; | |
192 | } | |
193 | --ps; | |
194 | --yypv; | |
195 | #ifdef PXP | |
196 | --yypw; | |
197 | #endif | |
198 | #ifdef PI | |
199 | if (OY.Yychar != YID) | |
200 | syneflg++; | |
201 | #endif | |
202 | OY.Yychar = -1; | |
203 | } | |
204 | if (yychar == YEOF) | |
205 | yyunexeof(); | |
206 | if (yystate == 1) | |
207 | yyexeof(); | |
208 | yerror("Unrecoverable syntax error - QUIT"); | |
209 | return; | |
210 | } | |
211 | panic("yyparse"); | |
212 | } |