]>
git.saurik.com Git - bison.git/blob - src/reader.c
1 /* Input parser for bison
2 Copyright (C) 1984, 1986, 1989, 1992, 1998, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 This file is part of Bison, the GNU Compiler Compiler.
7 Bison is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 Bison is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Bison; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
35 #include "conflicts.h"
36 #include "muscle_tab.h"
38 typedef struct symbol_list
40 struct symbol_list
*next
;
44 /* The action is attached to the LHS of a rule. */
52 static symbol_list
*grammar
= NULL
;
53 static int start_flag
= 0;
55 /* Nonzero if %union has been seen. */
58 /* Incremented for each %left, %right or %nonassoc seen */
59 static int lastprec
= 0;
62 symbol_list_new (symbol_t
*sym
)
64 symbol_list
*res
= XMALLOC (symbol_list
, 1);
74 /*===================\
76 \===================*/
79 skip_to_char (int target
)
83 complain (_(" Skipping to next \\n"));
85 complain (_(" Skipping to next %c"), target
);
88 c
= skip_white_space ();
89 while (c
!= target
&& c
!= EOF
);
95 /*---------------------------------------------------------.
96 | Read a signed integer from STREAM and return its value. |
97 `---------------------------------------------------------*/
100 read_signed_integer (FILE *stream
)
102 int c
= getc (stream
);
114 n
= 10 * n
+ (c
- '0');
123 /*--------------------------------------------------------------.
124 | Get the data type (alternative in the union) of the value for |
125 | symbol N in rule RULE. |
126 `--------------------------------------------------------------*/
129 get_type_name (int n
, symbol_list
*rule
)
136 complain (_("invalid $ value"));
146 if (rp
== NULL
|| rp
->sym
== NULL
)
148 complain (_("invalid $ value"));
154 return rp
->sym
->type_name
;
157 /*------------------------------------------------------------------.
158 | Copy the character C to OOUT, and insert quadigraphs when needed. |
159 `------------------------------------------------------------------*/
162 copy_character (struct obstack
*oout
, int c
)
167 obstack_sgrow (oout
, "@<:@");
171 obstack_sgrow (oout
, "@:>@");
175 obstack_1grow (oout
, c
);
179 /*------------------------------------------------------------.
180 | Dump the string from FIN to OOUT if non null. MATCH is the |
181 | delimiter of the string (either ' or "). |
182 `------------------------------------------------------------*/
185 copy_string2 (FILE *fin
, struct obstack
*oout
, int match
, int store
)
190 obstack_1grow (oout
, match
);
197 fatal (_("unterminated string at end of file"));
200 complain (_("unterminated string"));
202 c
= match
; /* invent terminator */
206 copy_character (oout
, c
);
212 fatal (_("unterminated string at end of file"));
213 copy_character (oout
, c
);
223 obstack_1grow (oout
, c
);
229 copy_string (FILE *fin
, struct obstack
*oout
, int match
)
231 copy_string2 (fin
, oout
, match
, 1);
237 copy_identifier (FILE *fin
, struct obstack
*oout
)
241 while (isalnum (c
= getc (fin
)) || c
== '_')
242 obstack_1grow (oout
, c
);
248 /*------------------------------------------------------------------.
249 | Dump the wannabee comment from IN to OOUT. In fact we just saw a |
250 | `/', which might or might not be a comment. In any case, copy |
252 `------------------------------------------------------------------*/
255 copy_comment (FILE *fin
, struct obstack
*oout
)
261 /* We read a `/', output it. */
262 obstack_1grow (oout
, '/');
264 switch ((c
= getc (fin
)))
277 obstack_1grow (oout
, c
);
283 if (!cplus_comment
&& c
== '*')
287 obstack_1grow (oout
, c
);
293 obstack_1grow (oout
, c
);
300 obstack_1grow (oout
, c
);
307 fatal (_("unterminated comment"));
310 copy_character (oout
, c
);
317 /*-------------------------------------------------------------------.
318 | FIN is pointing to a location (i.e., a `@'). Output to OOUT a |
319 | reference to this location. RULE_LENGTH is the number of values in |
320 | the current rule so far, which says where to find `$0' with |
321 | respect to the top of the stack. |
322 `-------------------------------------------------------------------*/
325 copy_at (FILE *fin
, struct obstack
*oout
, int rule_length
)
332 obstack_sgrow (oout
, "]b4_lhs_location[");
334 else if (isdigit (c
) || c
== '-')
339 n
= read_signed_integer (fin
);
341 complain (_("invalid value: %s%d"), "@", n
);
343 obstack_fgrow2 (oout
, "]b4_rhs_location([%d], [%d])[",
350 complain (_("%s is invalid"), quote (buf
));
355 /*------------------------------------------------------------------.
356 | FIN is pointing to a wannabee semantic value (i.e., a `$'). |
358 | Possible inputs: $[<TYPENAME>]($|integer) |
360 | Output to OOUT a reference to this semantic value. RULE_LENGTH is |
361 | the number of values in the current rule so far, which says where |
362 | to find `$0' with respect to the top of the stack. |
363 `------------------------------------------------------------------*/
366 copy_dollar (FILE *fin
, struct obstack
*oout
,
367 symbol_list
*rule
, int rule_length
)
370 const char *type_name
= NULL
;
372 /* Get the type name if explicit. */
375 read_type_name (fin
);
376 type_name
= token_buffer
;
383 type_name
= get_type_name (0, rule
);
384 if (!type_name
&& typed
)
385 complain (_("$$ of `%s' has no declared type"),
389 obstack_fgrow1 (oout
,
390 "]b4_lhs_value([%s])[", type_name
);
392 else if (isdigit (c
) || c
== '-')
396 n
= read_signed_integer (fin
);
399 complain (_("invalid value: %s%d"), "$", n
);
402 if (!type_name
&& n
> 0)
403 type_name
= get_type_name (n
, rule
);
404 if (!type_name
&& typed
)
405 complain (_("$%d of `%s' has no declared type"),
409 obstack_fgrow3 (oout
, "]b4_rhs_value([%d], [%d], [%s])[",
410 rule_length
, n
, type_name
);
417 complain (_("%s is invalid"), quote (buf
));
421 /*-------------------------------------------------------------------.
422 | Copy the contents of a `%{ ... %}' into the definitions file. The |
423 | `%{' has already been read. Return after reading the `%}'. |
424 `-------------------------------------------------------------------*/
427 copy_definition (struct obstack
*oout
)
430 /* -1 while reading a character if prev char was %. */
435 obstack_fgrow2 (oout
, muscle_find ("linef"),
436 lineno
, quotearg_style (c_quoting_style
,
437 muscle_find ("filename")));
449 obstack_1grow (oout
, c
);
459 copy_string (finput
, oout
, c
);
463 copy_comment (finput
, oout
);
467 fatal ("%s", _("unterminated `%{' definition"));
470 copy_character (oout
, c
);
479 obstack_1grow (oout
, '%');
486 /*------------------------------------------.
487 | Parse what comes after %token or %nterm. |
488 `------------------------------------------*/
491 parse_token_decl (symbol_class
class)
493 token_t token
= tok_undef
;
494 char *typename
= NULL
;
496 /* The symbol being defined. */
497 symbol_t
*symbol
= NULL
;
499 /* After `%token' and `%nterm', any number of symbols maybe be
503 int tmp_char
= ungetc (skip_white_space (), finput
);
505 /* `%' (for instance from `%token', or from `%%' etc.) is the
506 only valid means to end this declaration. */
510 fatal (_("Premature EOF after %s"), token_buffer
);
520 typename
= xstrdup (token_buffer
);
525 if (*symval
->tag
== '\"' && symbol
)
527 symbol_make_alias (symbol
, symval
, typename
);
533 symbol_class_set (symbol
, class);
535 symbol_type_set (symbol
, typename
);
540 symbol_user_token_number_set (symbol
, numval
);
544 complain (_("`%s' is invalid in %s"),
546 (class == token_sym
) ? "%token" : "%nterm");
554 /*------------------------------.
555 | Parse what comes after %start |
556 `------------------------------*/
559 parse_start_decl (void)
562 complain (_("multiple %s declarations"), "%start");
563 if (lex () != tok_identifier
)
564 complain (_("invalid %s declaration"), "%start");
568 startsymbol
= symval
;
572 /*-----------------------------------------------------------.
573 | read in a %type declaration and record its information for |
574 | get_type_name to access |
575 `-----------------------------------------------------------*/
578 parse_type_decl (void)
582 if (lex () != tok_typename
)
584 complain ("%s", _("%type declaration has no <typename>"));
589 name
= xstrdup (token_buffer
);
594 int tmp_char
= ungetc (skip_white_space (), finput
);
599 fatal (_("Premature EOF after %s"), token_buffer
);
610 symbol_type_set (symval
, name
);
614 complain (_("invalid %%type declaration due to item: %s"),
623 /*----------------------------------------------------------------.
624 | Read in a %left, %right or %nonassoc declaration and record its |
626 `----------------------------------------------------------------*/
629 parse_assoc_decl (associativity assoc
)
634 /* Assign a new precedence level, never 0. */
640 int tmp_char
= ungetc (skip_white_space (), finput
);
645 fatal (_("Premature EOF after %s"), token_buffer
);
652 name
= xstrdup (token_buffer
);
659 symbol_class_set (symval
, token_sym
);
660 symbol_precedence_set (symval
, lastprec
, assoc
);
662 symbol_type_set (symval
, name
);
666 if (prev
== tok_identifier
)
668 symbol_user_token_number_set (symval
, numval
);
673 (_("invalid text (%s) - number should be after identifier"),
683 complain (_("unexpected item: %s"), token_buffer
);
693 /*--------------------------------------------------------------.
694 | Copy the union declaration into the stype muscle |
695 | (and fdefines), where it is made into the definition of |
696 | YYSTYPE, the type of elements of the parser value stack. |
697 `--------------------------------------------------------------*/
700 parse_union_decl (void)
705 struct obstack union_obstack
;
707 complain (_("multiple %s declarations"), "%union");
711 MUSCLE_INSERT_INT ("stype_line", lineno
);
712 obstack_init (&union_obstack
);
713 obstack_sgrow (&union_obstack
, "union");
719 /* If C contains '/', it is output by copy_comment (). */
721 obstack_1grow (&union_obstack
, c
);
730 copy_comment (finput
, &union_obstack
);
738 /* FIXME: Errr. How could this happen???. --akim */
740 complain (_("unmatched %s"), "`}'");
748 /* JF don't choke on trailing semi */
749 c
= skip_white_space ();
752 obstack_1grow (&union_obstack
, 0);
753 muscle_insert ("stype", obstack_finish (&union_obstack
));
757 /*-------------------------------------------------------.
758 | Parse the declaration %expect N which says to expect N |
759 | shift-reduce conflicts. |
760 `-------------------------------------------------------*/
763 parse_expect_decl (void)
765 int c
= skip_white_space ();
769 complain (_("argument of %%expect is not an integer"));
771 expected_conflicts
= read_signed_integer (finput
);
776 parse_muscle_decl (void)
778 int ch
= ungetc (skip_white_space (), finput
);
783 if (!isalpha (ch
) && ch
!= '_')
785 complain (_("invalid %s declaration"), "%define");
789 copy_identifier (finput
, &muscle_obstack
);
790 obstack_1grow (&muscle_obstack
, 0);
791 muscle_key
= obstack_finish (&muscle_obstack
);
794 ch
= skip_white_space ();
800 complain (_("invalid %s declaration"), "%define");
805 fatal (_("Premature EOF after %s"), "\"");
807 copy_string2 (finput
, &muscle_obstack
, '"', 0);
808 obstack_1grow (&muscle_obstack
, 0);
809 muscle_value
= obstack_finish (&muscle_obstack
);
811 /* Store the (key, value) pair in the environment. */
812 muscle_insert (muscle_key
, muscle_value
);
817 /*---------------------------------.
818 | Parse a double quoted parameter. |
819 `---------------------------------*/
822 parse_dquoted_param (const char *from
)
824 struct obstack param_obstack
;
825 const char *param
= NULL
;
828 obstack_init (¶m_obstack
);
829 c
= skip_white_space ();
833 complain (_("invalid %s declaration"), from
);
839 while ((c
= literalchar ()) != '"')
840 obstack_1grow (¶m_obstack
, c
);
842 obstack_1grow (¶m_obstack
, '\0');
843 param
= obstack_finish (¶m_obstack
);
845 if (c
!= '"' || strlen (param
) == 0)
847 complain (_("invalid %s declaration"), from
);
857 /*----------------------------------.
858 | Parse what comes after %skeleton. |
859 `----------------------------------*/
862 parse_skel_decl (void)
864 skeleton
= parse_dquoted_param ("%skeleton");
867 /*----------------------------------------------------------------.
868 | Read from finput until `%%' is seen. Discard the `%%'. Handle |
869 | any `%' declarations, and copy the contents of any `%{ ... %}' |
870 | groups to PRE_PROLOGUE_OBSTACK or POST_PROLOGUE_OBSTACK. |
871 `----------------------------------------------------------------*/
874 read_declarations (void)
878 int c
= skip_white_space ();
882 token_t tok
= parse_percent_token ();
886 case tok_two_percents
:
889 case tok_percent_left_curly
:
891 copy_definition (&pre_prologue_obstack
);
893 copy_definition (&post_prologue_obstack
);
897 parse_token_decl (token_sym
);
901 parse_token_decl (nterm_sym
);
917 parse_expect_decl ();
921 parse_assoc_decl (left_assoc
);
925 parse_assoc_decl (right_assoc
);
929 parse_assoc_decl (non_assoc
);
933 parse_muscle_decl ();
951 complain (_("unrecognized: %s"), token_buffer
);
956 fatal (_("no input grammar"));
961 complain (_("unknown character: %s"), quote (buf
));
967 /*------------------------------------------------------------------.
968 | Assuming that a `{' has just been seen, copy everything up to the |
969 | matching `}' into ACTION_OBSTACK. |
971 | RULE_LENGTH is the number of values in the current rule so far, |
972 | which says where to find `$0' with respect to the top of the |
973 | stack. It is not the same as the rule->length in the case of mid |
976 | This routine is used for actions. |
977 `------------------------------------------------------------------*/
980 parse_action (symbol_list
*rule
, int rule_length
)
983 rule
->action_line
= lineno
;
987 while ((c
= getc (finput
)) != '}')
991 copy_character (&action_obstack
, c
);
996 copy_character (&action_obstack
, c
);
1002 copy_string (finput
, &action_obstack
, c
);
1006 copy_comment (finput
, &action_obstack
);
1010 copy_dollar (finput
, &action_obstack
, rule
, rule_length
);
1014 copy_at (finput
, &action_obstack
, rule_length
);
1018 fatal (_("unmatched %s"), "`{'");
1021 copy_character (&action_obstack
, c
);
1024 /* Above loop exits when C is '}'. */
1026 copy_character (&action_obstack
, c
);
1029 obstack_1grow (&action_obstack
, '\0');
1030 rule
->action
= obstack_finish (&action_obstack
);
1035 /*-------------------------------------------------------------------.
1036 | Generate a dummy symbol, a nonterminal, whose name cannot conflict |
1037 | with the user's names. |
1038 `-------------------------------------------------------------------*/
1043 /* Incremented for each generated symbol */
1044 static int gensym_count
= 0;
1045 static char buf
[256];
1049 sprintf (buf
, "@%d", ++gensym_count
);
1051 sym
= getsym (token_buffer
);
1052 sym
->class = nterm_sym
;
1053 sym
->number
= nvars
++;
1057 /*-------------------------------------------------------------------.
1058 | Parse the input grammar into a one symbol_list structure. Each |
1059 | rule is represented by a sequence of symbols: the left hand side |
1060 | followed by the contents of the right hand side, followed by a |
1061 | null pointer instead of a symbol to terminate the rule. The next |
1062 | symbol is the lhs of the following rule. |
1064 | All actions are copied out, labelled by the rule number they apply |
1067 | Bison used to allow some %directives in the rules sections, but |
1068 | this is no longer consider appropriate: (i) the documented grammar |
1069 | doesn't claim it, (ii), it would promote bad style, (iii), error |
1070 | recovery for %directives consists in skipping the junk until a `%' |
1071 | is seen and helrp synchronizing. This scheme is definitely wrong |
1072 | in the rules section. |
1073 `-------------------------------------------------------------------*/
1075 /* The (currently) last symbol of GRAMMAR. */
1076 symbol_list
*grammar_end
= NULL
;
1078 /* Append S to the GRAMMAR. */
1080 grammar_symbol_append (symbol_t
*s
)
1082 symbol_list
*p
= symbol_list_new (s
);
1085 grammar_end
->next
= p
;
1096 symbol_t
*lhs
= NULL
;
1098 /* Points to first symbol_list of current rule. its symbol is the
1100 symbol_list
*crule
= NULL
;
1101 /* Points to the symbol_list preceding crule. */
1102 symbol_list
*crule1
= NULL
;
1106 while (t
!= tok_two_percents
&& t
!= tok_eof
)
1107 if (t
== tok_identifier
|| t
== tok_bar
)
1109 int action_flag
= 0;
1110 /* Number of symbols in rhs of this rule so far */
1112 int xactions
= 0; /* JF for error checking */
1113 symbol_t
*first_rhs
= 0;
1115 if (t
== tok_identifier
)
1128 complain (_("ill-formed rule: initial symbol not followed by colon"));
1133 if (nrules
== 0 && t
== tok_bar
)
1135 complain (_("grammar starts with vertical bar"));
1136 lhs
= symval
; /* BOGUS: use a random symval */
1138 /* start a new rule and record its lhs. */
1143 crule1
= grammar_end
;
1144 grammar_symbol_append (lhs
);
1145 crule
= grammar_end
;
1147 /* mark the rule's lhs as a nonterminal if not already so. */
1149 if (lhs
->class == unknown_sym
)
1151 lhs
->class = nterm_sym
;
1152 lhs
->number
= nvars
;
1155 else if (lhs
->class == token_sym
)
1156 complain (_("rule given for %s, which is a token"), lhs
->tag
);
1158 /* read the rhs of the rule. */
1166 crule
->ruleprec
= symval
;
1170 if (!(t
== tok_identifier
|| t
== tok_left_curly
))
1173 /* If next token is an identifier, see if a colon follows it.
1174 If one does, exit this rule now. */
1175 if (t
== tok_identifier
)
1184 if (t1
== tok_colon
)
1186 warn (_("previous rule lacks an ending `;'"));
1190 if (!first_rhs
) /* JF */
1192 /* Not followed by colon =>
1193 process as part of this rule's rhs. */
1196 /* If we just passed an action, that action was in the middle
1197 of a rule, so make a dummy rule to reduce it to a
1201 /* Since the action was written out with this rule's
1202 number, we must give the new rule this number by
1203 inserting the new rule before it. */
1205 /* Make a dummy nonterminal, a gensym. */
1206 symbol_t
*sdummy
= gensym ();
1207 symbol_list
*p
= symbol_list_new (sdummy
);
1209 /* Make a new rule, whose body is empty, before the
1210 current one, so that the action just read can
1214 /* Attach its lineno to that of the host rule. */
1215 p
->line
= crule
->line
;
1216 /* Move the action from the host rule to this one. */
1217 p
->action
= crule
->action
;
1218 p
->action_line
= crule
->action_line
;
1219 crule
->action
= NULL
;
1225 /* End of the rule. */
1226 crule1
= symbol_list_new (NULL
);
1227 crule1
->next
= crule
;
1231 /* Insert the dummy generated by that rule into this
1234 grammar_symbol_append (sdummy
);
1238 if (t
== tok_identifier
)
1241 grammar_symbol_append (symval
);
1243 else /* handle an action. */
1245 parse_action (crule
, rulelength
);
1247 ++xactions
; /* JF */
1250 } /* end of read rhs of rule */
1252 /* Put an empty link in the list to mark the end of this rule */
1253 grammar_symbol_append (NULL
);
1257 complain (_("two @prec's in a row"));
1259 crule
->ruleprec
= symval
;
1263 if (t
== tok_left_curly
)
1265 /* This case never occurs -wjh */
1267 complain (_("two actions at end of one rule"));
1268 parse_action (crule
, rulelength
);
1270 ++xactions
; /* -wjh */
1273 /* If $$ is being set in default way, report if any type
1276 && first_rhs
&& lhs
->type_name
!= first_rhs
->type_name
)
1278 if (lhs
->type_name
== 0
1279 || first_rhs
->type_name
== 0
1280 || strcmp (lhs
->type_name
, first_rhs
->type_name
))
1281 complain (_("type clash (`%s' `%s') on default action"),
1282 lhs
->type_name
? lhs
->type_name
: "",
1283 first_rhs
->type_name
? first_rhs
->type_name
: "");
1285 /* Warn if there is no default for $$ but we need one. */
1286 else if (!xactions
&& !first_rhs
&& lhs
->type_name
!= 0)
1287 complain (_("empty rule for typed nonterminal, and no action"));
1288 if (t
== tok_two_percents
|| t
== tok_eof
)
1289 warn (_("previous rule lacks an ending `;'"));
1290 if (t
== tok_semicolon
)
1295 complain (_("invalid input: %s"), quote (token_buffer
));
1299 /* grammar has been read. Do some checking */
1302 fatal (_("no rules in the input grammar"));
1304 /* Report any undefined symbols and consider them nonterminals. */
1305 symbols_check_defined ();
1307 /* Insert the initial rule, which line is that of the first rule
1308 (not that of the start symbol):
1310 axiom: %start EOF. */
1312 symbol_list
*p
= symbol_list_new (axiom
);
1313 p
->line
= grammar
->line
;
1314 p
->next
= symbol_list_new (startsymbol
);
1315 p
->next
->next
= symbol_list_new (eoftoken
);
1316 p
->next
->next
->next
= symbol_list_new (NULL
);
1317 p
->next
->next
->next
->next
= grammar
;
1323 if (nsyms
> SHRT_MAX
)
1324 fatal (_("too many symbols (tokens plus nonterminals); maximum %d"),
1327 assert (nsyms
== ntokens
+ nvars
);
1330 /* At the end of the grammar file, some C source code must
1331 be stored. It is going to be associated to the epilogue
1334 read_additionnal_code (void)
1337 struct obstack el_obstack
;
1339 obstack_init (&el_obstack
);
1343 obstack_fgrow2 (&el_obstack
, muscle_find ("linef"),
1344 lineno
, quotearg_style (c_quoting_style
,
1345 muscle_find ("filename")));
1348 while ((c
= getc (finput
)) != EOF
)
1349 copy_character (&el_obstack
, c
);
1351 obstack_1grow (&el_obstack
, 0);
1352 muscle_insert ("epilogue", obstack_finish (&el_obstack
));
1356 /*---------------------------------------------------------------.
1357 | Convert the rules into the representation using RRHS, RLHS and |
1359 `---------------------------------------------------------------*/
1364 unsigned int itemno
;
1368 ritem
= XCALLOC (item_number_t
, nritems
);
1369 rules
= XCALLOC (rule_t
, nrules
) - 1;
1377 symbol_t
*ruleprec
= p
->ruleprec
;
1378 rules
[ruleno
].user_number
= ruleno
;
1379 rules
[ruleno
].number
= ruleno
;
1380 rules
[ruleno
].lhs
= p
->sym
;
1381 rules
[ruleno
].rhs
= ritem
+ itemno
;
1382 rules
[ruleno
].line
= p
->line
;
1383 rules
[ruleno
].useful
= TRUE
;
1384 rules
[ruleno
].action
= p
->action
;
1385 rules
[ruleno
].action_line
= p
->action_line
;
1390 /* item_number_t = symbol_number_t.
1391 But the former needs to contain more: negative rule numbers. */
1392 ritem
[itemno
++] = symbol_number_as_item_number (p
->sym
->number
);
1393 /* A rule gets by default the precedence and associativity
1394 of the last token in it. */
1395 if (p
->sym
->class == token_sym
)
1396 rules
[ruleno
].prec
= p
->sym
;
1401 /* If this rule has a %prec,
1402 the specified symbol's precedence replaces the default. */
1405 rules
[ruleno
].precsym
= ruleprec
;
1406 rules
[ruleno
].prec
= ruleprec
;
1408 ritem
[itemno
++] = -ruleno
;
1415 assert (itemno
== nritems
);
1418 ritem_print (stderr
);
1421 /*------------------------------------------------------------------.
1422 | Read in the grammar specification and record it in the format |
1423 | described in gram.h. All actions are copied into ACTION_OBSTACK, |
1424 | in each case forming the body of a C function (YYACTION) which |
1425 | contains a switch statement to decide which action to execute. |
1426 `------------------------------------------------------------------*/
1434 /* Initialize the muscle obstack. */
1435 obstack_init (&muscle_obstack
);
1437 /* Initialize the symbol table. */
1440 /* Construct the axiom symbol. */
1441 axiom
= getsym ("$axiom");
1442 axiom
->class = nterm_sym
;
1443 axiom
->number
= nvars
++;
1445 /* Construct the error token */
1446 errtoken
= getsym ("error");
1447 errtoken
->class = token_sym
;
1448 errtoken
->number
= ntokens
++;
1450 /* Construct a token that represents all undefined literal tokens.
1451 It is always token number 2. */
1452 undeftoken
= getsym ("$undefined.");
1453 undeftoken
->class = token_sym
;
1454 undeftoken
->number
= ntokens
++;
1456 /* Initialize the obstacks. */
1457 obstack_init (&action_obstack
);
1458 obstack_init (&output_obstack
);
1459 obstack_init (&pre_prologue_obstack
);
1460 obstack_init (&post_prologue_obstack
);
1462 finput
= xfopen (infile
, "r");
1464 /* Read the declaration section. Copy %{ ... %} groups to
1465 TABLE_OBSTACK and FDEFINES file. Also notice any %token, %left,
1466 etc. found there. */
1467 read_declarations ();
1469 /* If the user did not define her EOFTOKEN, do it now. */
1472 eoftoken
= getsym ("$");
1473 eoftoken
->class = token_sym
;
1474 eoftoken
->number
= 0;
1475 /* Value specified by POSIX. */
1476 eoftoken
->user_token_number
= 0;
1479 /* Read in the grammar, build grammar in list form. Write out
1482 /* Some C code is given at the end of the grammar file. */
1483 read_additionnal_code ();
1488 /* Assign the symbols their symbol numbers. Write #defines for the
1489 token symbols into FDEFINES if requested. */
1492 /* Convert the grammar into the format described in gram.h. */
1495 /* The grammar as a symbol_list is no longer needed. */
1496 LIST_FREE (symbol_list
, grammar
);