]>
git.saurik.com Git - bison.git/blob - src/output.c
308ad8d0b1bde451f9e67514d5dc663832ccad2a
1 /* Output the generated parsing program for bison,
2 Copyright 1984, 1986, 1989, 1992, 2000, 2001 Free Software Foundation, Inc.
4 This file is part of Bison, the GNU Compiler Compiler.
6 Bison is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 Bison is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Bison; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* The parser tables consist of these tables.
23 Starred ones needed only for the semantic parser.
24 Double starred are output only if switches are set.
26 yytranslate = vector mapping yylex's token numbers into bison's token
29 ** yytname = vector of string-names indexed by bison token number
31 ** yytoknum = vector of yylex token numbers corresponding to entries
34 yyrline = vector of line-numbers of all rules. For yydebug printouts.
36 yyrhs = vector of items of all rules.
37 This is exactly what ritems contains. For yydebug and for semantic
40 yyprhs[r] = index in yyrhs of first item for rule r.
42 yyr1[r] = symbol number of symbol that rule r derives.
44 yyr2[r] = number of symbols composing right hand side of rule r.
46 * yystos[s] = the symbol number of the symbol that leads to state s.
48 yydefact[s] = default rule to reduce with in state s,
49 when yytable doesn't specify something else to do.
50 Zero means the default is an error.
52 yydefgoto[i] = default state to go to after a reduction of a rule that
53 generates variable ntokens + i, except when yytable
54 specifies something else to do.
56 yypact[s] = index in yytable of the portion describing state s.
57 The lookahead token's type is used to index that portion
58 to find out what to do.
60 If the value in yytable is positive,
61 we shift the token and go to that state.
63 If the value is negative, it is minus a rule number to reduce by.
65 If the value is zero, the default action from yydefact[s] is used.
67 yypgoto[i] = the index in yytable of the portion describing
68 what to do after reducing a rule that derives variable i + ntokens.
69 This portion is indexed by the parser state number, s,
70 as of before the text for this nonterminal was read.
71 The value from yytable is the state to go to if
72 the corresponding value in yycheck is s.
74 yytable = a vector filled with portions for different uses,
75 found via yypact and yypgoto.
77 yycheck = a vector indexed in parallel with yytable.
78 It indicates, in a roundabout way, the bounds of the
79 portion you are trying to examine.
81 Suppose that the portion of yytable starts at index p
82 and the index to be examined within the portion is i.
83 Then if yycheck[p+i] != i, i is outside the bounds
84 of what is actually allocated, and the default
85 (from yydefact or yydefgoto) should be used.
86 Otherwise, yytable[p+i] should be used.
88 YYFINAL = the state number of the termination state.
89 YYFLAG = most negative short int. Used to flag ??
100 #include "complain.h"
104 #include "conflicts.h"
106 extern void berror
PARAMS((const char *));
112 static short **froms
= NULL
;
113 static short **tos
= NULL
;
114 static short *tally
= NULL
;
115 static short *width
= NULL
;
116 static short *actrow
= NULL
;
117 static short *state_count
= NULL
;
118 static short *order
= NULL
;
119 static short *base
= NULL
;
120 static short *pos
= NULL
;
121 static short *table
= NULL
;
122 static short *check
= NULL
;
129 output_short_or_char_table (struct obstack
*oout
,
132 const char *table_name
,
135 short begin
, short end
)
140 obstack_fgrow1 (oout
, "/* %s. */\n", comment
);
142 obstack_fgrow3 (oout
, "static const %s %s[] =\n{\n %6d",
143 type
, table_name
, first_value
);
146 for (i
= begin
; i
< end
; i
++)
148 obstack_1grow (oout
, ',');
152 obstack_sgrow (oout
, "\n ");
160 obstack_fgrow1 (oout
, "%6d", short_table
[i
]);
163 obstack_sgrow (oout
, "\n};\n");
168 output_short_table (struct obstack
*oout
,
170 const char *table_name
,
173 short begin
, short end
)
175 output_short_or_char_table (oout
, comment
, "short", table_name
, short_table
,
176 first_value
, begin
, end
);
180 /*--------------------------------------------------------------.
181 | output_headers -- Output constant strings to the beginning of |
183 `--------------------------------------------------------------*/
185 /* Don't put the `%s' insides quotes, since it quotearg puts them. */
190 extern int yyerror;\n\
191 extern int yycost;\n\
192 extern char * yymsg;\n\
193 extern YYSTYPE yyval;\n\
195 yyguard(n, yyvsp, yylsp)\n\
197 register YYSTYPE *yyvsp;\n\
198 register YYLTYPE *yylsp;\n\
209 extern YYSTYPE yyval;\n\
210 extern int yychar;\n\
212 yyaction(n, yyvsp, yylsp)\n\
214 register YYSTYPE *yyvsp;\n\
215 register YYLTYPE *yylsp;\n\
220 #define ACTSTR_SIMPLE "\n switch (yyn) {\n"
223 output_headers (void)
225 char *attrsfile_quoted
= 0;
229 /* FIXME: This is *buggy*. ATTRSFILE is not computed yet, since
230 we are waiting for the full input file to have been read to
231 be sure of the output file name. So basically, here, a SEGV
232 is guaranteed. OTOH, currently semantic parsers are not
234 attrsfile_quoted
= quotearg_style (c_quoting_style
, attrsfile
);
235 obstack_fgrow1 (&guard_obstack
, GUARDSTR
, attrsfile_quoted
);
242 obstack_fgrow1 (&action_obstack
, ACTSTR
, attrsfile_quoted
);
244 obstack_sgrow (&action_obstack
, ACTSTR_SIMPLE
);
246 /* Rename certain symbols if -p was specified. */
247 if (spec_name_prefix
)
249 obstack_fgrow1 (&table_obstack
,
250 "#define yyparse %sparse\n", spec_name_prefix
);
251 obstack_fgrow1 (&table_obstack
,
252 "#define yylex %slex\n", spec_name_prefix
);
253 obstack_fgrow1 (&table_obstack
,
254 "#define yyerror %serror\n", spec_name_prefix
);
255 obstack_fgrow1 (&table_obstack
,
256 "#define yylval %slval\n", spec_name_prefix
);
257 obstack_fgrow1 (&table_obstack
,
258 "#define yychar %schar\n", spec_name_prefix
);
259 obstack_fgrow1 (&table_obstack
,
260 "#define yydebug %sdebug\n", spec_name_prefix
);
261 obstack_fgrow1 (&table_obstack
,
262 "#define yynerrs %snerrs\n", spec_name_prefix
);
267 /*-------------------------------------------------------.
268 | Output constant strings to the ends of certain files. |
269 `-------------------------------------------------------*/
272 output_trailers (void)
275 obstack_sgrow (&guard_obstack
, "\n }\n}\n");
277 obstack_1grow (&action_obstack
, '\n');
283 obstack_sgrow (&action_obstack
, " }\n");
285 obstack_sgrow (&action_obstack
, "}\n");
291 output_token_translations (void)
293 obstack_sgrow (&table_obstack
, "\
295 /* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */\n");
297 obstack_fgrow2 (&table_obstack
,
298 "#define YYTRANSLATE(x) ((unsigned)(x) <= %d ? yytranslate[x] : %d)\
301 max_user_token_number
, nsyms
);
303 output_short_or_char_table (&table_obstack
,
304 "YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX",
305 ntokens
< 127 ? "char" : "short",
306 "yytranslate", token_translations
,
307 0, 1, max_user_token_number
+ 1);
309 XFREE (token_translations
);
316 /* With the ordinary parser,
317 yyprhs and yyrhs are needed only for yydebug. */
318 /* With the no_parser option, all tables are generated */
319 if (!semantic_parser
&& !no_parser_flag
)
320 obstack_sgrow (&table_obstack
, "\n#if YYDEBUG != 0\n");
324 short *values
= XCALLOC (short, nrules
+ 1);
325 for (i
= 0; i
< nrules
+ 1; ++i
)
326 values
[i
] = rule_table
[i
].rhs
;
327 output_short_table (&table_obstack
, NULL
, "yyprhs", values
,
333 size_t yyrhs_size
= 1;
337 for (sp
= ritem
+ 1; *sp
; sp
++)
339 yyrhs
= XMALLOC (short, yyrhs_size
);
341 for (sp
= ritem
+ 1, i
= 1; *sp
; ++sp
, ++i
)
342 yyrhs
[i
] = *sp
> 0 ? *sp
: 0;
344 output_short_table (&table_obstack
, NULL
, "yyrhs", yyrhs
,
345 ritem
[0], 1, yyrhs_size
);
349 if (!semantic_parser
&& !no_parser_flag
)
350 obstack_sgrow (&table_obstack
, "\n#endif\n");
358 short *values
= (short *) alloca (sizeof (short) * nstates
);
359 for (i
= 0; i
< nstates
; ++i
)
360 values
[i
] = state_table
[i
].accessing_symbol
;
361 output_short_table (&table_obstack
,
362 "YYSTOS[STATE] -- Accessing symbol to the STATE",
369 output_rule_data (void)
373 short *short_tab
= NULL
;
375 obstack_sgrow (&table_obstack
, "\n\
376 #if YYDEBUG != 0\n");
379 short *values
= XCALLOC (short, nrules
+ 1);
380 for (i
= 0; i
< nrules
+ 1; ++i
)
381 values
[i
] = rule_table
[i
].line
;
382 output_short_table (&table_obstack
,
383 "YYRLINE[YYN] -- source line where rule number YYN was defined",
389 obstack_sgrow (&table_obstack
, "#endif\n\n");
391 if (token_table_flag
|| no_parser_flag
)
393 obstack_fgrow1 (&table_obstack
, "#define YYNTOKENS %d\n", ntokens
);
394 obstack_fgrow1 (&table_obstack
, "#define YYNNTS %d\n", nvars
);
395 obstack_fgrow1 (&table_obstack
, "#define YYNRULES %d\n", nrules
);
396 obstack_fgrow1 (&table_obstack
, "#define YYNSTATES %d\n", nstates
);
397 obstack_fgrow1 (&table_obstack
, "#define YYMAXUTOK %d\n\n",
398 max_user_token_number
);
401 /* Output the table of symbol names. */
402 if (!token_table_flag
&& !no_parser_flag
)
403 obstack_sgrow (&table_obstack
,
404 "\n#if YYDEBUG != 0 || defined YYERROR_VERBOSE\n\n");
405 obstack_sgrow (&table_obstack
, "\
406 /* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */\n");
407 obstack_sgrow (&table_obstack
,
408 "static const char *const yytname[] =\n{\n ");
411 for (i
= 0; i
< nsyms
; i
++)
412 /* this used to be i<=nsyms, but that output a final "" symbol
413 almost by accident */
415 /* Width of the next token, including the two quotes, the coma
420 for (p
= tags
[i
]; p
&& *p
; p
++)
421 if (*p
== '"' || *p
== '\\' || *p
== '\n' || *p
== '\t'
424 else if (*p
< 040 || *p
>= 0177)
429 if (j
+ strsize
> 75)
431 obstack_sgrow (&table_obstack
, "\n ");
435 obstack_1grow (&table_obstack
, '\"');
436 for (p
= tags
[i
]; p
&& *p
; p
++)
438 if (*p
== '"' || *p
== '\\')
439 obstack_fgrow1 (&table_obstack
, "\\%c", *p
);
441 obstack_sgrow (&table_obstack
, "\\n");
443 obstack_sgrow (&table_obstack
, "\\t");
445 obstack_sgrow (&table_obstack
, "\\b");
446 else if (*p
< 040 || *p
>= 0177)
447 obstack_fgrow1 (&table_obstack
, "\\%03o", *p
);
449 obstack_1grow (&table_obstack
, *p
);
452 obstack_sgrow (&table_obstack
, "\", ");
455 /* add a NULL entry to list of tokens */
456 obstack_sgrow (&table_obstack
, "NULL\n};\n");
458 if (!token_table_flag
&& !no_parser_flag
)
459 obstack_sgrow (&table_obstack
, "#endif\n\n");
461 /* Output YYTOKNUM. */
462 if (token_table_flag
)
464 output_short_table (&table_obstack
,
465 "YYTOKNUM[YYLEX] -- Index in YYTNAME corresponding to YYLEX",
466 "yytoknum", user_toknums
,
472 short *values
= XCALLOC (short, nrules
+ 1);
473 for (i
= 0; i
< nrules
+ 1; ++i
)
474 values
[i
] = rule_table
[i
].lhs
;
475 output_short_table (&table_obstack
,
476 "YYR1[YYN] -- Symbol number of symbol that rule YYN derives",
482 obstack_1grow (&table_obstack
, '\n');
485 short_tab
= XMALLOC (short, nrules
+ 1);
486 for (i
= 1; i
< nrules
; i
++)
487 short_tab
[i
] = rule_table
[i
+ 1].rhs
- rule_table
[i
].rhs
- 1;
488 short_tab
[nrules
] = nitems
- rule_table
[nrules
].rhs
- 1;
489 output_short_table (&table_obstack
,
490 "YYR2[YYN] -- Number of symbols composing right hand side of rule YYN",
493 obstack_1grow (&table_obstack
, '\n');
497 XFREE (rule_table
+ 1);
502 output_defines (void)
504 obstack_fgrow1 (&table_obstack
, "\n\n#define\tYYFINAL\t\t%d\n", final_state
);
505 obstack_fgrow1 (&table_obstack
, "#define\tYYFLAG\t\t%d\n", MINSHORT
);
506 obstack_fgrow1 (&table_obstack
, "#define\tYYNTBASE\t%d\n", ntokens
);
510 /*------------------------------------------------------------------.
511 | Decide what to do for each type of token if seen as the lookahead |
512 | token in specified state. The value returned is used as the |
513 | default action (yydefact) for the state. In addition, actrow is |
514 | filled with what to do for each kind of token, index by symbol |
515 | number, with zero meaning do the default action. The value |
516 | MINSHORT, a very negative number, means this situation is an |
517 | error. The parser recognizes this value specially. |
519 | This is where conflicts are resolved. The loop over lookahead |
520 | rules considered lower-numbered rules last, and the last rule |
521 | considered that likes a token gets to handle it. |
522 `------------------------------------------------------------------*/
525 action_row (int state
)
544 int nodefault
= 0; /* set nonzero to inhibit having any default reduction */
546 for (i
= 0; i
< ntokens
; i
++)
551 redp
= state_table
[state
].reduction_table
;
559 /* loop over all the rules available here which require
561 m
= state_table
[state
].lookaheads
;
562 n
= state_table
[state
+ 1].lookaheads
;
564 for (i
= n
- 1; i
>= m
; i
--)
570 /* and find each token which the rule finds acceptable
572 for (j
= 0; j
< ntokens
; j
++)
574 /* and record this rule as the rule to use if that
590 shiftp
= state_table
[state
].shift_table
;
592 /* Now see which tokens are allowed for shifts in this state. For
593 them, record the shift as the thing to do. So shift is preferred
600 for (i
= 0; i
< k
; i
++)
602 shift_state
= shiftp
->shifts
[i
];
606 symbol
= state_table
[shift_state
].accessing_symbol
;
611 actrow
[symbol
] = shift_state
;
613 /* Do not use any default reduction if there is a shift for
615 if (symbol
== error_token_number
)
620 errp
= err_table
[state
];
622 /* See which tokens are an explicit error in this state (due to
623 %nonassoc). For them, record MINSHORT as the action. */
629 for (i
= 0; i
< k
; i
++)
631 symbol
= errp
->errs
[i
];
632 actrow
[symbol
] = MINSHORT
;
636 /* Now find the most common reduction and make it the default action
639 if (nreds
>= 1 && !nodefault
)
641 if (state_table
[state
].consistent
)
642 default_rule
= redp
->rules
[0];
646 for (i
= m
; i
< n
; i
++)
651 for (j
= 0; j
< ntokens
; j
++)
653 if (actrow
[j
] == rule
)
664 /* actions which match the default are replaced with zero,
665 which means "use the default" */
669 for (j
= 0; j
< ntokens
; j
++)
671 if (actrow
[j
] == default_rule
)
675 default_rule
= -default_rule
;
680 /* If have no default rule, the default is an error.
681 So replace any action which says "error" with "use default". */
683 if (default_rule
== 0)
684 for (j
= 0; j
< ntokens
; j
++)
686 if (actrow
[j
] == MINSHORT
)
704 for (i
= 0; i
< ntokens
; i
++)
713 froms
[state
] = sp1
= sp
= XCALLOC (short, count
);
714 tos
[state
] = sp2
= XCALLOC (short, count
);
716 for (i
= 0; i
< ntokens
; i
++)
725 tally
[state
] = count
;
726 width
[state
] = sp1
[-1] - sp
[0] + 1;
730 /*------------------------------------------------------------------.
731 | Figure out the actions for the specified state, indexed by |
732 | lookahead token type. |
734 | The YYDEFACT table is output now. The detailed info is saved for |
735 | putting into YYTABLE later. |
736 `------------------------------------------------------------------*/
742 short *yydefact
= XCALLOC (short, nstates
);
744 actrow
= XCALLOC (short, ntokens
);
745 for (i
= 0; i
< nstates
; ++i
)
747 yydefact
[i
] = action_row (i
);
752 output_short_table (&table_obstack
,
753 "YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE\n\
754 doesn't specify something else to do. Zero means the default is an\n\
756 "yydefact", yydefact
,
757 yydefact
[0], 1, nstates
);
758 obstack_1grow (&table_obstack
, '\n');
766 shifts
*sp
, *sptmp
; /* JF derefrenced freed ptr */
768 for (sp
= first_shift
; sp
; sp
= sptmp
)
777 free_reductions (void)
779 reductions
*rp
, *rptmp
; /* JF fixed freed ptr */
781 for (rp
= first_reduction
; rp
; rp
= rptmp
)
791 save_column (int symbol
, int default_state
)
800 short begin
= goto_map
[symbol
];
801 short end
= goto_map
[symbol
+ 1];
804 for (i
= begin
; i
< end
; i
++)
806 if (to_state
[i
] != default_state
)
813 symno
= symbol
- ntokens
+ nstates
;
815 froms
[symno
] = sp1
= sp
= XCALLOC (short, count
);
816 tos
[symno
] = sp2
= XCALLOC (short, count
);
818 for (i
= begin
; i
< end
; i
++)
820 if (to_state
[i
] != default_state
)
822 *sp1
++ = from_state
[i
];
823 *sp2
++ = to_state
[i
];
827 tally
[symno
] = count
;
828 width
[symno
] = sp1
[-1] - sp
[0] + 1;
832 default_goto (int symbol
)
840 m
= goto_map
[symbol
];
841 n
= goto_map
[symbol
+ 1];
846 for (i
= 0; i
< nstates
; i
++)
849 for (i
= m
; i
< n
; i
++)
850 state_count
[to_state
[i
]]++;
855 for (i
= 0; i
< nstates
; i
++)
857 if (state_count
[i
] > max
)
859 max
= state_count
[i
];
864 return default_state
;
868 /*-------------------------------------------------------------------.
869 | Figure out what to do after reducing with each rule, depending on |
870 | the saved state from before the beginning of parsing the data that |
871 | matched this rule. |
873 | The YYDEFGOTO table is output now. The detailed info is saved for |
874 | putting into YYTABLE later. |
875 `-------------------------------------------------------------------*/
882 short *yydefgoto
= XMALLOC (short, nsyms
- ntokens
);
883 state_count
= XCALLOC (short, nstates
);
885 for (i
= ntokens
; i
< nsyms
; ++i
)
887 int default_state
= default_goto (i
);
888 save_column (i
, default_state
);
889 yydefgoto
[i
- ntokens
] = default_state
;
892 output_short_table (&table_obstack
, NULL
, "yydefgoto", yydefgoto
,
893 yydefgoto
[0], 1, nsyms
- ntokens
);
900 /* The next few functions decide how to pack the actions and gotos
901 information into yytable. */
912 order
= XCALLOC (short, nvectors
);
915 for (i
= 0; i
< nvectors
; i
++)
923 while (j
>= 0 && (width
[order
[j
]] < w
))
926 while (j
>= 0 && (width
[order
[j
]] == w
) && (tally
[order
[j
]] < t
))
929 for (k
= nentries
- 1; k
> j
; k
--)
930 order
[k
+ 1] = order
[k
];
940 matching_state (int vector
)
957 for (prev
= vector
- 1; prev
>= 0; prev
--)
960 if (width
[j
] != w
|| tally
[j
] != t
)
964 for (k
= 0; match
&& k
< t
; k
++)
966 if (tos
[j
][k
] != tos
[i
][k
] || froms
[j
][k
] != froms
[i
][k
])
979 pack_vector (int vector
)
998 for (j
= lowzero
- from
[0]; j
< MAXTABLE
; j
++)
1002 for (k
= 0; ok
&& k
< t
; k
++)
1006 fatal (_("maximum table size (%d) exceeded"), MAXTABLE
);
1008 if (table
[loc
] != 0)
1012 for (k
= 0; ok
&& k
< vector
; k
++)
1020 for (k
= 0; k
< t
; k
++)
1024 check
[loc
] = from
[k
];
1027 while (table
[lowzero
] != 0)
1037 berror ("pack_vector");
1038 return 0; /* JF keep lint happy */
1049 base
= XCALLOC (short, nvectors
);
1050 pos
= XCALLOC (short, nentries
);
1051 table
= XCALLOC (short, MAXTABLE
);
1052 check
= XCALLOC (short, MAXTABLE
);
1057 for (i
= 0; i
< nvectors
; i
++)
1060 for (i
= 0; i
< MAXTABLE
; i
++)
1063 for (i
= 0; i
< nentries
; i
++)
1065 state
= matching_state (i
);
1068 place
= pack_vector (i
);
1070 place
= base
[state
];
1073 base
[order
[i
]] = place
;
1076 for (i
= 0; i
< nvectors
; i
++)
1089 /* the following functions output yytable, yycheck
1090 and the vectors whose elements index the portion starts */
1095 output_short_table (&table_obstack
, NULL
, "yypact", base
,
1096 base
[0], 1, nstates
);
1098 obstack_1grow (&table_obstack
, '\n');
1100 output_short_table (&table_obstack
, NULL
, "yypgoto", base
,
1101 base
[nstates
], nstates
+ 1, nvectors
);
1110 obstack_fgrow1 (&table_obstack
, "\n\n#define\tYYLAST\t\t%d\n\n\n", high
);
1111 output_short_table (&table_obstack
, NULL
, "yytable", table
,
1112 table
[0], 1, high
+ 1);
1120 output_short_table (&table_obstack
, NULL
, "yycheck", check
,
1121 check
[0], 1, high
+ 1);
1125 /* compute and output yydefact, yydefgoto, yypact, yypgoto, yytable
1129 output_actions (void)
1131 nvectors
= nstates
+ nvars
;
1133 froms
= XCALLOC (short *, nvectors
);
1134 tos
= XCALLOC (short *, nvectors
);
1135 tally
= XCALLOC (short, nvectors
);
1136 width
= XCALLOC (short, nvectors
);
1145 XFREE (goto_map
+ ntokens
);
1151 obstack_1grow (&table_obstack
, '\n');
1154 obstack_1grow (&table_obstack
, '\n');
1158 /*------------------------------------------.
1159 | Copy the parser code into TABLE_OBSTACK. |
1160 `------------------------------------------*/
1163 output_parser (void)
1168 int actions_dumped
= 0;
1171 obstack_sgrow (&table_obstack
, "#define YYPURE 1\n\n");
1173 /* Loop over lines in the standard parser file. */
1176 if (semantic_parser
)
1177 skeleton
= skeleton_find ("BISON_HAIRY", BISON_HAIRY
);
1179 skeleton
= skeleton_find ("BISON_SIMPLE", BISON_SIMPLE
);
1182 fskel
= xfopen (skeleton
, "r");
1184 /* Set LINE to 2, not 1: `#line LINENUM' -- Here LINENUM is a
1185 decimal integer constant. This specifies that the line number of
1186 the *following* line of input, in its original source file, was
1195 sync_line
, /* #line. */
1196 actions_line
/* %% actions. */
1198 enum line_type_e line_type
= regular_line
;
1202 /* Is this line special? */
1205 /* See if it's a `#line' line. */
1206 if ((c
= getc (fskel
)) == 'l')
1207 if ((c
= getc (fskel
)) == 'i')
1208 if ((c
= getc (fskel
)) == 'n')
1209 if ((c
= getc (fskel
)) == 'e')
1210 line_type
= sync_line
;
1212 obstack_sgrow (&table_obstack
, "#lin");
1214 obstack_sgrow (&table_obstack
, "#li");
1216 obstack_sgrow (&table_obstack
, "#l");
1218 obstack_sgrow (&table_obstack
, "#");
1222 /* See if it's a `%% actions' line. */
1223 if ((c
= getc (fskel
)) == '%')
1224 if ((c
= getc (fskel
)) == ' ')
1225 if ((c
= getc (fskel
)) == 'a')
1226 if ((c
= getc (fskel
)) == 'c')
1227 if ((c
= getc (fskel
)) == 't')
1228 if ((c
= getc (fskel
)) == 'i')
1229 if ((c
= getc (fskel
)) == 'o')
1230 if ((c
= getc (fskel
)) == 'n')
1231 if ((c
= getc (fskel
)) == 's')
1232 line_type
= actions_line
;
1234 obstack_sgrow (&table_obstack
, "%% action");
1236 obstack_sgrow (&table_obstack
, "%% actio");
1238 obstack_sgrow (&table_obstack
, "%% acti");
1240 obstack_sgrow (&table_obstack
, "%% act");
1242 obstack_sgrow (&table_obstack
, "%% ac");
1244 obstack_sgrow (&table_obstack
, "%% a");
1246 obstack_sgrow (&table_obstack
, "%% ");
1248 obstack_sgrow (&table_obstack
, "%%");
1250 obstack_sgrow (&table_obstack
, "%");
1257 obstack_fgrow2 (&table_obstack
, "#line %d %s\n",
1258 line
, quotearg_style (c_quoting_style
, skeleton
));
1260 /* Skip the end of line. */
1261 for (; c
!= '\n' && c
!= EOF
; c
= getc (fskel
))
1267 size_t size
= obstack_object_size (&action_obstack
);
1270 assert (actions_dumped
== 1);
1271 obstack_grow (&table_obstack
,
1272 obstack_finish (&action_obstack
),
1276 /* Skip the end of line. */
1277 for (; c
!= '\n' && c
!= EOF
; c
= getc (fskel
))
1282 for (; c
!= '\n' && c
!= EOF
; c
= getc (fskel
))
1283 obstack_1grow (&table_obstack
, c
);
1288 obstack_1grow (&table_obstack
, c
);
1291 assert (actions_dumped
== 1);
1296 output_program (void)
1301 obstack_fgrow2 (&table_obstack
, "#line %d %s\n",
1302 lineno
, quotearg_style (c_quoting_style
, infile
));
1304 while ((c
= getc (finput
)) != EOF
)
1305 obstack_1grow (&table_obstack
, c
);
1310 free_itemsets (void)
1313 for (cp
= first_state
; cp
; cp
= cptmp
)
1321 /*----------------------------------------------------------.
1322 | Output the parsing tables and the parser code to ftable. |
1323 `----------------------------------------------------------*/
1328 /* output_token_defines(ftable); / * JF put out token defines FIRST */
1330 /* If using a simple parser the definition of YYSTYPE are put into
1332 if (!semantic_parser
)
1334 size_t size
= obstack_object_size (&attrs_obstack
);
1335 obstack_grow (&table_obstack
, obstack_finish (&attrs_obstack
), size
);
1337 reader_output_yylsp (&table_obstack
);
1339 obstack_sgrow (&table_obstack
, "\
1341 # define YYDEBUG 1\n\
1345 if (semantic_parser
)
1346 obstack_fgrow1 (&table_obstack
, "#include %s\n",
1347 quotearg_style (c_quoting_style
, attrsfile
));
1349 if (!no_parser_flag
)
1350 obstack_sgrow (&table_obstack
, "#include <stdio.h>\n\n");
1354 output_token_translations ();
1355 /* if (semantic_parser) */
1356 /* This is now unconditional because debugging printouts can use it. */
1359 if (semantic_parser
)
1361 output_rule_data ();
1363 XFREE (state_table
);
1365 if (!no_parser_flag
)