Tue Jan 24 22:28:42 2017 UTC ()
don't output extern YYSTYPE decl if pure_parser.


(christos)
diff -r1.15 -r1.16 src/external/bsd/byacc/dist/output.c

cvs diff -r1.15 -r1.16 src/external/bsd/byacc/dist/output.c (switch to unified diff)

--- src/external/bsd/byacc/dist/output.c 2016/01/09 22:05:33 1.15
+++ src/external/bsd/byacc/dist/output.c 2017/01/24 22:28:42 1.16
@@ -1,2076 +1,2077 @@ @@ -1,2076 +1,2077 @@
1/* $NetBSD: output.c,v 1.15 2016/01/09 22:05:33 christos Exp $ */ 1/* $NetBSD: output.c,v 1.16 2017/01/24 22:28:42 christos Exp $ */
2 2
3/* Id: output.c,v 1.74 2014/10/05 23:21:09 tom Exp */ 3/* Id: output.c,v 1.74 2014/10/05 23:21:09 tom Exp */
4 4
5#include "defs.h" 5#include "defs.h"
6 6
7#include <sys/cdefs.h> 7#include <sys/cdefs.h>
8__RCSID("$NetBSD: output.c,v 1.15 2016/01/09 22:05:33 christos Exp $"); 8__RCSID("$NetBSD: output.c,v 1.16 2017/01/24 22:28:42 christos Exp $");
9 9
10#define StaticOrR (rflag ? "" : "static ") 10#define StaticOrR (rflag ? "" : "static ")
11#define CountLine(fp) (!rflag || ((fp) == code_file)) 11#define CountLine(fp) (!rflag || ((fp) == code_file))
12 12
13#if defined(YYBTYACC) 13#if defined(YYBTYACC)
14#define PER_STATE 3 14#define PER_STATE 3
15#else 15#else
16#define PER_STATE 2 16#define PER_STATE 2
17#endif 17#endif
18 18
19static int nvectors; 19static int nvectors;
20static int nentries; 20static int nentries;
21static Value_t **froms; 21static Value_t **froms;
22static Value_t **tos; 22static Value_t **tos;
23#if defined(YYBTYACC) 23#if defined(YYBTYACC)
24static Value_t *conflicts = NULL; 24static Value_t *conflicts = NULL;
25static Value_t nconflicts = 0; 25static Value_t nconflicts = 0;
26#endif 26#endif
27static Value_t *tally; 27static Value_t *tally;
28static Value_t *width; 28static Value_t *width;
29static Value_t *state_count; 29static Value_t *state_count;
30static Value_t *order; 30static Value_t *order;
31static Value_t *base; 31static Value_t *base;
32static Value_t *pos; 32static Value_t *pos;
33static int maxtable; 33static int maxtable;
34static Value_t *table; 34static Value_t *table;
35static Value_t *check; 35static Value_t *check;
36static int lowzero; 36static int lowzero;
37static long high; 37static long high;
38 38
39static void 39static void
40putc_code(FILE * fp, int c) 40putc_code(FILE * fp, int c)
41{ 41{
42 if ((c == '\n') && (fp == code_file)) 42 if ((c == '\n') && (fp == code_file))
43 ++outline; 43 ++outline;
44 putc(c, fp); 44 putc(c, fp);
45} 45}
46 46
47static void 47static void
48putl_code(FILE * fp, const char *s) 48putl_code(FILE * fp, const char *s)
49{ 49{
50 if (fp == code_file) 50 if (fp == code_file)
51 ++outline; 51 ++outline;
52 fputs(s, fp); 52 fputs(s, fp);
53} 53}
54 54
55static void 55static void
56puts_code(FILE * fp, const char *s) 56puts_code(FILE * fp, const char *s)
57{ 57{
58 fputs(s, fp); 58 fputs(s, fp);
59} 59}
60 60
61static void 61static void
62puts_param_types(FILE * fp, param * list, int more) 62puts_param_types(FILE * fp, param * list, int more)
63{ 63{
64 param *p; 64 param *p;
65 65
66 if (list != 0) 66 if (list != 0)
67 { 67 {
68 for (p = list; p; p = p->next) 68 for (p = list; p; p = p->next)
69 { 69 {
70 size_t len_type = strlen(p->type); 70 size_t len_type = strlen(p->type);
71 fprintf(fp, "%s%s%s%s%s", p->type, 71 fprintf(fp, "%s%s%s%s%s", p->type,
72 (((len_type != 0) && (p->type[len_type - 1] == '*')) 72 (((len_type != 0) && (p->type[len_type - 1] == '*'))
73 ? "" 73 ? ""
74 : " "), 74 : " "),
75 p->name, p->type2, 75 p->name, p->type2,
76 ((more || p->next) ? ", " : "")); 76 ((more || p->next) ? ", " : ""));
77 } 77 }
78 } 78 }
79 else 79 else
80 { 80 {
81 if (!more) 81 if (!more)
82 fprintf(fp, "void"); 82 fprintf(fp, "void");
83 } 83 }
84} 84}
85 85
86static void 86static void
87puts_param_names(FILE * fp, param * list, int more) 87puts_param_names(FILE * fp, param * list, int more)
88{ 88{
89 param *p; 89 param *p;
90 90
91 for (p = list; p; p = p->next) 91 for (p = list; p; p = p->next)
92 { 92 {
93 fprintf(fp, "%s%s", p->name, 93 fprintf(fp, "%s%s", p->name,
94 ((more || p->next) ? ", " : "")); 94 ((more || p->next) ? ", " : ""));
95 } 95 }
96} 96}
97 97
98static void 98static void
99write_code_lineno(FILE * fp) 99write_code_lineno(FILE * fp)
100{ 100{
101 if (!lflag && (fp == code_file)) 101 if (!lflag && (fp == code_file))
102 { 102 {
103 ++outline; 103 ++outline;
104 fprintf(fp, line_format, outline + 1, code_file_name); 104 fprintf(fp, line_format, outline + 1, code_file_name);
105 } 105 }
106} 106}
107 107
108static void 108static void
109write_input_lineno(void) 109write_input_lineno(void)
110{ 110{
111 if (!lflag) 111 if (!lflag)
112 { 112 {
113 ++outline; 113 ++outline;
114 fprintf(code_file, line_format, lineno, input_file_name); 114 fprintf(code_file, line_format, lineno, input_file_name);
115 } 115 }
116} 116}
117 117
118static void 118static void
119define_prefixed(FILE * fp, const char *name) 119define_prefixed(FILE * fp, const char *name)
120{ 120{
121 int bump_line = CountLine(fp); 121 int bump_line = CountLine(fp);
122 if (bump_line) 122 if (bump_line)
123 ++outline; 123 ++outline;
124 fprintf(fp, "\n"); 124 fprintf(fp, "\n");
125 125
126 if (bump_line) 126 if (bump_line)
127 ++outline; 127 ++outline;
128 fprintf(fp, "#ifndef %s\n", name); 128 fprintf(fp, "#ifndef %s\n", name);
129 129
130 if (bump_line) 130 if (bump_line)
131 ++outline; 131 ++outline;
132 fprintf(fp, "#define %-10s %s%s\n", name, symbol_prefix, name + 2); 132 fprintf(fp, "#define %-10s %s%s\n", name, symbol_prefix, name + 2);
133 133
134 if (bump_line) 134 if (bump_line)
135 ++outline; 135 ++outline;
136 fprintf(fp, "#endif /* %s */\n", name); 136 fprintf(fp, "#endif /* %s */\n", name);
137} 137}
138 138
139static void 139static void
140output_prefix(FILE * fp) 140output_prefix(FILE * fp)
141{ 141{
142 if (symbol_prefix == NULL) 142 if (symbol_prefix == NULL)
143 { 143 {
144 symbol_prefix = "yy"; 144 symbol_prefix = "yy";
145 } 145 }
146 else 146 else
147 { 147 {
148 define_prefixed(fp, "yyparse"); 148 define_prefixed(fp, "yyparse");
149 define_prefixed(fp, "yylex"); 149 define_prefixed(fp, "yylex");
150 define_prefixed(fp, "yyerror"); 150 define_prefixed(fp, "yyerror");
151 define_prefixed(fp, "yychar"); 151 define_prefixed(fp, "yychar");
152 define_prefixed(fp, "yyval"); 152 define_prefixed(fp, "yyval");
153 define_prefixed(fp, "yylval"); 153 define_prefixed(fp, "yylval");
154 define_prefixed(fp, "yydebug"); 154 define_prefixed(fp, "yydebug");
155 define_prefixed(fp, "yynerrs"); 155 define_prefixed(fp, "yynerrs");
156 define_prefixed(fp, "yyerrflag"); 156 define_prefixed(fp, "yyerrflag");
157 define_prefixed(fp, "yylhs"); 157 define_prefixed(fp, "yylhs");
158 define_prefixed(fp, "yylen"); 158 define_prefixed(fp, "yylen");
159 define_prefixed(fp, "yydefred"); 159 define_prefixed(fp, "yydefred");
160#if defined(YYBTYACC) 160#if defined(YYBTYACC)
161 define_prefixed(fp, "yystos"); 161 define_prefixed(fp, "yystos");
162#endif 162#endif
163 define_prefixed(fp, "yydgoto"); 163 define_prefixed(fp, "yydgoto");
164 define_prefixed(fp, "yysindex"); 164 define_prefixed(fp, "yysindex");
165 define_prefixed(fp, "yyrindex"); 165 define_prefixed(fp, "yyrindex");
166 define_prefixed(fp, "yygindex"); 166 define_prefixed(fp, "yygindex");
167 define_prefixed(fp, "yytable"); 167 define_prefixed(fp, "yytable");
168 define_prefixed(fp, "yycheck"); 168 define_prefixed(fp, "yycheck");
169 define_prefixed(fp, "yyname"); 169 define_prefixed(fp, "yyname");
170 define_prefixed(fp, "yyrule"); 170 define_prefixed(fp, "yyrule");
171#if defined(YYBTYACC) 171#if defined(YYBTYACC)
172 if (locations) 172 if (locations)
173 { 173 {
174 define_prefixed(fp, "yyloc"); 174 define_prefixed(fp, "yyloc");
175 define_prefixed(fp, "yylloc"); 175 define_prefixed(fp, "yylloc");
176 } 176 }
177 putc_code(fp, '\n'); 177 putc_code(fp, '\n');
178 putl_code(fp, "#if YYBTYACC\n"); 178 putl_code(fp, "#if YYBTYACC\n");
179 179
180 define_prefixed(fp, "yycindex"); 180 define_prefixed(fp, "yycindex");
181 define_prefixed(fp, "yyctable"); 181 define_prefixed(fp, "yyctable");
182 182
183 putc_code(fp, '\n'); 183 putc_code(fp, '\n');
184 putl_code(fp, "#endif /* YYBTYACC */\n"); 184 putl_code(fp, "#endif /* YYBTYACC */\n");
185 putc_code(fp, '\n'); 185 putc_code(fp, '\n');
186#endif 186#endif
187 } 187 }
188 if (CountLine(fp)) 188 if (CountLine(fp))
189 ++outline; 189 ++outline;
190 fprintf(fp, "#define YYPREFIX \"%s\"\n", symbol_prefix); 190 fprintf(fp, "#define YYPREFIX \"%s\"\n", symbol_prefix);
191} 191}
192 192
193static void 193static void
194output_newline(void) 194output_newline(void)
195{ 195{
196 if (!rflag) 196 if (!rflag)
197 ++outline; 197 ++outline;
198 putc('\n', output_file); 198 putc('\n', output_file);
199} 199}
200 200
201static void 201static void
202output_line(const char *value) 202output_line(const char *value)
203{ 203{
204 fputs(value, output_file); 204 fputs(value, output_file);
205 output_newline(); 205 output_newline();
206} 206}
207 207
208static void 208static void
209output_int(int value) 209output_int(int value)
210{ 210{
211 fprintf(output_file, "%5d,", value); 211 fprintf(output_file, "%5d,", value);
212} 212}
213 213
214static void 214static void
215start_int_table(const char *name, int value) 215start_int_table(const char *name, int value)
216{ 216{
217 int need = 34 - (int)(strlen(symbol_prefix) + strlen(name)); 217 int need = 34 - (int)(strlen(symbol_prefix) + strlen(name));
218 218
219 if (need < 6) 219 if (need < 6)
220 need = 6; 220 need = 6;
221 fprintf(output_file, 221 fprintf(output_file,
222 "%sconst YYINT %s%s[] = {%*d,", 222 "%sconst YYINT %s%s[] = {%*d,",
223 StaticOrR, symbol_prefix, name, need, value); 223 StaticOrR, symbol_prefix, name, need, value);
224} 224}
225 225
226static void 226static void
227start_str_table(const char *name) 227start_str_table(const char *name)
228{ 228{
229 fprintf(output_file, 229 fprintf(output_file,
230 "%sconst char *const %s%s[] = {", 230 "%sconst char *const %s%s[] = {",
231 StaticOrR, symbol_prefix, name); 231 StaticOrR, symbol_prefix, name);
232 output_newline(); 232 output_newline();
233} 233}
234 234
235static void 235static void
236end_table(void) 236end_table(void)
237{ 237{
238 output_newline(); 238 output_newline();
239 output_line("};"); 239 output_line("};");
240} 240}
241 241
242static void 242static void
243output_YYINT_typedef(FILE * fp) 243output_YYINT_typedef(FILE * fp)
244{ 244{
245 /* generate the type used to index the various parser tables */ 245 /* generate the type used to index the various parser tables */
246 if (CountLine(fp)) 246 if (CountLine(fp))
247 ++outline; 247 ++outline;
248 fprintf(fp, "typedef %s YYINT;\n", CONCAT1("", YYINT)); 248 fprintf(fp, "typedef %s YYINT;\n", CONCAT1("", YYINT));
249} 249}
250 250
251static void 251static void
252output_rule_data(void) 252output_rule_data(void)
253{ 253{
254 int i; 254 int i;
255 int j; 255 int j;
256 256
257 output_YYINT_typedef(output_file); 257 output_YYINT_typedef(output_file);
258 258
259 start_int_table("lhs", symbol_value[start_symbol]); 259 start_int_table("lhs", symbol_value[start_symbol]);
260 260
261 j = 10; 261 j = 10;
262 for (i = 3; i < nrules; i++) 262 for (i = 3; i < nrules; i++)
263 { 263 {
264 if (j >= 10) 264 if (j >= 10)
265 { 265 {
266 output_newline(); 266 output_newline();
267 j = 1; 267 j = 1;
268 } 268 }
269 else 269 else
270 ++j; 270 ++j;
271 271
272 output_int(symbol_value[rlhs[i]]); 272 output_int(symbol_value[rlhs[i]]);
273 } 273 }
274 end_table(); 274 end_table();
275 275
276 start_int_table("len", 2); 276 start_int_table("len", 2);
277 277
278 j = 10; 278 j = 10;
279 for (i = 3; i < nrules; i++) 279 for (i = 3; i < nrules; i++)
280 { 280 {
281 if (j >= 10) 281 if (j >= 10)
282 { 282 {
283 output_newline(); 283 output_newline();
284 j = 1; 284 j = 1;
285 } 285 }
286 else 286 else
287 j++; 287 j++;
288 288
289 output_int(rrhs[i + 1] - rrhs[i] - 1); 289 output_int(rrhs[i + 1] - rrhs[i] - 1);
290 } 290 }
291 end_table(); 291 end_table();
292} 292}
293 293
294static void 294static void
295output_yydefred(void) 295output_yydefred(void)
296{ 296{
297 int i, j; 297 int i, j;
298 298
299 start_int_table("defred", (defred[0] ? defred[0] - 2 : 0)); 299 start_int_table("defred", (defred[0] ? defred[0] - 2 : 0));
300 300
301 j = 10; 301 j = 10;
302 for (i = 1; i < nstates; i++) 302 for (i = 1; i < nstates; i++)
303 { 303 {
304 if (j < 10) 304 if (j < 10)
305 ++j; 305 ++j;
306 else 306 else
307 { 307 {
308 output_newline(); 308 output_newline();
309 j = 1; 309 j = 1;
310 } 310 }
311 311
312 output_int((defred[i] ? defred[i] - 2 : 0)); 312 output_int((defred[i] ? defred[i] - 2 : 0));
313 } 313 }
314 314
315 end_table(); 315 end_table();
316} 316}
317 317
318#if defined(YYBTYACC) 318#if defined(YYBTYACC)
319static void 319static void
320output_accessing_symbols(void) 320output_accessing_symbols(void)
321{ 321{
322 int i, j; 322 int i, j;
323 int *translate; 323 int *translate;
324 324
325 if (nstates != 0) 325 if (nstates != 0)
326 { 326 {
327 translate = TMALLOC(int, nstates); 327 translate = TMALLOC(int, nstates);
328 NO_SPACE(translate); 328 NO_SPACE(translate);
329 329
330 for (i = 0; i < nstates; ++i) 330 for (i = 0; i < nstates; ++i)
331 { 331 {
332 int gsymb = accessing_symbol[i]; 332 int gsymb = accessing_symbol[i];
333 333
334 translate[i] = symbol_pval[gsymb]; 334 translate[i] = symbol_pval[gsymb];
335 } 335 }
336 336
337 putl_code(output_file, 337 putl_code(output_file,
338 "#if defined(YYDESTRUCT_CALL) || defined(YYSTYPE_TOSTRING)\n"); 338 "#if defined(YYDESTRUCT_CALL) || defined(YYSTYPE_TOSTRING)\n");
339 /* yystos[] may be unused, depending on compile-time defines */ 339 /* yystos[] may be unused, depending on compile-time defines */
340 start_int_table("stos", translate[0]); 340 start_int_table("stos", translate[0]);
341 341
342 j = 10; 342 j = 10;
343 for (i = 1; i < nstates; ++i) 343 for (i = 1; i < nstates; ++i)
344 { 344 {
345 if (j < 10) 345 if (j < 10)
346 ++j; 346 ++j;
347 else 347 else
348 { 348 {
349 output_newline(); 349 output_newline();
350 j = 1; 350 j = 1;
351 } 351 }
352 352
353 output_int(translate[i]); 353 output_int(translate[i]);
354 } 354 }
355 355
356 end_table(); 356 end_table();
357 FREE(translate); 357 FREE(translate);
358 putl_code(output_file, 358 putl_code(output_file,
359 "#endif /* YYDESTRUCT_CALL || YYSTYPE_TOSTRING */\n"); 359 "#endif /* YYDESTRUCT_CALL || YYSTYPE_TOSTRING */\n");
360 } 360 }
361} 361}
362 362
363static Value_t 363static Value_t
364find_conflict_base(int cbase) 364find_conflict_base(int cbase)
365{ 365{
366 int i, j; 366 int i, j;
367 367
368 for (i = 0; i < cbase; i++) 368 for (i = 0; i < cbase; i++)
369 { 369 {
370 for (j = 0; j + cbase < nconflicts; j++) 370 for (j = 0; j + cbase < nconflicts; j++)
371 { 371 {
372 if (conflicts[i + j] != conflicts[cbase + j]) 372 if (conflicts[i + j] != conflicts[cbase + j])
373 break; 373 break;
374 } 374 }
375 if (j + cbase >= nconflicts) 375 if (j + cbase >= nconflicts)
376 break; 376 break;
377 } 377 }
378 return (Value_t) i; 378 return (Value_t) i;
379} 379}
380#endif 380#endif
381 381
382static void 382static void
383token_actions(void) 383token_actions(void)
384{ 384{
385 int i, j; 385 int i, j;
386 Value_t shiftcount, reducecount; 386 Value_t shiftcount, reducecount;
387#if defined(YYBTYACC) 387#if defined(YYBTYACC)
388 Value_t conflictcount = 0; 388 Value_t conflictcount = 0;
389 Value_t csym = -1; 389 Value_t csym = -1;
390 Value_t cbase = 0; 390 Value_t cbase = 0;
391#endif 391#endif
392 int max, min; 392 int max, min;
393 Value_t *actionrow, *r, *s; 393 Value_t *actionrow, *r, *s;
394 action *p; 394 action *p;
395 395
396 actionrow = NEW2(PER_STATE * ntokens, Value_t); 396 actionrow = NEW2(PER_STATE * ntokens, Value_t);
397 for (i = 0; i < nstates; ++i) 397 for (i = 0; i < nstates; ++i)
398 { 398 {
399 if (parser[i]) 399 if (parser[i])
400 { 400 {
401 for (j = 0; j < PER_STATE * ntokens; ++j) 401 for (j = 0; j < PER_STATE * ntokens; ++j)
402 actionrow[j] = 0; 402 actionrow[j] = 0;
403 403
404 shiftcount = 0; 404 shiftcount = 0;
405 reducecount = 0; 405 reducecount = 0;
406#if defined(YYBTYACC) 406#if defined(YYBTYACC)
407 if (backtrack) 407 if (backtrack)
408 { 408 {
409 conflictcount = 0; 409 conflictcount = 0;
410 csym = -1; 410 csym = -1;
411 cbase = nconflicts; 411 cbase = nconflicts;
412 } 412 }
413#endif 413#endif
414 for (p = parser[i]; p; p = p->next) 414 for (p = parser[i]; p; p = p->next)
415 { 415 {
416#if defined(YYBTYACC) 416#if defined(YYBTYACC)
417 if (backtrack) 417 if (backtrack)
418 { 418 {
419 if (csym != -1 && csym != p->symbol) 419 if (csym != -1 && csym != p->symbol)
420 { 420 {
421 conflictcount++; 421 conflictcount++;
422 conflicts[nconflicts++] = -1; 422 conflicts[nconflicts++] = -1;
423 j = find_conflict_base(cbase); 423 j = find_conflict_base(cbase);
424 actionrow[csym + 2 * ntokens] = (Value_t) (j + 1); 424 actionrow[csym + 2 * ntokens] = (Value_t) (j + 1);
425 if (j == cbase) 425 if (j == cbase)
426 { 426 {
427 cbase = nconflicts; 427 cbase = nconflicts;
428 } 428 }
429 else 429 else
430 { 430 {
431 if (conflicts[cbase] == -1) 431 if (conflicts[cbase] == -1)
432 cbase++; 432 cbase++;
433 nconflicts = cbase; 433 nconflicts = cbase;
434 } 434 }
435 csym = -1; 435 csym = -1;
436 } 436 }
437 } 437 }
438#endif 438#endif
439 if (p->suppressed == 0) 439 if (p->suppressed == 0)
440 { 440 {
441 if (p->action_code == SHIFT) 441 if (p->action_code == SHIFT)
442 { 442 {
443 ++shiftcount; 443 ++shiftcount;
444 actionrow[p->symbol] = p->number; 444 actionrow[p->symbol] = p->number;
445 } 445 }
446 else if (p->action_code == REDUCE && p->number != defred[i]) 446 else if (p->action_code == REDUCE && p->number != defred[i])
447 { 447 {
448 ++reducecount; 448 ++reducecount;
449 actionrow[p->symbol + ntokens] = p->number; 449 actionrow[p->symbol + ntokens] = p->number;
450 } 450 }
451 } 451 }
452#if defined(YYBTYACC) 452#if defined(YYBTYACC)
453 else if (backtrack && p->suppressed == 1) 453 else if (backtrack && p->suppressed == 1)
454 { 454 {
455 csym = p->symbol; 455 csym = p->symbol;
456 if (p->action_code == SHIFT) 456 if (p->action_code == SHIFT)
457 { 457 {
458 conflicts[nconflicts++] = p->number; 458 conflicts[nconflicts++] = p->number;
459 } 459 }
460 else if (p->action_code == REDUCE && p->number != defred[i]) 460 else if (p->action_code == REDUCE && p->number != defred[i])
461 { 461 {
462 if (cbase == nconflicts) 462 if (cbase == nconflicts)
463 { 463 {
464 if (cbase) 464 if (cbase)
465 cbase--; 465 cbase--;
466 else 466 else
467 conflicts[nconflicts++] = -1; 467 conflicts[nconflicts++] = -1;
468 } 468 }
469 conflicts[nconflicts++] = (Value_t) (p->number - 2); 469 conflicts[nconflicts++] = (Value_t) (p->number - 2);
470 } 470 }
471 } 471 }
472#endif 472#endif
473 } 473 }
474#if defined(YYBTYACC) 474#if defined(YYBTYACC)
475 if (backtrack && csym != -1) 475 if (backtrack && csym != -1)
476 { 476 {
477 conflictcount++; 477 conflictcount++;
478 conflicts[nconflicts++] = -1; 478 conflicts[nconflicts++] = -1;
479 j = find_conflict_base(cbase); 479 j = find_conflict_base(cbase);
480 actionrow[csym + 2 * ntokens] = (Value_t) (j + 1); 480 actionrow[csym + 2 * ntokens] = (Value_t) (j + 1);
481 if (j == cbase) 481 if (j == cbase)
482 { 482 {
483 cbase = nconflicts; 483 cbase = nconflicts;
484 } 484 }
485 else 485 else
486 { 486 {
487 if (conflicts[cbase] == -1) 487 if (conflicts[cbase] == -1)
488 cbase++; 488 cbase++;
489 nconflicts = cbase; 489 nconflicts = cbase;
490 } 490 }
491 } 491 }
492#endif 492#endif
493 493
494 tally[i] = shiftcount; 494 tally[i] = shiftcount;
495 tally[nstates + i] = reducecount; 495 tally[nstates + i] = reducecount;
496#if defined(YYBTYACC) 496#if defined(YYBTYACC)
497 if (backtrack) 497 if (backtrack)
498 tally[2 * nstates + i] = conflictcount; 498 tally[2 * nstates + i] = conflictcount;
499#endif 499#endif
500 width[i] = 0; 500 width[i] = 0;
501 width[nstates + i] = 0; 501 width[nstates + i] = 0;
502#if defined(YYBTYACC) 502#if defined(YYBTYACC)
503 if (backtrack) 503 if (backtrack)
504 width[2 * nstates + i] = 0; 504 width[2 * nstates + i] = 0;
505#endif 505#endif
506 if (shiftcount > 0) 506 if (shiftcount > 0)
507 { 507 {
508 froms[i] = r = NEW2(shiftcount, Value_t); 508 froms[i] = r = NEW2(shiftcount, Value_t);
509 tos[i] = s = NEW2(shiftcount, Value_t); 509 tos[i] = s = NEW2(shiftcount, Value_t);
510 min = MAXYYINT; 510 min = MAXYYINT;
511 max = 0; 511 max = 0;
512 for (j = 0; j < ntokens; ++j) 512 for (j = 0; j < ntokens; ++j)
513 { 513 {
514 if (actionrow[j]) 514 if (actionrow[j])
515 { 515 {
516 if (min > symbol_value[j]) 516 if (min > symbol_value[j])
517 min = symbol_value[j]; 517 min = symbol_value[j];
518 if (max < symbol_value[j]) 518 if (max < symbol_value[j])
519 max = symbol_value[j]; 519 max = symbol_value[j];
520 *r++ = symbol_value[j]; 520 *r++ = symbol_value[j];
521 *s++ = actionrow[j]; 521 *s++ = actionrow[j];
522 } 522 }
523 } 523 }
524 width[i] = (Value_t) (max - min + 1); 524 width[i] = (Value_t) (max - min + 1);
525 } 525 }
526 if (reducecount > 0) 526 if (reducecount > 0)
527 { 527 {
528 froms[nstates + i] = r = NEW2(reducecount, Value_t); 528 froms[nstates + i] = r = NEW2(reducecount, Value_t);
529 tos[nstates + i] = s = NEW2(reducecount, Value_t); 529 tos[nstates + i] = s = NEW2(reducecount, Value_t);
530 min = MAXYYINT; 530 min = MAXYYINT;
531 max = 0; 531 max = 0;
532 for (j = 0; j < ntokens; ++j) 532 for (j = 0; j < ntokens; ++j)
533 { 533 {
534 if (actionrow[ntokens + j]) 534 if (actionrow[ntokens + j])
535 { 535 {
536 if (min > symbol_value[j]) 536 if (min > symbol_value[j])
537 min = symbol_value[j]; 537 min = symbol_value[j];
538 if (max < symbol_value[j]) 538 if (max < symbol_value[j])
539 max = symbol_value[j]; 539 max = symbol_value[j];
540 *r++ = symbol_value[j]; 540 *r++ = symbol_value[j];
541 *s++ = (Value_t) (actionrow[ntokens + j] - 2); 541 *s++ = (Value_t) (actionrow[ntokens + j] - 2);
542 } 542 }
543 } 543 }
544 width[nstates + i] = (Value_t) (max - min + 1); 544 width[nstates + i] = (Value_t) (max - min + 1);
545 } 545 }
546#if defined(YYBTYACC) 546#if defined(YYBTYACC)
547 if (backtrack && conflictcount > 0) 547 if (backtrack && conflictcount > 0)
548 { 548 {
549 froms[2 * nstates + i] = r = NEW2(conflictcount, Value_t); 549 froms[2 * nstates + i] = r = NEW2(conflictcount, Value_t);
550 tos[2 * nstates + i] = s = NEW2(conflictcount, Value_t); 550 tos[2 * nstates + i] = s = NEW2(conflictcount, Value_t);
551 min = MAXYYINT; 551 min = MAXYYINT;
552 max = 0; 552 max = 0;
553 for (j = 0; j < ntokens; ++j) 553 for (j = 0; j < ntokens; ++j)
554 { 554 {
555 if (actionrow[2 * ntokens + j]) 555 if (actionrow[2 * ntokens + j])
556 { 556 {
557 if (min > symbol_value[j]) 557 if (min > symbol_value[j])
558 min = symbol_value[j]; 558 min = symbol_value[j];
559 if (max < symbol_value[j]) 559 if (max < symbol_value[j])
560 max = symbol_value[j]; 560 max = symbol_value[j];
561 *r++ = symbol_value[j]; 561 *r++ = symbol_value[j];
562 *s++ = (Value_t) (actionrow[2 * ntokens + j] - 1); 562 *s++ = (Value_t) (actionrow[2 * ntokens + j] - 1);
563 } 563 }
564 } 564 }
565 width[2 * nstates + i] = (Value_t) (max - min + 1); 565 width[2 * nstates + i] = (Value_t) (max - min + 1);
566 } 566 }
567#endif 567#endif
568 } 568 }
569 } 569 }
570 FREE(actionrow); 570 FREE(actionrow);
571} 571}
572 572
573static int 573static int
574default_goto(int symbol) 574default_goto(int symbol)
575{ 575{
576 int i; 576 int i;
577 int m; 577 int m;
578 int n; 578 int n;
579 int default_state; 579 int default_state;
580 int max; 580 int max;
581 581
582 m = goto_map[symbol]; 582 m = goto_map[symbol];
583 n = goto_map[symbol + 1]; 583 n = goto_map[symbol + 1];
584 584
585 if (m == n) 585 if (m == n)
586 return (0); 586 return (0);
587 587
588 for (i = 0; i < nstates; i++) 588 for (i = 0; i < nstates; i++)
589 state_count[i] = 0; 589 state_count[i] = 0;
590 590
591 for (i = m; i < n; i++) 591 for (i = m; i < n; i++)
592 state_count[to_state[i]]++; 592 state_count[to_state[i]]++;
593 593
594 max = 0; 594 max = 0;
595 default_state = 0; 595 default_state = 0;
596 for (i = 0; i < nstates; i++) 596 for (i = 0; i < nstates; i++)
597 { 597 {
598 if (state_count[i] > max) 598 if (state_count[i] > max)
599 { 599 {
600 max = state_count[i]; 600 max = state_count[i];
601 default_state = i; 601 default_state = i;
602 } 602 }
603 } 603 }
604 604
605 return (default_state); 605 return (default_state);
606} 606}
607 607
608static void 608static void
609save_column(int symbol, int default_state) 609save_column(int symbol, int default_state)
610{ 610{
611 int i; 611 int i;
612 int m; 612 int m;
613 int n; 613 int n;
614 Value_t *sp; 614 Value_t *sp;
615 Value_t *sp1; 615 Value_t *sp1;
616 Value_t *sp2; 616 Value_t *sp2;
617 Value_t count; 617 Value_t count;
618 int symno; 618 int symno;
619 619
620 m = goto_map[symbol]; 620 m = goto_map[symbol];
621 n = goto_map[symbol + 1]; 621 n = goto_map[symbol + 1];
622 622
623 count = 0; 623 count = 0;
624 for (i = m; i < n; i++) 624 for (i = m; i < n; i++)
625 { 625 {
626 if (to_state[i] != default_state) 626 if (to_state[i] != default_state)
627 ++count; 627 ++count;
628 } 628 }
629 if (count == 0) 629 if (count == 0)
630 return; 630 return;
631 631
632 symno = symbol_value[symbol] + PER_STATE * nstates; 632 symno = symbol_value[symbol] + PER_STATE * nstates;
633 633
634 froms[symno] = sp1 = sp = NEW2(count, Value_t); 634 froms[symno] = sp1 = sp = NEW2(count, Value_t);
635 tos[symno] = sp2 = NEW2(count, Value_t); 635 tos[symno] = sp2 = NEW2(count, Value_t);
636 636
637 for (i = m; i < n; i++) 637 for (i = m; i < n; i++)
638 { 638 {
639 if (to_state[i] != default_state) 639 if (to_state[i] != default_state)
640 { 640 {
641 *sp1++ = from_state[i]; 641 *sp1++ = from_state[i];
642 *sp2++ = to_state[i]; 642 *sp2++ = to_state[i];
643 } 643 }
644 } 644 }
645 645
646 tally[symno] = count; 646 tally[symno] = count;
647 width[symno] = (Value_t) (sp1[-1] - sp[0] + 1); 647 width[symno] = (Value_t) (sp1[-1] - sp[0] + 1);
648} 648}
649 649
650static void 650static void
651goto_actions(void) 651goto_actions(void)
652{ 652{
653 int i, j, k; 653 int i, j, k;
654 654
655 state_count = NEW2(nstates, Value_t); 655 state_count = NEW2(nstates, Value_t);
656 656
657 k = default_goto(start_symbol + 1); 657 k = default_goto(start_symbol + 1);
658 start_int_table("dgoto", k); 658 start_int_table("dgoto", k);
659 save_column(start_symbol + 1, k); 659 save_column(start_symbol + 1, k);
660 660
661 j = 10; 661 j = 10;
662 for (i = start_symbol + 2; i < nsyms; i++) 662 for (i = start_symbol + 2; i < nsyms; i++)
663 { 663 {
664 if (j >= 10) 664 if (j >= 10)
665 { 665 {
666 output_newline(); 666 output_newline();
667 j = 1; 667 j = 1;
668 } 668 }
669 else 669 else
670 ++j; 670 ++j;
671 671
672 k = default_goto(i); 672 k = default_goto(i);
673 output_int(k); 673 output_int(k);
674 save_column(i, k); 674 save_column(i, k);
675 } 675 }
676 676
677 end_table(); 677 end_table();
678 FREE(state_count); 678 FREE(state_count);
679} 679}
680 680
681static void 681static void
682sort_actions(void) 682sort_actions(void)
683{ 683{
684 Value_t i; 684 Value_t i;
685 int j; 685 int j;
686 int k; 686 int k;
687 int t; 687 int t;
688 int w; 688 int w;
689 689
690 order = NEW2(nvectors, Value_t); 690 order = NEW2(nvectors, Value_t);
691 nentries = 0; 691 nentries = 0;
692 692
693 for (i = 0; i < nvectors; i++) 693 for (i = 0; i < nvectors; i++)
694 { 694 {
695 if (tally[i] > 0) 695 if (tally[i] > 0)
696 { 696 {
697 t = tally[i]; 697 t = tally[i];
698 w = width[i]; 698 w = width[i];
699 j = nentries - 1; 699 j = nentries - 1;
700 700
701 while (j >= 0 && (width[order[j]] < w)) 701 while (j >= 0 && (width[order[j]] < w))
702 j--; 702 j--;
703 703
704 while (j >= 0 && (width[order[j]] == w) && (tally[order[j]] < t)) 704 while (j >= 0 && (width[order[j]] == w) && (tally[order[j]] < t))
705 j--; 705 j--;
706 706
707 for (k = nentries - 1; k > j; k--) 707 for (k = nentries - 1; k > j; k--)
708 order[k + 1] = order[k]; 708 order[k + 1] = order[k];
709 709
710 order[j + 1] = i; 710 order[j + 1] = i;
711 nentries++; 711 nentries++;
712 } 712 }
713 } 713 }
714} 714}
715 715
716/* The function matching_vector determines if the vector specified by */ 716/* The function matching_vector determines if the vector specified by */
717/* the input parameter matches a previously considered vector. The */ 717/* the input parameter matches a previously considered vector. The */
718/* test at the start of the function checks if the vector represents */ 718/* test at the start of the function checks if the vector represents */
719/* a row of shifts over terminal symbols or a row of reductions, or a */ 719/* a row of shifts over terminal symbols or a row of reductions, or a */
720/* column of shifts over a nonterminal symbol. Berkeley Yacc does not */ 720/* column of shifts over a nonterminal symbol. Berkeley Yacc does not */
721/* check if a column of shifts over a nonterminal symbols matches a */ 721/* check if a column of shifts over a nonterminal symbols matches a */
722/* previously considered vector. Because of the nature of LR parsing */ 722/* previously considered vector. Because of the nature of LR parsing */
723/* tables, no two columns can match. Therefore, the only possible */ 723/* tables, no two columns can match. Therefore, the only possible */
724/* match would be between a row and a column. Such matches are */ 724/* match would be between a row and a column. Such matches are */
725/* unlikely. Therefore, to save time, no attempt is made to see if a */ 725/* unlikely. Therefore, to save time, no attempt is made to see if a */
726/* column matches a previously considered vector. */ 726/* column matches a previously considered vector. */
727/* */ 727/* */
728/* Matching_vector is poorly designed. The test could easily be made */ 728/* Matching_vector is poorly designed. The test could easily be made */
729/* faster. Also, it depends on the vectors being in a specific */ 729/* faster. Also, it depends on the vectors being in a specific */
730/* order. */ 730/* order. */
731#if defined(YYBTYACC) 731#if defined(YYBTYACC)
732/* */ 732/* */
733/* Not really any point in checking for matching conflicts -- it is */ 733/* Not really any point in checking for matching conflicts -- it is */
734/* extremely unlikely to occur, and conflicts are (hopefully) rare. */ 734/* extremely unlikely to occur, and conflicts are (hopefully) rare. */
735#endif 735#endif
736 736
737static int 737static int
738matching_vector(int vector) 738matching_vector(int vector)
739{ 739{
740 int i; 740 int i;
741 int j; 741 int j;
742 int k; 742 int k;
743 int t; 743 int t;
744 int w; 744 int w;
745 int match; 745 int match;
746 int prev; 746 int prev;
747 747
748 i = order[vector]; 748 i = order[vector];
749 if (i >= 2 * nstates) 749 if (i >= 2 * nstates)
750 return (-1); 750 return (-1);
751 751
752 t = tally[i]; 752 t = tally[i];
753 w = width[i]; 753 w = width[i];
754 754
755 for (prev = vector - 1; prev >= 0; prev--) 755 for (prev = vector - 1; prev >= 0; prev--)
756 { 756 {
757 j = order[prev]; 757 j = order[prev];
758 if (width[j] != w || tally[j] != t) 758 if (width[j] != w || tally[j] != t)
759 return (-1); 759 return (-1);
760 760
761 match = 1; 761 match = 1;
762 for (k = 0; match && k < t; k++) 762 for (k = 0; match && k < t; k++)
763 { 763 {
764 if (tos[j][k] != tos[i][k] || froms[j][k] != froms[i][k]) 764 if (tos[j][k] != tos[i][k] || froms[j][k] != froms[i][k])
765 match = 0; 765 match = 0;
766 } 766 }
767 767
768 if (match) 768 if (match)
769 return (j); 769 return (j);
770 } 770 }
771 771
772 return (-1); 772 return (-1);
773} 773}
774 774
775static int 775static int
776pack_vector(int vector) 776pack_vector(int vector)
777{ 777{
778 int i, j, k, l; 778 int i, j, k, l;
779 int t; 779 int t;
780 int loc; 780 int loc;
781 int ok; 781 int ok;
782 Value_t *from; 782 Value_t *from;
783 Value_t *to; 783 Value_t *to;
784 int newmax; 784 int newmax;
785 785
786 i = order[vector]; 786 i = order[vector];
787 t = tally[i]; 787 t = tally[i];
788 assert(t); 788 assert(t);
789 789
790 from = froms[i]; 790 from = froms[i];
791 to = tos[i]; 791 to = tos[i];
792 792
793 j = lowzero - from[0]; 793 j = lowzero - from[0];
794 for (k = 1; k < t; ++k) 794 for (k = 1; k < t; ++k)
795 if (lowzero - from[k] > j) 795 if (lowzero - from[k] > j)
796 j = lowzero - from[k]; 796 j = lowzero - from[k];
797 for (;; ++j) 797 for (;; ++j)
798 { 798 {
799 if (j == 0) 799 if (j == 0)
800 continue; 800 continue;
801 ok = 1; 801 ok = 1;
802 for (k = 0; ok && k < t; k++) 802 for (k = 0; ok && k < t; k++)
803 { 803 {
804 loc = j + from[k]; 804 loc = j + from[k];
805 if (loc >= maxtable - 1) 805 if (loc >= maxtable - 1)
806 { 806 {
807 if (loc >= MAXTABLE - 1) 807 if (loc >= MAXTABLE - 1)
808 fatal("maximum table size exceeded"); 808 fatal("maximum table size exceeded");
809 809
810 newmax = maxtable; 810 newmax = maxtable;
811 do 811 do
812 { 812 {
813 newmax += 200; 813 newmax += 200;
814 } 814 }
815 while (newmax <= loc); 815 while (newmax <= loc);
816 816
817 table = TREALLOC(Value_t, table, newmax); 817 table = TREALLOC(Value_t, table, newmax);
818 NO_SPACE(table); 818 NO_SPACE(table);
819 819
820 check = TREALLOC(Value_t, check, newmax); 820 check = TREALLOC(Value_t, check, newmax);
821 NO_SPACE(check); 821 NO_SPACE(check);
822 822
823 for (l = maxtable; l < newmax; ++l) 823 for (l = maxtable; l < newmax; ++l)
824 { 824 {
825 table[l] = 0; 825 table[l] = 0;
826 check[l] = -1; 826 check[l] = -1;
827 } 827 }
828 maxtable = newmax; 828 maxtable = newmax;
829 } 829 }
830 830
831 if (check[loc] != -1) 831 if (check[loc] != -1)
832 ok = 0; 832 ok = 0;
833 } 833 }
834 for (k = 0; ok && k < vector; k++) 834 for (k = 0; ok && k < vector; k++)
835 { 835 {
836 if (pos[k] == j) 836 if (pos[k] == j)
837 ok = 0; 837 ok = 0;
838 } 838 }
839 if (ok) 839 if (ok)
840 { 840 {
841 for (k = 0; k < t; k++) 841 for (k = 0; k < t; k++)
842 { 842 {
843 loc = j + from[k]; 843 loc = j + from[k];
844 table[loc] = to[k]; 844 table[loc] = to[k];
845 check[loc] = from[k]; 845 check[loc] = from[k];
846 if (loc > high) 846 if (loc > high)
847 high = loc; 847 high = loc;
848 } 848 }
849 849
850 while (check[lowzero] != -1) 850 while (check[lowzero] != -1)
851 ++lowzero; 851 ++lowzero;
852 852
853 return (j); 853 return (j);
854 } 854 }
855 } 855 }
856} 856}
857 857
858static void 858static void
859pack_table(void) 859pack_table(void)
860{ 860{
861 int i; 861 int i;
862 Value_t place; 862 Value_t place;
863 int state; 863 int state;
864 864
865 base = NEW2(nvectors, Value_t); 865 base = NEW2(nvectors, Value_t);
866 pos = NEW2(nentries, Value_t); 866 pos = NEW2(nentries, Value_t);
867 867
868 maxtable = 1000; 868 maxtable = 1000;
869 table = NEW2(maxtable, Value_t); 869 table = NEW2(maxtable, Value_t);
870 check = NEW2(maxtable, Value_t); 870 check = NEW2(maxtable, Value_t);
871 871
872 lowzero = 0; 872 lowzero = 0;
873 high = 0; 873 high = 0;
874 874
875 for (i = 0; i < maxtable; i++) 875 for (i = 0; i < maxtable; i++)
876 check[i] = -1; 876 check[i] = -1;
877 877
878 for (i = 0; i < nentries; i++) 878 for (i = 0; i < nentries; i++)
879 { 879 {
880 state = matching_vector(i); 880 state = matching_vector(i);
881 881
882 if (state < 0) 882 if (state < 0)
883 place = (Value_t) pack_vector(i); 883 place = (Value_t) pack_vector(i);
884 else 884 else
885 place = base[state]; 885 place = base[state];
886 886
887 pos[i] = place; 887 pos[i] = place;
888 base[order[i]] = place; 888 base[order[i]] = place;
889 } 889 }
890 890
891 for (i = 0; i < nvectors; i++) 891 for (i = 0; i < nvectors; i++)
892 { 892 {
893 if (froms[i]) 893 if (froms[i])
894 FREE(froms[i]); 894 FREE(froms[i]);
895 if (tos[i]) 895 if (tos[i])
896 FREE(tos[i]); 896 FREE(tos[i]);
897 } 897 }
898 898
899 DO_FREE(froms); 899 DO_FREE(froms);
900 DO_FREE(tos); 900 DO_FREE(tos);
901 DO_FREE(tally); 901 DO_FREE(tally);
902 DO_FREE(width); 902 DO_FREE(width);
903 DO_FREE(pos); 903 DO_FREE(pos);
904} 904}
905 905
906static void 906static void
907output_base(void) 907output_base(void)
908{ 908{
909 int i, j; 909 int i, j;
910 910
911 start_int_table("sindex", base[0]); 911 start_int_table("sindex", base[0]);
912 912
913 j = 10; 913 j = 10;
914 for (i = 1; i < nstates; i++) 914 for (i = 1; i < nstates; i++)
915 { 915 {
916 if (j >= 10) 916 if (j >= 10)
917 { 917 {
918 output_newline(); 918 output_newline();
919 j = 1; 919 j = 1;
920 } 920 }
921 else 921 else
922 ++j; 922 ++j;
923 923
924 output_int(base[i]); 924 output_int(base[i]);
925 } 925 }
926 926
927 end_table(); 927 end_table();
928 928
929 start_int_table("rindex", base[nstates]); 929 start_int_table("rindex", base[nstates]);
930 930
931 j = 10; 931 j = 10;
932 for (i = nstates + 1; i < 2 * nstates; i++) 932 for (i = nstates + 1; i < 2 * nstates; i++)
933 { 933 {
934 if (j >= 10) 934 if (j >= 10)
935 { 935 {
936 output_newline(); 936 output_newline();
937 j = 1; 937 j = 1;
938 } 938 }
939 else 939 else
940 ++j; 940 ++j;
941 941
942 output_int(base[i]); 942 output_int(base[i]);
943 } 943 }
944 944
945 end_table(); 945 end_table();
946 946
947#if defined(YYBTYACC) 947#if defined(YYBTYACC)
948 output_line("#if YYBTYACC"); 948 output_line("#if YYBTYACC");
949 start_int_table("cindex", base[2 * nstates]); 949 start_int_table("cindex", base[2 * nstates]);
950 950
951 j = 10; 951 j = 10;
952 for (i = 2 * nstates + 1; i < 3 * nstates; i++) 952 for (i = 2 * nstates + 1; i < 3 * nstates; i++)
953 { 953 {
954 if (j >= 10) 954 if (j >= 10)
955 { 955 {
956 output_newline(); 956 output_newline();
957 j = 1; 957 j = 1;
958 } 958 }
959 else 959 else
960 ++j; 960 ++j;
961 961
962 output_int(base[i]); 962 output_int(base[i]);
963 } 963 }
964 964
965 end_table(); 965 end_table();
966 output_line("#endif"); 966 output_line("#endif");
967#endif 967#endif
968 968
969 start_int_table("gindex", base[PER_STATE * nstates]); 969 start_int_table("gindex", base[PER_STATE * nstates]);
970 970
971 j = 10; 971 j = 10;
972 for (i = PER_STATE * nstates + 1; i < nvectors - 1; i++) 972 for (i = PER_STATE * nstates + 1; i < nvectors - 1; i++)
973 { 973 {
974 if (j >= 10) 974 if (j >= 10)
975 { 975 {
976 output_newline(); 976 output_newline();
977 j = 1; 977 j = 1;
978 } 978 }
979 else 979 else
980 ++j; 980 ++j;
981 981
982 output_int(base[i]); 982 output_int(base[i]);
983 } 983 }
984 984
985 end_table(); 985 end_table();
986 FREE(base); 986 FREE(base);
987} 987}
988 988
989static void 989static void
990output_table(void) 990output_table(void)
991{ 991{
992 int i; 992 int i;
993 int j; 993 int j;
994 994
995 if (high >= MAXYYINT) 995 if (high >= MAXYYINT)
996 { 996 {
997 fprintf(stderr, "YYTABLESIZE: %ld\n", high); 997 fprintf(stderr, "YYTABLESIZE: %ld\n", high);
998 fprintf(stderr, "Table is longer than %d elements.\n", MAXYYINT); 998 fprintf(stderr, "Table is longer than %d elements.\n", MAXYYINT);
999 done(1); 999 done(1);
1000 } 1000 }
1001 1001
1002 ++outline; 1002 ++outline;
1003 fprintf(code_file, "#define YYTABLESIZE %ld\n", high); 1003 fprintf(code_file, "#define YYTABLESIZE %ld\n", high);
1004 start_int_table("table", table[0]); 1004 start_int_table("table", table[0]);
1005 1005
1006 j = 10; 1006 j = 10;
1007 for (i = 1; i <= high; i++) 1007 for (i = 1; i <= high; i++)
1008 { 1008 {
1009 if (j >= 10) 1009 if (j >= 10)
1010 { 1010 {
1011 output_newline(); 1011 output_newline();
1012 j = 1; 1012 j = 1;
1013 } 1013 }
1014 else 1014 else
1015 ++j; 1015 ++j;
1016 1016
1017 output_int(table[i]); 1017 output_int(table[i]);
1018 } 1018 }
1019 1019
1020 end_table(); 1020 end_table();
1021 FREE(table); 1021 FREE(table);
1022} 1022}
1023 1023
1024static void 1024static void
1025output_check(void) 1025output_check(void)
1026{ 1026{
1027 int i; 1027 int i;
1028 int j; 1028 int j;
1029 1029
1030 start_int_table("check", check[0]); 1030 start_int_table("check", check[0]);
1031 1031
1032 j = 10; 1032 j = 10;
1033 for (i = 1; i <= high; i++) 1033 for (i = 1; i <= high; i++)
1034 { 1034 {
1035 if (j >= 10) 1035 if (j >= 10)
1036 { 1036 {
1037 output_newline(); 1037 output_newline();
1038 j = 1; 1038 j = 1;
1039 } 1039 }
1040 else 1040 else
1041 ++j; 1041 ++j;
1042 1042
1043 output_int(check[i]); 1043 output_int(check[i]);
1044 } 1044 }
1045 1045
1046 end_table(); 1046 end_table();
1047 FREE(check); 1047 FREE(check);
1048} 1048}
1049 1049
1050#if defined(YYBTYACC) 1050#if defined(YYBTYACC)
1051static void 1051static void
1052output_ctable(void) 1052output_ctable(void)
1053{ 1053{
1054 int i; 1054 int i;
1055 int j; 1055 int j;
1056 int limit = (conflicts != 0) ? nconflicts : 0; 1056 int limit = (conflicts != 0) ? nconflicts : 0;
1057 1057
1058 if (limit < high) 1058 if (limit < high)
1059 limit = (int)high; 1059 limit = (int)high;
1060 1060
1061 output_line("#if YYBTYACC"); 1061 output_line("#if YYBTYACC");
1062 start_int_table("ctable", conflicts ? conflicts[0] : -1); 1062 start_int_table("ctable", conflicts ? conflicts[0] : -1);
1063 1063
1064 j = 10; 1064 j = 10;
1065 for (i = 1; i < limit; i++) 1065 for (i = 1; i < limit; i++)
1066 { 1066 {
1067 if (j >= 10) 1067 if (j >= 10)
1068 { 1068 {
1069 output_newline(); 1069 output_newline();
1070 j = 1; 1070 j = 1;
1071 } 1071 }
1072 else 1072 else
1073 ++j; 1073 ++j;
1074 1074
1075 output_int((conflicts != 0 && i < nconflicts) ? conflicts[i] : -1); 1075 output_int((conflicts != 0 && i < nconflicts) ? conflicts[i] : -1);
1076 } 1076 }
1077 1077
1078 if (conflicts) 1078 if (conflicts)
1079 FREE(conflicts); 1079 FREE(conflicts);
1080 1080
1081 end_table(); 1081 end_table();
1082 output_line("#endif"); 1082 output_line("#endif");
1083} 1083}
1084#endif 1084#endif
1085 1085
1086static void 1086static void
1087output_actions(void) 1087output_actions(void)
1088{ 1088{
1089 nvectors = PER_STATE * nstates + nvars; 1089 nvectors = PER_STATE * nstates + nvars;
1090 1090
1091 froms = NEW2(nvectors, Value_t *); 1091 froms = NEW2(nvectors, Value_t *);
1092 tos = NEW2(nvectors, Value_t *); 1092 tos = NEW2(nvectors, Value_t *);
1093 tally = NEW2(nvectors, Value_t); 1093 tally = NEW2(nvectors, Value_t);
1094 width = NEW2(nvectors, Value_t); 1094 width = NEW2(nvectors, Value_t);
1095 1095
1096#if defined(YYBTYACC) 1096#if defined(YYBTYACC)
1097 if (backtrack && (SRtotal + RRtotal) != 0) 1097 if (backtrack && (SRtotal + RRtotal) != 0)
1098 conflicts = NEW2(4 * (SRtotal + RRtotal), Value_t); 1098 conflicts = NEW2(4 * (SRtotal + RRtotal), Value_t);
1099#endif 1099#endif
1100 1100
1101 token_actions(); 1101 token_actions();
1102 FREE(lookaheads); 1102 FREE(lookaheads);
1103 FREE(LA); 1103 FREE(LA);
1104 FREE(LAruleno); 1104 FREE(LAruleno);
1105 FREE(accessing_symbol); 1105 FREE(accessing_symbol);
1106 1106
1107 goto_actions(); 1107 goto_actions();
1108 FREE(goto_base); 1108 FREE(goto_base);
1109 FREE(from_state); 1109 FREE(from_state);
1110 FREE(to_state); 1110 FREE(to_state);
1111 1111
1112 sort_actions(); 1112 sort_actions();
1113 pack_table(); 1113 pack_table();
1114 output_base(); 1114 output_base();
1115 output_table(); 1115 output_table();
1116 output_check(); 1116 output_check();
1117#if defined(YYBTYACC) 1117#if defined(YYBTYACC)
1118 output_ctable(); 1118 output_ctable();
1119#endif 1119#endif
1120} 1120}
1121 1121
1122static int 1122static int
1123is_C_identifier(char *name) 1123is_C_identifier(char *name)
1124{ 1124{
1125 char *s; 1125 char *s;
1126 int c; 1126 int c;
1127 1127
1128 s = name; 1128 s = name;
1129 c = *s; 1129 c = *s;
1130 if (c == '"') 1130 if (c == '"')
1131 { 1131 {
1132 c = *++s; 1132 c = *++s;
1133 if (!isalpha(c) && c != '_' && c != '$') 1133 if (!isalpha(c) && c != '_' && c != '$')
1134 return (0); 1134 return (0);
1135 while ((c = *++s) != '"') 1135 while ((c = *++s) != '"')
1136 { 1136 {
1137 if (!isalnum(c) && c != '_' && c != '$') 1137 if (!isalnum(c) && c != '_' && c != '$')
1138 return (0); 1138 return (0);
1139 } 1139 }
1140 return (1); 1140 return (1);
1141 } 1141 }
1142 1142
1143 if (!isalpha(c) && c != '_' && c != '$') 1143 if (!isalpha(c) && c != '_' && c != '$')
1144 return (0); 1144 return (0);
1145 while ((c = *++s) != 0) 1145 while ((c = *++s) != 0)
1146 { 1146 {
1147 if (!isalnum(c) && c != '_' && c != '$') 1147 if (!isalnum(c) && c != '_' && c != '$')
1148 return (0); 1148 return (0);
1149 } 1149 }
1150 return (1); 1150 return (1);
1151} 1151}
1152 1152
1153#if USE_HEADER_GUARDS 1153#if USE_HEADER_GUARDS
1154static void 1154static void
1155start_defines_file(void) 1155start_defines_file(void)
1156{ 1156{
1157 fprintf(defines_file, "#ifndef _%s_defines_h_\n", symbol_prefix); 1157 fprintf(defines_file, "#ifndef _%s_defines_h_\n", symbol_prefix);
1158 fprintf(defines_file, "#define _%s_defines_h_\n\n", symbol_prefix); 1158 fprintf(defines_file, "#define _%s_defines_h_\n\n", symbol_prefix);
1159} 1159}
1160 1160
1161static void 1161static void
1162end_defines_file(void) 1162end_defines_file(void)
1163{ 1163{
1164 fprintf(defines_file, "\n#endif /* _%s_defines_h_ */\n", symbol_prefix); 1164 fprintf(defines_file, "\n#endif /* _%s_defines_h_ */\n", symbol_prefix);
1165} 1165}
1166#else 1166#else
1167#define start_defines_file() /* nothing */ 1167#define start_defines_file() /* nothing */
1168#define end_defines_file() /* nothing */ 1168#define end_defines_file() /* nothing */
1169#endif 1169#endif
1170 1170
1171static void 1171static void
1172output_defines(FILE * fp) 1172output_defines(FILE * fp)
1173{ 1173{
1174 int c, i; 1174 int c, i;
1175 char *s; 1175 char *s;
1176 1176
1177 for (i = 2; i < ntokens; ++i) 1177 for (i = 2; i < ntokens; ++i)
1178 { 1178 {
1179 s = symbol_name[i]; 1179 s = symbol_name[i];
1180 if (is_C_identifier(s) && (!sflag || *s != '"')) 1180 if (is_C_identifier(s) && (!sflag || *s != '"'))
1181 { 1181 {
1182 fprintf(fp, "#define "); 1182 fprintf(fp, "#define ");
1183 c = *s; 1183 c = *s;
1184 if (c == '"') 1184 if (c == '"')
1185 { 1185 {
1186 while ((c = *++s) != '"') 1186 while ((c = *++s) != '"')
1187 { 1187 {
1188 putc(c, fp); 1188 putc(c, fp);
1189 } 1189 }
1190 } 1190 }
1191 else 1191 else
1192 { 1192 {
1193 do 1193 do
1194 { 1194 {
1195 putc(c, fp); 1195 putc(c, fp);
1196 } 1196 }
1197 while ((c = *++s) != 0); 1197 while ((c = *++s) != 0);
1198 } 1198 }
1199 if (fp == code_file) 1199 if (fp == code_file)
1200 ++outline; 1200 ++outline;
1201 fprintf(fp, " %d\n", symbol_value[i]); 1201 fprintf(fp, " %d\n", symbol_value[i]);
1202 } 1202 }
1203 } 1203 }
1204 1204
1205 if (fp == code_file) 1205 if (fp == code_file)
1206 ++outline; 1206 ++outline;
1207 if (fp != defines_file || iflag) 1207 if (fp != defines_file || iflag)
1208 fprintf(fp, "#define YYERRCODE %d\n", symbol_value[1]); 1208 fprintf(fp, "#define YYERRCODE %d\n", symbol_value[1]);
1209 1209
1210 if (fp == defines_file || (iflag && !dflag)) 1210 if (fp == defines_file || (iflag && !dflag))
1211 { 1211 {
1212 if (unionized) 1212 if (unionized)
1213 { 1213 {
1214 if (union_file != 0) 1214 if (union_file != 0)
1215 { 1215 {
1216 rewind(union_file); 1216 rewind(union_file);
1217 while ((c = getc(union_file)) != EOF) 1217 while ((c = getc(union_file)) != EOF)
1218 putc_code(fp, c); 1218 putc_code(fp, c);
1219 } 1219 }
1220 fprintf(fp, "extern YYSTYPE %slval;\n", symbol_prefix); 1220 if (!pure_parser)
 1221 fprintf(fp, "extern YYSTYPE %slval;\n", symbol_prefix);
1221 } 1222 }
1222 } 1223 }
1223} 1224}
1224 1225
1225static void 1226static void
1226output_stored_text(FILE * fp) 1227output_stored_text(FILE * fp)
1227{ 1228{
1228 int c; 1229 int c;
1229 FILE *in; 1230 FILE *in;
1230 1231
1231 rewind(text_file); 1232 rewind(text_file);
1232 if (text_file == NULL) 1233 if (text_file == NULL)
1233 open_error("text_file"); 1234 open_error("text_file");
1234 in = text_file; 1235 in = text_file;
1235 if ((c = getc(in)) == EOF) 1236 if ((c = getc(in)) == EOF)
1236 return; 1237 return;
1237 putc_code(fp, c); 1238 putc_code(fp, c);
1238 while ((c = getc(in)) != EOF) 1239 while ((c = getc(in)) != EOF)
1239 { 1240 {
1240 putc_code(fp, c); 1241 putc_code(fp, c);
1241 } 1242 }
1242 write_code_lineno(fp); 1243 write_code_lineno(fp);
1243} 1244}
1244 1245
1245static void 1246static void
1246output_debug(void) 1247output_debug(void)
1247{ 1248{
1248 int i, j, k, max, maxtok; 1249 int i, j, k, max, maxtok;
1249 const char **symnam; 1250 const char **symnam;
1250 const char *s; 1251 const char *s;
1251 1252
1252 ++outline; 1253 ++outline;
1253 fprintf(code_file, "#define YYFINAL %d\n", final_state); 1254 fprintf(code_file, "#define YYFINAL %d\n", final_state);
1254 1255
1255 putl_code(code_file, "#ifndef YYDEBUG\n"); 1256 putl_code(code_file, "#ifndef YYDEBUG\n");
1256 ++outline; 1257 ++outline;
1257 fprintf(code_file, "#define YYDEBUG %d\n", tflag); 1258 fprintf(code_file, "#define YYDEBUG %d\n", tflag);
1258 putl_code(code_file, "#endif\n"); 1259 putl_code(code_file, "#endif\n");
1259 1260
1260 if (rflag) 1261 if (rflag)
1261 { 1262 {
1262 fprintf(output_file, "#ifndef YYDEBUG\n"); 1263 fprintf(output_file, "#ifndef YYDEBUG\n");
1263 fprintf(output_file, "#define YYDEBUG %d\n", tflag); 1264 fprintf(output_file, "#define YYDEBUG %d\n", tflag);
1264 fprintf(output_file, "#endif\n"); 1265 fprintf(output_file, "#endif\n");
1265 } 1266 }
1266 1267
1267 maxtok = 0; 1268 maxtok = 0;
1268 for (i = 0; i < ntokens; ++i) 1269 for (i = 0; i < ntokens; ++i)
1269 if (symbol_value[i] > maxtok) 1270 if (symbol_value[i] > maxtok)
1270 maxtok = symbol_value[i]; 1271 maxtok = symbol_value[i];
1271 1272
1272 /* symbol_value[$accept] = -1 */ 1273 /* symbol_value[$accept] = -1 */
1273 /* symbol_value[<goal>] = 0 */ 1274 /* symbol_value[<goal>] = 0 */
1274 /* remaining non-terminals start at 1 */ 1275 /* remaining non-terminals start at 1 */
1275 max = maxtok; 1276 max = maxtok;
1276 for (i = ntokens; i < nsyms; ++i) 1277 for (i = ntokens; i < nsyms; ++i)
1277 if (((maxtok + 1) + (symbol_value[i] + 1)) > max) 1278 if (((maxtok + 1) + (symbol_value[i] + 1)) > max)
1278 max = (maxtok + 1) + (symbol_value[i] + 1); 1279 max = (maxtok + 1) + (symbol_value[i] + 1);
1279 1280
1280 ++outline; 1281 ++outline;
1281 fprintf(code_file, "#define YYMAXTOKEN %d\n", maxtok); 1282 fprintf(code_file, "#define YYMAXTOKEN %d\n", maxtok);
1282 1283
1283 ++outline; 1284 ++outline;
1284 fprintf(code_file, "#define YYUNDFTOKEN %d\n", max + 1); 1285 fprintf(code_file, "#define YYUNDFTOKEN %d\n", max + 1);
1285 1286
1286 ++outline; 1287 ++outline;
1287 fprintf(code_file, "#define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? " 1288 fprintf(code_file, "#define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? "
1288 "YYUNDFTOKEN : (a))\n"); 1289 "YYUNDFTOKEN : (a))\n");
1289 1290
1290 symnam = TMALLOC(const char *, max + 2); 1291 symnam = TMALLOC(const char *, max + 2);
1291 NO_SPACE(symnam); 1292 NO_SPACE(symnam);
1292 1293
1293 /* Note that it is not necessary to initialize the element */ 1294 /* Note that it is not necessary to initialize the element */
1294 /* symnam[max]. */ 1295 /* symnam[max]. */
1295#if defined(YYBTYACC) 1296#if defined(YYBTYACC)
1296 for (i = 0; i < max; ++i) 1297 for (i = 0; i < max; ++i)
1297 symnam[i] = 0; 1298 symnam[i] = 0;
1298 for (i = nsyms - 1; i >= 0; --i) 1299 for (i = nsyms - 1; i >= 0; --i)
1299 symnam[symbol_pval[i]] = symbol_name[i]; 1300 symnam[symbol_pval[i]] = symbol_name[i];
1300 symnam[max + 1] = "illegal-symbol"; 1301 symnam[max + 1] = "illegal-symbol";
1301#else 1302#else
1302 for (i = 0; i <= max; ++i) 1303 for (i = 0; i <= max; ++i)
1303 symnam[i] = 0; 1304 symnam[i] = 0;
1304 for (i = ntokens - 1; i >= 2; --i) 1305 for (i = ntokens - 1; i >= 2; --i)
1305 symnam[symbol_value[i]] = symbol_name[i]; 1306 symnam[symbol_value[i]] = symbol_name[i];
1306 symnam[0] = "end-of-file"; 1307 symnam[0] = "end-of-file";
1307 symnam[max + 1] = "illegal-symbol"; 1308 symnam[max + 1] = "illegal-symbol";
1308#endif 1309#endif
1309 1310
1310 /* 1311 /*
1311 * bison's yytname[] array is roughly the same as byacc's yyname[] array. 1312 * bison's yytname[] array is roughly the same as byacc's yyname[] array.
1312 * The difference is that byacc does not predefine "$undefined". 1313 * The difference is that byacc does not predefine "$undefined".
1313 * 1314 *
1314 * If the grammar declares "%token-table", define symbol "yytname" so 1315 * If the grammar declares "%token-table", define symbol "yytname" so
1315 * an application such as ntpd can build. 1316 * an application such as ntpd can build.
1316 */ 1317 */
1317 if (token_table) 1318 if (token_table)
1318 { 1319 {
1319 output_line("#undef yytname"); 1320 output_line("#undef yytname");
1320 output_line("#define yytname yyname"); 1321 output_line("#define yytname yyname");
1321 } 1322 }
1322 else 1323 else
1323 { 1324 {
1324 output_line("#if YYDEBUG"); 1325 output_line("#if YYDEBUG");
1325 } 1326 }
1326 1327
1327 start_str_table("name"); 1328 start_str_table("name");
1328 j = 80; 1329 j = 80;
1329 for (i = 0; i <= max + 1; ++i) 1330 for (i = 0; i <= max + 1; ++i)
1330 { 1331 {
1331 if ((s = symnam[i]) != 0) 1332 if ((s = symnam[i]) != 0)
1332 { 1333 {
1333 if (s[0] == '"') 1334 if (s[0] == '"')
1334 { 1335 {
1335 k = 7; 1336 k = 7;
1336 while (*++s != '"') 1337 while (*++s != '"')
1337 { 1338 {
1338 ++k; 1339 ++k;
1339 if (*s == '\\') 1340 if (*s == '\\')
1340 { 1341 {
1341 k += 2; 1342 k += 2;
1342 if (*++s == '\\') 1343 if (*++s == '\\')
1343 ++k; 1344 ++k;
1344 } 1345 }
1345 } 1346 }
1346 j += k; 1347 j += k;
1347 if (j > 80) 1348 if (j > 80)
1348 { 1349 {
1349 output_newline(); 1350 output_newline();
1350 j = k; 1351 j = k;
1351 } 1352 }
1352 fprintf(output_file, "\"\\\""); 1353 fprintf(output_file, "\"\\\"");
1353 s = symnam[i]; 1354 s = symnam[i];
1354 while (*++s != '"') 1355 while (*++s != '"')
1355 { 1356 {
1356 if (*s == '\\') 1357 if (*s == '\\')
1357 { 1358 {
1358 fprintf(output_file, "\\\\"); 1359 fprintf(output_file, "\\\\");
1359 if (*++s == '\\') 1360 if (*++s == '\\')
1360 fprintf(output_file, "\\\\"); 1361 fprintf(output_file, "\\\\");
1361 else 1362 else
1362 putc(*s, output_file); 1363 putc(*s, output_file);
1363 } 1364 }
1364 else 1365 else
1365 putc(*s, output_file); 1366 putc(*s, output_file);
1366 } 1367 }
1367 fprintf(output_file, "\\\"\","); 1368 fprintf(output_file, "\\\"\",");
1368 } 1369 }
1369 else if (s[0] == '\'') 1370 else if (s[0] == '\'')
1370 { 1371 {
1371 if (s[1] == '"') 1372 if (s[1] == '"')
1372 { 1373 {
1373 j += 7; 1374 j += 7;
1374 if (j > 80) 1375 if (j > 80)
1375 { 1376 {
1376 output_newline(); 1377 output_newline();
1377 j = 7; 1378 j = 7;
1378 } 1379 }
1379 fprintf(output_file, "\"'\\\"'\","); 1380 fprintf(output_file, "\"'\\\"'\",");
1380 } 1381 }
1381 else 1382 else
1382 { 1383 {
1383 k = 5; 1384 k = 5;
1384 while (*++s != '\'') 1385 while (*++s != '\'')
1385 { 1386 {
1386 ++k; 1387 ++k;
1387 if (*s == '\\') 1388 if (*s == '\\')
1388 { 1389 {
1389 k += 2; 1390 k += 2;
1390 if (*++s == '\\') 1391 if (*++s == '\\')
1391 ++k; 1392 ++k;
1392 } 1393 }
1393 } 1394 }
1394 j += k; 1395 j += k;
1395 if (j > 80) 1396 if (j > 80)
1396 { 1397 {
1397 output_newline(); 1398 output_newline();
1398 j = k; 1399 j = k;
1399 } 1400 }
1400 fprintf(output_file, "\"'"); 1401 fprintf(output_file, "\"'");
1401 s = symnam[i]; 1402 s = symnam[i];
1402 while (*++s != '\'') 1403 while (*++s != '\'')
1403 { 1404 {
1404 if (*s == '\\') 1405 if (*s == '\\')
1405 { 1406 {
1406 fprintf(output_file, "\\\\"); 1407 fprintf(output_file, "\\\\");
1407 if (*++s == '\\') 1408 if (*++s == '\\')
1408 fprintf(output_file, "\\\\"); 1409 fprintf(output_file, "\\\\");
1409 else 1410 else
1410 putc(*s, output_file); 1411 putc(*s, output_file);
1411 } 1412 }
1412 else 1413 else
1413 putc(*s, output_file); 1414 putc(*s, output_file);
1414 } 1415 }
1415 fprintf(output_file, "'\","); 1416 fprintf(output_file, "'\",");
1416 } 1417 }
1417 } 1418 }
1418 else 1419 else
1419 { 1420 {
1420 k = (int)strlen(s) + 3; 1421 k = (int)strlen(s) + 3;
1421 j += k; 1422 j += k;
1422 if (j > 80) 1423 if (j > 80)
1423 { 1424 {
1424 output_newline(); 1425 output_newline();
1425 j = k; 1426 j = k;
1426 } 1427 }
1427 putc('"', output_file); 1428 putc('"', output_file);
1428 do 1429 do
1429 { 1430 {
1430 putc(*s, output_file); 1431 putc(*s, output_file);
1431 } 1432 }
1432 while (*++s); 1433 while (*++s);
1433 fprintf(output_file, "\","); 1434 fprintf(output_file, "\",");
1434 } 1435 }
1435 } 1436 }
1436 else 1437 else
1437 { 1438 {
1438 j += 2; 1439 j += 2;
1439 if (j > 80) 1440 if (j > 80)
1440 { 1441 {
1441 output_newline(); 1442 output_newline();
1442 j = 2; 1443 j = 2;
1443 } 1444 }
1444 fprintf(output_file, "0,"); 1445 fprintf(output_file, "0,");
1445 } 1446 }
1446 } 1447 }
1447 end_table(); 1448 end_table();
1448 FREE(symnam); 1449 FREE(symnam);
1449 1450
1450 if (token_table) 1451 if (token_table)
1451 output_line("#if YYDEBUG"); 1452 output_line("#if YYDEBUG");
1452 start_str_table("rule"); 1453 start_str_table("rule");
1453 for (i = 2; i < nrules; ++i) 1454 for (i = 2; i < nrules; ++i)
1454 { 1455 {
1455 fprintf(output_file, "\"%s :", symbol_name[rlhs[i]]); 1456 fprintf(output_file, "\"%s :", symbol_name[rlhs[i]]);
1456 for (j = rrhs[i]; ritem[j] > 0; ++j) 1457 for (j = rrhs[i]; ritem[j] > 0; ++j)
1457 { 1458 {
1458 s = symbol_name[ritem[j]]; 1459 s = symbol_name[ritem[j]];
1459 if (s[0] == '"') 1460 if (s[0] == '"')
1460 { 1461 {
1461 fprintf(output_file, " \\\""); 1462 fprintf(output_file, " \\\"");
1462 while (*++s != '"') 1463 while (*++s != '"')
1463 { 1464 {
1464 if (*s == '\\') 1465 if (*s == '\\')
1465 { 1466 {
1466 if (s[1] == '\\') 1467 if (s[1] == '\\')
1467 fprintf(output_file, "\\\\\\\\"); 1468 fprintf(output_file, "\\\\\\\\");
1468 else 1469 else
1469 fprintf(output_file, "\\\\%c", s[1]); 1470 fprintf(output_file, "\\\\%c", s[1]);
1470 ++s; 1471 ++s;
1471 } 1472 }
1472 else 1473 else
1473 putc(*s, output_file); 1474 putc(*s, output_file);
1474 } 1475 }
1475 fprintf(output_file, "\\\""); 1476 fprintf(output_file, "\\\"");
1476 } 1477 }
1477 else if (s[0] == '\'') 1478 else if (s[0] == '\'')
1478 { 1479 {
1479 if (s[1] == '"') 1480 if (s[1] == '"')
1480 fprintf(output_file, " '\\\"'"); 1481 fprintf(output_file, " '\\\"'");
1481 else if (s[1] == '\\') 1482 else if (s[1] == '\\')
1482 { 1483 {
1483 if (s[2] == '\\') 1484 if (s[2] == '\\')
1484 fprintf(output_file, " '\\\\\\\\"); 1485 fprintf(output_file, " '\\\\\\\\");
1485 else 1486 else
1486 fprintf(output_file, " '\\\\%c", s[2]); 1487 fprintf(output_file, " '\\\\%c", s[2]);
1487 s += 2; 1488 s += 2;
1488 while (*++s != '\'') 1489 while (*++s != '\'')
1489 putc(*s, output_file); 1490 putc(*s, output_file);
1490 putc('\'', output_file); 1491 putc('\'', output_file);
1491 } 1492 }
1492 else 1493 else
1493 fprintf(output_file, " '%c'", s[1]); 1494 fprintf(output_file, " '%c'", s[1]);
1494 } 1495 }
1495 else 1496 else
1496 fprintf(output_file, " %s", s); 1497 fprintf(output_file, " %s", s);
1497 } 1498 }
1498 fprintf(output_file, "\","); 1499 fprintf(output_file, "\",");
1499 output_newline(); 1500 output_newline();
1500 } 1501 }
1501 1502
1502 end_table(); 1503 end_table();
1503 output_line("#endif"); 1504 output_line("#endif");
1504} 1505}
1505 1506
1506#if defined(YYBTYACC) 1507#if defined(YYBTYACC)
1507static void 1508static void
1508output_backtracking_parser(FILE * fp) 1509output_backtracking_parser(FILE * fp)
1509{ 1510{
1510 putl_code(fp, "#undef YYBTYACC\n"); 1511 putl_code(fp, "#undef YYBTYACC\n");
1511#if defined(YYBTYACC) 1512#if defined(YYBTYACC)
1512 if (backtrack) 1513 if (backtrack)
1513 { 1514 {
1514 putl_code(fp, "#define YYBTYACC 1\n"); 1515 putl_code(fp, "#define YYBTYACC 1\n");
1515 putl_code(fp, 1516 putl_code(fp,
1516 "#define YYDEBUGSTR (yytrial ? YYPREFIX \"debug(trial)\" : YYPREFIX \"debug\")\n"); 1517 "#define YYDEBUGSTR (yytrial ? YYPREFIX \"debug(trial)\" : YYPREFIX \"debug\")\n");
1517 } 1518 }
1518 else 1519 else
1519#endif 1520#endif
1520 { 1521 {
1521 putl_code(fp, "#define YYBTYACC 0\n"); 1522 putl_code(fp, "#define YYBTYACC 0\n");
1522 putl_code(fp, "#define YYDEBUGSTR YYPREFIX \"debug\"\n"); 1523 putl_code(fp, "#define YYDEBUGSTR YYPREFIX \"debug\"\n");
1523 } 1524 }
1524} 1525}
1525#endif 1526#endif
1526 1527
1527static void 1528static void
1528output_pure_parser(FILE * fp) 1529output_pure_parser(FILE * fp)
1529{ 1530{
1530 putc_code(fp, '\n'); 1531 putc_code(fp, '\n');
1531 1532
1532 if (fp == code_file) 1533 if (fp == code_file)
1533 ++outline; 1534 ++outline;
1534 fprintf(fp, "#define YYPURE %d\n", pure_parser); 1535 fprintf(fp, "#define YYPURE %d\n", pure_parser);
1535 putc_code(fp, '\n'); 1536 putc_code(fp, '\n');
1536} 1537}
1537 1538
1538static void 1539static void
1539output_stype(FILE * fp) 1540output_stype(FILE * fp)
1540{ 1541{
1541 if (!unionized && ntags == 0) 1542 if (!unionized && ntags == 0)
1542 { 1543 {
1543 putc_code(fp, '\n'); 1544 putc_code(fp, '\n');
1544 putl_code(fp, "#if " 1545 putl_code(fp, "#if "
1545 "! defined(YYSTYPE) && " 1546 "! defined(YYSTYPE) && "
1546 "! defined(YYSTYPE_IS_DECLARED)\n"); 1547 "! defined(YYSTYPE_IS_DECLARED)\n");
1547 putl_code(fp, "/* Default: YYSTYPE is the semantic value type. */\n"); 1548 putl_code(fp, "/* Default: YYSTYPE is the semantic value type. */\n");
1548 putl_code(fp, "typedef int YYSTYPE;\n"); 1549 putl_code(fp, "typedef int YYSTYPE;\n");
1549 putl_code(fp, "# define YYSTYPE_IS_DECLARED 1\n"); 1550 putl_code(fp, "# define YYSTYPE_IS_DECLARED 1\n");
1550 putl_code(fp, "#endif\n"); 1551 putl_code(fp, "#endif\n");
1551 } 1552 }
1552} 1553}
1553 1554
1554#if defined(YYBTYACC) 1555#if defined(YYBTYACC)
1555static void 1556static void
1556output_ltype(FILE * fp) 1557output_ltype(FILE * fp)
1557{ 1558{
1558 putc_code(fp, '\n'); 1559 putc_code(fp, '\n');
1559 putl_code(fp, "#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED\n"); 1560 putl_code(fp, "#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED\n");
1560 putl_code(fp, "/* Default: YYLTYPE is the text position type. */\n"); 1561 putl_code(fp, "/* Default: YYLTYPE is the text position type. */\n");
1561 putl_code(fp, "typedef struct YYLTYPE\n"); 1562 putl_code(fp, "typedef struct YYLTYPE\n");
1562 putl_code(fp, "{\n"); 1563 putl_code(fp, "{\n");
1563 putl_code(fp, " int first_line;\n"); 1564 putl_code(fp, " int first_line;\n");
1564 putl_code(fp, " int first_column;\n"); 1565 putl_code(fp, " int first_column;\n");
1565 putl_code(fp, " int last_line;\n"); 1566 putl_code(fp, " int last_line;\n");
1566 putl_code(fp, " int last_column;\n"); 1567 putl_code(fp, " int last_column;\n");
1567 putl_code(fp, " unsigned source;\n"); 1568 putl_code(fp, " unsigned source;\n");
1568 putl_code(fp, "} YYLTYPE;\n"); 1569 putl_code(fp, "} YYLTYPE;\n");
1569 putl_code(fp, "#define YYLTYPE_IS_DECLARED 1\n"); 1570 putl_code(fp, "#define YYLTYPE_IS_DECLARED 1\n");
1570 putl_code(fp, "#endif\n"); 1571 putl_code(fp, "#endif\n");
1571 putl_code(fp, "#define YYRHSLOC(rhs, k) ((rhs)[k])\n"); 1572 putl_code(fp, "#define YYRHSLOC(rhs, k) ((rhs)[k])\n");
1572} 1573}
1573#endif 1574#endif
1574 1575
1575static void 1576static void
1576output_trailing_text(void) 1577output_trailing_text(void)
1577{ 1578{
1578 int c, last; 1579 int c, last;
1579 FILE *in; 1580 FILE *in;
1580 1581
1581 if (line == 0) 1582 if (line == 0)
1582 return; 1583 return;
1583 1584
1584 in = input_file; 1585 in = input_file;
1585 c = *cptr; 1586 c = *cptr;
1586 if (c == '\n') 1587 if (c == '\n')
1587 { 1588 {
1588 ++lineno; 1589 ++lineno;
1589 if ((c = getc(in)) == EOF) 1590 if ((c = getc(in)) == EOF)
1590 return; 1591 return;
1591 write_input_lineno(); 1592 write_input_lineno();
1592 putc_code(code_file, c); 1593 putc_code(code_file, c);
1593 last = c; 1594 last = c;
1594 } 1595 }
1595 else 1596 else
1596 { 1597 {
1597 write_input_lineno(); 1598 write_input_lineno();
1598 do 1599 do
1599 { 1600 {
1600 putc_code(code_file, c); 1601 putc_code(code_file, c);
1601 } 1602 }
1602 while ((c = *++cptr) != '\n'); 1603 while ((c = *++cptr) != '\n');
1603 putc_code(code_file, c); 1604 putc_code(code_file, c);
1604 last = '\n'; 1605 last = '\n';
1605 } 1606 }
1606 1607
1607 while ((c = getc(in)) != EOF) 1608 while ((c = getc(in)) != EOF)
1608 { 1609 {
1609 putc_code(code_file, c); 1610 putc_code(code_file, c);
1610 last = c; 1611 last = c;
1611 } 1612 }
1612 1613
1613 if (last != '\n') 1614 if (last != '\n')
1614 { 1615 {
1615 putc_code(code_file, '\n'); 1616 putc_code(code_file, '\n');
1616 } 1617 }
1617 write_code_lineno(code_file); 1618 write_code_lineno(code_file);
1618} 1619}
1619 1620
1620static void 1621static void
1621output_semantic_actions(void) 1622output_semantic_actions(void)
1622{ 1623{
1623 int c, last; 1624 int c, last;
1624 1625
1625 rewind(action_file); 1626 rewind(action_file);
1626 if ((c = getc(action_file)) == EOF) 1627 if ((c = getc(action_file)) == EOF)
1627 return; 1628 return;
1628 1629
1629 last = c; 1630 last = c;
1630 putc_code(code_file, c); 1631 putc_code(code_file, c);
1631 while ((c = getc(action_file)) != EOF) 1632 while ((c = getc(action_file)) != EOF)
1632 { 1633 {
1633 putc_code(code_file, c); 1634 putc_code(code_file, c);
1634 last = c; 1635 last = c;
1635 } 1636 }
1636 1637
1637 if (last != '\n') 1638 if (last != '\n')
1638 { 1639 {
1639 putc_code(code_file, '\n'); 1640 putc_code(code_file, '\n');
1640 } 1641 }
1641 1642
1642 write_code_lineno(code_file); 1643 write_code_lineno(code_file);
1643} 1644}
1644 1645
1645static void 1646static void
1646output_parse_decl(FILE * fp) 1647output_parse_decl(FILE * fp)
1647{ 1648{
1648 putc_code(fp, '\n'); 1649 putc_code(fp, '\n');
1649 putl_code(fp, "/* compatibility with bison */\n"); 1650 putl_code(fp, "/* compatibility with bison */\n");
1650 putl_code(fp, "#ifdef YYPARSE_PARAM\n"); 1651 putl_code(fp, "#ifdef YYPARSE_PARAM\n");
1651 putl_code(fp, "/* compatibility with FreeBSD */\n"); 1652 putl_code(fp, "/* compatibility with FreeBSD */\n");
1652 putl_code(fp, "# ifdef YYPARSE_PARAM_TYPE\n"); 1653 putl_code(fp, "# ifdef YYPARSE_PARAM_TYPE\n");
1653 putl_code(fp, 1654 putl_code(fp,
1654 "# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)\n"); 1655 "# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)\n");
1655 putl_code(fp, "# else\n"); 1656 putl_code(fp, "# else\n");
1656 putl_code(fp, "# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)\n"); 1657 putl_code(fp, "# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)\n");
1657 putl_code(fp, "# endif\n"); 1658 putl_code(fp, "# endif\n");
1658 putl_code(fp, "#else\n"); 1659 putl_code(fp, "#else\n");
1659 1660
1660 puts_code(fp, "# define YYPARSE_DECL() yyparse("); 1661 puts_code(fp, "# define YYPARSE_DECL() yyparse(");
1661 puts_param_types(fp, parse_param, 0); 1662 puts_param_types(fp, parse_param, 0);
1662 putl_code(fp, ")\n"); 1663 putl_code(fp, ")\n");
1663 1664
1664 putl_code(fp, "#endif\n"); 1665 putl_code(fp, "#endif\n");
1665} 1666}
1666 1667
1667static void 1668static void
1668output_lex_decl(FILE * fp) 1669output_lex_decl(FILE * fp)
1669{ 1670{
1670 putc_code(fp, '\n'); 1671 putc_code(fp, '\n');
1671 putl_code(fp, "/* Parameters sent to lex. */\n"); 1672 putl_code(fp, "/* Parameters sent to lex. */\n");
1672 putl_code(fp, "#ifdef YYLEX_PARAM\n"); 1673 putl_code(fp, "#ifdef YYLEX_PARAM\n");
1673 if (pure_parser) 1674 if (pure_parser)
1674 { 1675 {
1675 putl_code(fp, "# ifdef YYLEX_PARAM_TYPE\n"); 1676 putl_code(fp, "# ifdef YYLEX_PARAM_TYPE\n");
1676#if defined(YYBTYACC) 1677#if defined(YYBTYACC)
1677 if (locations) 1678 if (locations)
1678 { 1679 {
1679 putl_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval," 1680 putl_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval,"
1680 " YYLTYPE *yylloc," 1681 " YYLTYPE *yylloc,"
1681 " YYLEX_PARAM_TYPE YYLEX_PARAM)\n"); 1682 " YYLEX_PARAM_TYPE YYLEX_PARAM)\n");
1682 } 1683 }
1683 else 1684 else
1684#endif 1685#endif
1685 { 1686 {
1686 putl_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval," 1687 putl_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval,"
1687 " YYLEX_PARAM_TYPE YYLEX_PARAM)\n"); 1688 " YYLEX_PARAM_TYPE YYLEX_PARAM)\n");
1688 } 1689 }
1689 putl_code(fp, "# else\n"); 1690 putl_code(fp, "# else\n");
1690#if defined(YYBTYACC) 1691#if defined(YYBTYACC)
1691 if (locations) 1692 if (locations)
1692 { 1693 {
1693 putl_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval," 1694 putl_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval,"
1694 " YYLTYPE *yylloc," 1695 " YYLTYPE *yylloc,"
1695 " void * YYLEX_PARAM)\n"); 1696 " void * YYLEX_PARAM)\n");
1696 } 1697 }
1697 else 1698 else
1698#endif 1699#endif
1699 { 1700 {
1700 putl_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval," 1701 putl_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval,"
1701 " void * YYLEX_PARAM)\n"); 1702 " void * YYLEX_PARAM)\n");
1702 } 1703 }
1703 putl_code(fp, "# endif\n"); 1704 putl_code(fp, "# endif\n");
1704#if defined(YYBTYACC) 1705#if defined(YYBTYACC)
1705 if (locations) 1706 if (locations)
1706 putl_code(fp, 1707 putl_code(fp,
1707 "# define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)\n"); 1708 "# define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)\n");
1708 else 1709 else
1709#endif 1710#endif
1710 putl_code(fp, "# define YYLEX yylex(&yylval, YYLEX_PARAM)\n"); 1711 putl_code(fp, "# define YYLEX yylex(&yylval, YYLEX_PARAM)\n");
1711 } 1712 }
1712 else 1713 else
1713 { 1714 {
1714 putl_code(fp, "# define YYLEX_DECL() yylex(void *YYLEX_PARAM)\n"); 1715 putl_code(fp, "# define YYLEX_DECL() yylex(void *YYLEX_PARAM)\n");
1715 putl_code(fp, "# define YYLEX yylex(YYLEX_PARAM)\n"); 1716 putl_code(fp, "# define YYLEX yylex(YYLEX_PARAM)\n");
1716 } 1717 }
1717 putl_code(fp, "#else\n"); 1718 putl_code(fp, "#else\n");
1718 if (pure_parser && lex_param) 1719 if (pure_parser && lex_param)
1719 { 1720 {
1720#if defined(YYBTYACC) 1721#if defined(YYBTYACC)
1721 if (locations) 1722 if (locations)
1722 puts_code(fp, 1723 puts_code(fp,
1723 "# define YYLEX_DECL() yylex(YYSTYPE *yylval, YYLTYPE *yylloc, "); 1724 "# define YYLEX_DECL() yylex(YYSTYPE *yylval, YYLTYPE *yylloc, ");
1724 else 1725 else
1725#endif 1726#endif
1726 puts_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval, "); 1727 puts_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval, ");
1727 puts_param_types(fp, lex_param, 0); 1728 puts_param_types(fp, lex_param, 0);
1728 putl_code(fp, ")\n"); 1729 putl_code(fp, ")\n");
1729 1730
1730#if defined(YYBTYACC) 1731#if defined(YYBTYACC)
1731 if (locations) 1732 if (locations)
1732 puts_code(fp, "# define YYLEX yylex(&yylval, &yylloc, "); 1733 puts_code(fp, "# define YYLEX yylex(&yylval, &yylloc, ");
1733 else 1734 else
1734#endif 1735#endif
1735 puts_code(fp, "# define YYLEX yylex(&yylval, "); 1736 puts_code(fp, "# define YYLEX yylex(&yylval, ");
1736 puts_param_names(fp, lex_param, 0); 1737 puts_param_names(fp, lex_param, 0);
1737 putl_code(fp, ")\n"); 1738 putl_code(fp, ")\n");
1738 } 1739 }
1739 else if (pure_parser) 1740 else if (pure_parser)
1740 { 1741 {
1741#if defined(YYBTYACC) 1742#if defined(YYBTYACC)
1742 if (locations) 1743 if (locations)
1743 { 1744 {
1744 putl_code(fp, 1745 putl_code(fp,
1745 "# define YYLEX_DECL() yylex(YYSTYPE *yylval, YYLTYPE *yylloc)\n"); 1746 "# define YYLEX_DECL() yylex(YYSTYPE *yylval, YYLTYPE *yylloc)\n");
1746 putl_code(fp, "# define YYLEX yylex(&yylval, &yylloc)\n"); 1747 putl_code(fp, "# define YYLEX yylex(&yylval, &yylloc)\n");
1747 } 1748 }
1748 else 1749 else
1749#endif 1750#endif
1750 { 1751 {
1751 putl_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval)\n"); 1752 putl_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval)\n");
1752 putl_code(fp, "# define YYLEX yylex(&yylval)\n"); 1753 putl_code(fp, "# define YYLEX yylex(&yylval)\n");
1753 } 1754 }
1754 } 1755 }
1755 else if (lex_param) 1756 else if (lex_param)
1756 { 1757 {
1757 puts_code(fp, "# define YYLEX_DECL() yylex("); 1758 puts_code(fp, "# define YYLEX_DECL() yylex(");
1758 puts_param_types(fp, lex_param, 0); 1759 puts_param_types(fp, lex_param, 0);
1759 putl_code(fp, ")\n"); 1760 putl_code(fp, ")\n");
1760 1761
1761 puts_code(fp, "# define YYLEX yylex("); 1762 puts_code(fp, "# define YYLEX yylex(");
1762 puts_param_names(fp, lex_param, 0); 1763 puts_param_names(fp, lex_param, 0);
1763 putl_code(fp, ")\n"); 1764 putl_code(fp, ")\n");
1764 } 1765 }
1765 else 1766 else
1766 { 1767 {
1767 putl_code(fp, "# define YYLEX_DECL() yylex(void)\n"); 1768 putl_code(fp, "# define YYLEX_DECL() yylex(void)\n");
1768 putl_code(fp, "# define YYLEX yylex()\n"); 1769 putl_code(fp, "# define YYLEX yylex()\n");
1769 } 1770 }
1770 putl_code(fp, "#endif\n"); 1771 putl_code(fp, "#endif\n");
1771} 1772}
1772 1773
1773static void 1774static void
1774output_error_decl(FILE * fp) 1775output_error_decl(FILE * fp)
1775{ 1776{
1776 putc_code(fp, '\n'); 1777 putc_code(fp, '\n');
1777 putl_code(fp, "/* Parameters sent to yyerror. */\n"); 1778 putl_code(fp, "/* Parameters sent to yyerror. */\n");
1778 putl_code(fp, "#ifndef YYERROR_DECL\n"); 1779 putl_code(fp, "#ifndef YYERROR_DECL\n");
1779 puts_code(fp, "#define YYERROR_DECL() yyerror("); 1780 puts_code(fp, "#define YYERROR_DECL() yyerror(");
1780#if defined(YYBTYACC) 1781#if defined(YYBTYACC)
1781 if (locations) 1782 if (locations)
1782 puts_code(fp, "YYLTYPE *loc, "); 1783 puts_code(fp, "YYLTYPE *loc, ");
1783#endif 1784#endif
1784 puts_param_types(fp, parse_param, 1); 1785 puts_param_types(fp, parse_param, 1);
1785 putl_code(fp, "const char *s)\n"); 1786 putl_code(fp, "const char *s)\n");
1786 putl_code(fp, "#endif\n"); 1787 putl_code(fp, "#endif\n");
1787 1788
1788 putl_code(fp, "#ifndef YYERROR_CALL\n"); 1789 putl_code(fp, "#ifndef YYERROR_CALL\n");
1789 1790
1790 puts_code(fp, "#define YYERROR_CALL(msg) yyerror("); 1791 puts_code(fp, "#define YYERROR_CALL(msg) yyerror(");
1791#if defined(YYBTYACC) 1792#if defined(YYBTYACC)
1792 if (locations) 1793 if (locations)
1793 puts_code(fp, "&yylloc, "); 1794 puts_code(fp, "&yylloc, ");
1794#endif 1795#endif
1795 puts_param_names(fp, parse_param, 1); 1796 puts_param_names(fp, parse_param, 1);
1796 putl_code(fp, "msg)\n"); 1797 putl_code(fp, "msg)\n");
1797 1798
1798 putl_code(fp, "#endif\n"); 1799 putl_code(fp, "#endif\n");
1799} 1800}
1800 1801
1801#if defined(YYBTYACC) 1802#if defined(YYBTYACC)
1802static void 1803static void
1803output_yydestruct_decl(FILE * fp) 1804output_yydestruct_decl(FILE * fp)
1804{ 1805{
1805 putc_code(fp, '\n'); 1806 putc_code(fp, '\n');
1806 putl_code(fp, "#ifndef YYDESTRUCT_DECL\n"); 1807 putl_code(fp, "#ifndef YYDESTRUCT_DECL\n");
1807 1808
1808 puts_code(fp, 1809 puts_code(fp,
1809 "#define YYDESTRUCT_DECL() " 1810 "#define YYDESTRUCT_DECL() "
1810 "yydestruct(const char *msg, int psymb, YYSTYPE *val"); 1811 "yydestruct(const char *msg, int psymb, YYSTYPE *val");
1811#if defined(YYBTYACC) 1812#if defined(YYBTYACC)
1812 if (locations) 1813 if (locations)
1813 puts_code(fp, ", YYLTYPE *loc"); 1814 puts_code(fp, ", YYLTYPE *loc");
1814#endif 1815#endif
1815 if (parse_param) 1816 if (parse_param)
1816 { 1817 {
1817 puts_code(fp, ", "); 1818 puts_code(fp, ", ");
1818 puts_param_types(fp, parse_param, 0); 1819 puts_param_types(fp, parse_param, 0);
1819 } 1820 }
1820 putl_code(fp, ")\n"); 1821 putl_code(fp, ")\n");
1821 1822
1822 putl_code(fp, "#endif\n"); 1823 putl_code(fp, "#endif\n");
1823 1824
1824 putl_code(fp, "#ifndef YYDESTRUCT_CALL\n"); 1825 putl_code(fp, "#ifndef YYDESTRUCT_CALL\n");
1825 1826
1826 puts_code(fp, "#define YYDESTRUCT_CALL(msg, psymb, val"); 1827 puts_code(fp, "#define YYDESTRUCT_CALL(msg, psymb, val");
1827#if defined(YYBTYACC) 1828#if defined(YYBTYACC)
1828 if (locations) 1829 if (locations)
1829 puts_code(fp, ", loc"); 1830 puts_code(fp, ", loc");
1830#endif 1831#endif
1831 puts_code(fp, ") yydestruct(msg, psymb, val"); 1832 puts_code(fp, ") yydestruct(msg, psymb, val");
1832#if defined(YYBTYACC) 1833#if defined(YYBTYACC)
1833 if (locations) 1834 if (locations)
1834 puts_code(fp, ", loc"); 1835 puts_code(fp, ", loc");
1835#endif 1836#endif
1836 if (parse_param) 1837 if (parse_param)
1837 { 1838 {
1838 puts_code(fp, ", "); 1839 puts_code(fp, ", ");
1839 puts_param_names(fp, parse_param, 0); 1840 puts_param_names(fp, parse_param, 0);
1840 } 1841 }
1841 putl_code(fp, ")\n"); 1842 putl_code(fp, ")\n");
1842 1843
1843 putl_code(fp, "#endif\n"); 1844 putl_code(fp, "#endif\n");
1844} 1845}
1845 1846
1846static void 1847static void
1847output_initial_action(void) 1848output_initial_action(void)
1848{ 1849{
1849 if (initial_action) 1850 if (initial_action)
1850 fprintf(code_file, "%s\n", initial_action); 1851 fprintf(code_file, "%s\n", initial_action);
1851} 1852}
1852 1853
1853static void 1854static void
1854output_yydestruct_impl(void) 1855output_yydestruct_impl(void)
1855{ 1856{
1856 int i; 1857 int i;
1857 char *s, *destructor_code; 1858 char *s, *destructor_code;
1858 1859
1859 putc_code(code_file, '\n'); 1860 putc_code(code_file, '\n');
1860 putl_code(code_file, "/* Release memory associated with symbol. */\n"); 1861 putl_code(code_file, "/* Release memory associated with symbol. */\n");
1861 putl_code(code_file, "#if ! defined YYDESTRUCT_IS_DECLARED\n"); 1862 putl_code(code_file, "#if ! defined YYDESTRUCT_IS_DECLARED\n");
1862 putl_code(code_file, "static void\n"); 1863 putl_code(code_file, "static void\n");
1863 putl_code(code_file, "YYDESTRUCT_DECL()\n"); 1864 putl_code(code_file, "YYDESTRUCT_DECL()\n");
1864 putl_code(code_file, "{\n"); 1865 putl_code(code_file, "{\n");
1865 putl_code(code_file, " switch (psymb)\n"); 1866 putl_code(code_file, " switch (psymb)\n");
1866 putl_code(code_file, " {\n"); 1867 putl_code(code_file, " {\n");
1867 for (i = 2; i < nsyms; ++i) 1868 for (i = 2; i < nsyms; ++i)
1868 { 1869 {
1869 if ((destructor_code = symbol_destructor[i]) != NULL) 1870 if ((destructor_code = symbol_destructor[i]) != NULL)
1870 { 1871 {
1871 ++outline; 1872 ++outline;
1872 fprintf(code_file, "\tcase %d:\n", symbol_pval[i]); 1873 fprintf(code_file, "\tcase %d:\n", symbol_pval[i]);
1873 /* comprehend the number of lines in the destructor code */ 1874 /* comprehend the number of lines in the destructor code */
1874 for (s = destructor_code; (s = strchr(s, '\n')) != NULL; s++) 1875 for (s = destructor_code; (s = strchr(s, '\n')) != NULL; s++)
1875 ++outline; 1876 ++outline;
1876 puts_code(code_file, destructor_code); 1877 puts_code(code_file, destructor_code);
1877 putc_code(code_file, '\n'); 1878 putc_code(code_file, '\n');
1878 putl_code(code_file, "\tbreak;\n"); 1879 putl_code(code_file, "\tbreak;\n");
1879 write_code_lineno(code_file); 1880 write_code_lineno(code_file);
1880 FREE(destructor_code); 1881 FREE(destructor_code);
1881 } 1882 }
1882 } 1883 }
1883 putl_code(code_file, " }\n"); 1884 putl_code(code_file, " }\n");
1884 putl_code(code_file, "}\n"); 1885 putl_code(code_file, "}\n");
1885 putl_code(code_file, "#define YYDESTRUCT_IS_DECLARED 1\n"); 1886 putl_code(code_file, "#define YYDESTRUCT_IS_DECLARED 1\n");
1886 putl_code(code_file, "#endif\n"); 1887 putl_code(code_file, "#endif\n");
1887 1888
1888 DO_FREE(symbol_destructor); 1889 DO_FREE(symbol_destructor);
1889} 1890}
1890#endif 1891#endif
1891 1892
1892static void 1893static void
1893free_itemsets(void) 1894free_itemsets(void)
1894{ 1895{
1895 core *cp, *next; 1896 core *cp, *next;
1896 1897
1897 FREE(state_table); 1898 FREE(state_table);
1898 for (cp = first_state; cp; cp = next) 1899 for (cp = first_state; cp; cp = next)
1899 { 1900 {
1900 next = cp->next; 1901 next = cp->next;
1901 FREE(cp); 1902 FREE(cp);
1902 } 1903 }
1903} 1904}
1904 1905
1905static void 1906static void
1906free_shifts(void) 1907free_shifts(void)
1907{ 1908{
1908 shifts *sp, *next; 1909 shifts *sp, *next;
1909 1910
1910 FREE(shift_table); 1911 FREE(shift_table);
1911 for (sp = first_shift; sp; sp = next) 1912 for (sp = first_shift; sp; sp = next)
1912 { 1913 {
1913 next = sp->next; 1914 next = sp->next;
1914 FREE(sp); 1915 FREE(sp);
1915 } 1916 }
1916} 1917}
1917 1918
1918static void 1919static void
1919free_reductions(void) 1920free_reductions(void)
1920{ 1921{
1921 reductions *rp, *next; 1922 reductions *rp, *next;
1922 1923
1923 FREE(reduction_table); 1924 FREE(reduction_table);
1924 for (rp = first_reduction; rp; rp = next) 1925 for (rp = first_reduction; rp; rp = next)
1925 { 1926 {
1926 next = rp->next; 1927 next = rp->next;
1927 FREE(rp); 1928 FREE(rp);
1928 } 1929 }
1929} 1930}
1930 1931
1931static void 1932static void
1932output_externs(FILE * fp, const char *const section[]) 1933output_externs(FILE * fp, const char *const section[])
1933{ 1934{
1934 int i; 1935 int i;
1935 const char *s; 1936 const char *s;
1936 1937
1937 for (i = 0; (s = section[i]) != 0; ++i) 1938 for (i = 0; (s = section[i]) != 0; ++i)
1938 { 1939 {
1939 /* prefix non-blank lines that don't start with 1940 /* prefix non-blank lines that don't start with
1940 C pre-processor directives with 'extern ' */ 1941 C pre-processor directives with 'extern ' */
1941 if (*s && (*s != '#')) 1942 if (*s && (*s != '#'))
1942 fputs("extern\t", fp); 1943 fputs("extern\t", fp);
1943 if (fp == code_file) 1944 if (fp == code_file)
1944 ++outline; 1945 ++outline;
1945 fprintf(fp, "%s\n", s); 1946 fprintf(fp, "%s\n", s);
1946 } 1947 }
1947} 1948}
1948 1949
1949void 1950void
1950output(void) 1951output(void)
1951{ 1952{
1952 FILE *fp; 1953 FILE *fp;
1953 1954
1954 free_itemsets(); 1955 free_itemsets();
1955 free_shifts(); 1956 free_shifts();
1956 free_reductions(); 1957 free_reductions();
1957 1958
1958#if defined(YYBTYACC) 1959#if defined(YYBTYACC)
1959 output_backtracking_parser(output_file); 1960 output_backtracking_parser(output_file);
1960 if (rflag) 1961 if (rflag)
1961 output_backtracking_parser(code_file); 1962 output_backtracking_parser(code_file);
1962#endif 1963#endif
1963 1964
1964 if (iflag) 1965 if (iflag)
1965 { 1966 {
1966 write_code_lineno(code_file); 1967 write_code_lineno(code_file);
1967 ++outline; 1968 ++outline;
1968 fprintf(code_file, "#include \"%s\"\n", externs_file_name); 1969 fprintf(code_file, "#include \"%s\"\n", externs_file_name);
1969 fp = externs_file; 1970 fp = externs_file;
1970 } 1971 }
1971 else 1972 else
1972 fp = code_file; 1973 fp = code_file;
1973 1974
1974 output_prefix(fp); 1975 output_prefix(fp);
1975 output_pure_parser(fp); 1976 output_pure_parser(fp);
1976 output_stored_text(fp); 1977 output_stored_text(fp);
1977 output_stype(fp); 1978 output_stype(fp);
1978#if defined(YYBTYACC) 1979#if defined(YYBTYACC)
1979 if (locations) 1980 if (locations)
1980 output_ltype(fp); 1981 output_ltype(fp);
1981#endif 1982#endif
1982 output_parse_decl(fp); 1983 output_parse_decl(fp);
1983 output_lex_decl(fp); 1984 output_lex_decl(fp);
1984 output_error_decl(fp); 1985 output_error_decl(fp);
1985#if defined(YYBTYACC) 1986#if defined(YYBTYACC)
1986 if (destructor) 1987 if (destructor)
1987 output_yydestruct_decl(fp); 1988 output_yydestruct_decl(fp);
1988#endif 1989#endif
1989 if (iflag || !rflag) 1990 if (iflag || !rflag)
1990 { 1991 {
1991 write_section(fp, xdecls); 1992 write_section(fp, xdecls);
1992 } 1993 }
1993 1994
1994 if (iflag) 1995 if (iflag)
1995 { 1996 {
1996 output_externs(externs_file, global_vars); 1997 output_externs(externs_file, global_vars);
1997 if (!pure_parser) 1998 if (!pure_parser)
1998 output_externs(externs_file, impure_vars); 1999 output_externs(externs_file, impure_vars);
1999 } 2000 }
2000 2001
2001 if (iflag) 2002 if (iflag)
2002 { 2003 {
2003 if (dflag) 2004 if (dflag)
2004 { 2005 {
2005 ++outline; 2006 ++outline;
2006 fprintf(code_file, "#include \"%s\"\n", defines_file_name); 2007 fprintf(code_file, "#include \"%s\"\n", defines_file_name);
2007 } 2008 }
2008 else 2009 else
2009 output_defines(externs_file); 2010 output_defines(externs_file);
2010 } 2011 }
2011 else 2012 else
2012 { 2013 {
2013 putc_code(code_file, '\n'); 2014 putc_code(code_file, '\n');
2014 output_defines(code_file); 2015 output_defines(code_file);
2015 } 2016 }
2016 2017
2017 if (dflag) 2018 if (dflag)
2018 { 2019 {
2019 start_defines_file(); 2020 start_defines_file();
2020 output_defines(defines_file); 2021 output_defines(defines_file);
2021 end_defines_file(); 2022 end_defines_file();
2022 } 2023 }
2023 2024
2024 output_rule_data(); 2025 output_rule_data();
2025 output_yydefred(); 2026 output_yydefred();
2026#if defined(YYBTYACC) 2027#if defined(YYBTYACC)
2027 output_accessing_symbols(); 2028 output_accessing_symbols();
2028#endif 2029#endif
2029 output_actions(); 2030 output_actions();
2030 free_parser(); 2031 free_parser();
2031 output_debug(); 2032 output_debug();
2032 if (rflag) 2033 if (rflag)
2033 { 2034 {
2034 write_section(code_file, xdecls); 2035 write_section(code_file, xdecls);
2035 output_YYINT_typedef(code_file); 2036 output_YYINT_typedef(code_file);
2036 write_section(code_file, tables); 2037 write_section(code_file, tables);
2037 } 2038 }
2038 write_section(code_file, global_vars); 2039 write_section(code_file, global_vars);
2039 if (!pure_parser) 2040 if (!pure_parser)
2040 { 2041 {
2041 write_section(code_file, impure_vars); 2042 write_section(code_file, impure_vars);
2042 } 2043 }
2043 write_section(code_file, hdr_defs); 2044 write_section(code_file, hdr_defs);
2044 if (!pure_parser) 2045 if (!pure_parser)
2045 { 2046 {
2046 write_section(code_file, hdr_vars); 2047 write_section(code_file, hdr_vars);
2047 } 2048 }
2048 output_trailing_text(); 2049 output_trailing_text();
2049#if defined(YYBTYACC) 2050#if defined(YYBTYACC)
2050 if (destructor) 2051 if (destructor)
2051 output_yydestruct_impl(); 2052 output_yydestruct_impl();
2052#endif 2053#endif
2053 write_section(code_file, body_1); 2054 write_section(code_file, body_1);
2054 if (pure_parser) 2055 if (pure_parser)
2055 { 2056 {
2056 write_section(code_file, body_vars); 2057 write_section(code_file, body_vars);
2057 } 2058 }
2058 write_section(code_file, body_2); 2059 write_section(code_file, body_2);
2059#if defined(YYBTYACC) 2060#if defined(YYBTYACC)
2060 if (initial_action) 2061 if (initial_action)
2061 output_initial_action(); 2062 output_initial_action();
2062#endif 2063#endif
2063 write_section(code_file, body_3); 2064 write_section(code_file, body_3);
2064 output_semantic_actions(); 2065 output_semantic_actions();
2065 write_section(code_file, trailer); 2066 write_section(code_file, trailer);
2066} 2067}
2067 2068
2068#ifdef NO_LEAKS 2069#ifdef NO_LEAKS
2069void 2070void
2070output_leaks(void) 2071output_leaks(void)
2071{ 2072{
2072 DO_FREE(tally); 2073 DO_FREE(tally);
2073 DO_FREE(width); 2074 DO_FREE(width);
2074 DO_FREE(order); 2075 DO_FREE(order);
2075} 2076}
2076#endif 2077#endif