]>
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 |
975 `------------------------------------------------------------------*/
978 parse_action (symbol_list
*rule
, int rule_length
)
981 rule
->action_line
= lineno
;
985 while ((c
= getc (finput
)) != '}')
989 copy_character (&action_obstack
, c
);
994 copy_character (&action_obstack
, c
);
1000 copy_string (finput
, &action_obstack
, c
);
1004 copy_comment (finput
, &action_obstack
);
1008 copy_dollar (finput
, &action_obstack
, rule
, rule_length
);
1012 copy_at (finput
, &action_obstack
, rule_length
);
1016 fatal (_("unmatched %s"), "`{'");
1019 copy_character (&action_obstack
, c
);
1022 /* Above loop exits when C is '}'. */
1024 copy_character (&action_obstack
, c
);
1027 obstack_1grow (&action_obstack
, '\0');
1028 rule
->action
= obstack_finish (&action_obstack
);
1033 /*-------------------------------------------------------------------.
1034 | Generate a dummy symbol, a nonterminal, whose name cannot conflict |
1035 | with the user's names. |
1036 `-------------------------------------------------------------------*/
1041 /* Incremented for each generated symbol */
1042 static int gensym_count
= 0;
1043 static char buf
[256];
1047 sprintf (buf
, "@%d", ++gensym_count
);
1049 sym
= getsym (token_buffer
);
1050 sym
->class = nterm_sym
;
1051 sym
->number
= nvars
++;
1055 /*-------------------------------------------------------------------.
1056 | Parse the input grammar into a one symbol_list structure. Each |
1057 | rule is represented by a sequence of symbols: the left hand side |
1058 | followed by the contents of the right hand side, followed by a |
1059 | null pointer instead of a symbol to terminate the rule. The next |
1060 | symbol is the lhs of the following rule. |
1062 | All actions are copied out, labelled by the rule number they apply |
1065 | Bison used to allow some %directives in the rules sections, but |
1066 | this is no longer consider appropriate: (i) the documented grammar |
1067 | doesn't claim it, (ii), it would promote bad style, (iii), error |
1068 | recovery for %directives consists in skipping the junk until a `%' |
1069 | is seen and helrp synchronizing. This scheme is definitely wrong |
1070 | in the rules section. |
1071 `-------------------------------------------------------------------*/
1073 /* The (currently) last symbol of GRAMMAR. */
1074 symbol_list
*grammar_end
= NULL
;
1076 /* Append S to the GRAMMAR. */
1078 grammar_symbol_append (symbol_t
*s
)
1080 symbol_list
*p
= symbol_list_new (s
);
1083 grammar_end
->next
= p
;
1090 /* The rule currently being defined, and the previous rule. Point to
1091 the first symbol of each list: their lhs. */
1092 symbol_list
*current_rule
= NULL
;
1093 symbol_list
*previous_rule
= NULL
;
1096 /* Create a new rule for LHS in to the GRAMMAR. */
1099 grammar_rule_begin (symbol_t
*lhs
)
1107 /* Start a new rule and record its lhs. */
1111 previous_rule
= grammar_end
;
1112 grammar_symbol_append (lhs
);
1113 current_rule
= grammar_end
;
1115 /* Mark the rule's lhs as a nonterminal if not already so. */
1117 if (lhs
->class == unknown_sym
)
1119 lhs
->class = nterm_sym
;
1120 lhs
->number
= nvars
;
1123 else if (lhs
->class == token_sym
)
1124 complain (_("rule given for %s, which is a token"), lhs
->tag
);
1127 /* The previous action turns out the be a mid-rule action. Attach it
1128 to the current rule, i.e., create a dummy symbol, attach it this
1129 mid-rule action, and append this dummy nonterminal to the current
1133 grammar_midrule_action (void)
1135 /* Since the action was written out with this rule's number, we must
1136 give the new rule this number by inserting the new rule before
1139 /* Make a dummy nonterminal, a gensym. */
1140 symbol_t
*sdummy
= gensym ();
1141 symbol_list
*midrule_action
= symbol_list_new (sdummy
);
1143 /* Make a new rule, whose body is empty, before the current one, so
1144 that the action just read can belong to it. */
1147 /* Attach its lineno to that of the host rule. */
1148 midrule_action
->line
= current_rule
->line
;
1149 /* Move the action from the host rule to this one. */
1150 midrule_action
->action
= current_rule
->action
;
1151 midrule_action
->action_line
= current_rule
->action_line
;
1152 current_rule
->action
= NULL
;
1155 previous_rule
->next
= midrule_action
;
1157 grammar
= midrule_action
;
1159 /* End of the rule. */
1160 previous_rule
= symbol_list_new (NULL
);
1161 previous_rule
->next
= current_rule
;
1163 midrule_action
->next
= previous_rule
;
1165 /* Insert the dummy generated by that rule into this rule. */
1167 grammar_symbol_append (sdummy
);
1170 /* Set the precedence symbol of the current rule to PRECSYM. */
1173 grammar_current_rule_prec_set (symbol_t
*precsym
)
1175 if (current_rule
->ruleprec
)
1176 complain (_("two @prec's in a row"));
1177 current_rule
->ruleprec
= precsym
;
1180 /* Check that the last rule (CURRENT_RULE) is properly defined. For
1181 instance, there should be no type clash on the default action. */
1184 grammar_current_rule_check (void)
1186 symbol_t
*lhs
= current_rule
->sym
;
1187 symbol_t
*first_rhs
= current_rule
->next
->sym
;
1189 /* If there is an action, then there is nothing we can do: the user
1190 is allowed to shoot in her foot. */
1191 if (current_rule
->action
)
1194 /* If $$ is being set in default way, report if any type mismatch.
1198 const char *lhs_type
= lhs
->type_name
? lhs
->type_name
: "";
1199 const char *rhs_type
= first_rhs
->type_name
? first_rhs
->type_name
: "";
1200 if (strcmp (lhs_type
, rhs_type
))
1201 complain (_("type clash (`%s' `%s') on default action"),
1202 lhs_type
, rhs_type
);
1204 /* Warn if there is no default for $$ but we need one. */
1208 complain (_("empty rule for typed nonterminal, and no action"));
1217 symbol_t
*lhs
= NULL
;
1221 while (t
!= tok_two_percents
&& t
!= tok_eof
)
1222 if (t
== tok_identifier
|| t
== tok_bar
)
1224 int action_flag
= 0;
1225 /* Number of symbols in rhs of this rule so far */
1228 if (t
== tok_identifier
)
1235 complain (_("ill-formed rule: initial symbol not followed by colon"));
1239 if (nrules
== 0 && t
== tok_bar
)
1241 complain (_("grammar starts with vertical bar"));
1242 lhs
= symval
; /* BOGUS: use a random symval */
1245 grammar_rule_begin (lhs
);
1246 /* read the rhs of the rule. */
1254 grammar_current_rule_prec_set (symval
);
1258 if (!(t
== tok_identifier
|| t
== tok_left_curly
))
1261 /* If next token is an identifier, see if a colon follows it.
1262 If one does, exit this rule now. */
1263 if (t
== tok_identifier
)
1272 if (t1
== tok_colon
)
1274 warn (_("previous rule lacks an ending `;'"));
1277 /* Not followed by colon => process as part of this
1281 /* If we just passed an action, that action was in the middle
1282 of a rule, so make a dummy rule to reduce it to a
1286 grammar_midrule_action ();
1290 if (t
== tok_identifier
)
1293 grammar_symbol_append (symval
);
1295 else /* handle an action. */
1297 parse_action (current_rule
, rulelength
);
1301 } /* end of read rhs of rule */
1303 /* Put an empty link in the list to mark the end of this rule */
1304 grammar_symbol_append (NULL
);
1309 grammar_current_rule_prec_set (symval
);
1313 if (t
== tok_left_curly
)
1315 parse_action (current_rule
, rulelength
);
1320 grammar_current_rule_check ();
1322 if (t
== tok_two_percents
|| t
== tok_eof
)
1323 warn (_("previous rule lacks an ending `;'"));
1324 if (t
== tok_semicolon
)
1329 complain (_("invalid input: %s"), quote (token_buffer
));
1333 /* grammar has been read. Do some checking */
1336 fatal (_("no rules in the input grammar"));
1338 /* Report any undefined symbols and consider them nonterminals. */
1339 symbols_check_defined ();
1341 /* Insert the initial rule, which line is that of the first rule
1342 (not that of the start symbol):
1344 axiom: %start EOF. */
1346 symbol_list
*p
= symbol_list_new (axiom
);
1347 p
->line
= grammar
->line
;
1348 p
->next
= symbol_list_new (startsymbol
);
1349 p
->next
->next
= symbol_list_new (eoftoken
);
1350 p
->next
->next
->next
= symbol_list_new (NULL
);
1351 p
->next
->next
->next
->next
= grammar
;
1357 if (nsyms
> SHRT_MAX
)
1358 fatal (_("too many symbols (tokens plus nonterminals); maximum %d"),
1361 assert (nsyms
== ntokens
+ nvars
);
1364 /* At the end of the grammar file, some C source code must
1365 be stored. It is going to be associated to the epilogue
1368 read_additionnal_code (void)
1371 struct obstack el_obstack
;
1373 obstack_init (&el_obstack
);
1377 obstack_fgrow2 (&el_obstack
, muscle_find ("linef"),
1378 lineno
, quotearg_style (c_quoting_style
,
1379 muscle_find ("filename")));
1382 while ((c
= getc (finput
)) != EOF
)
1383 copy_character (&el_obstack
, c
);
1385 obstack_1grow (&el_obstack
, 0);
1386 muscle_insert ("epilogue", obstack_finish (&el_obstack
));
1390 /*---------------------------------------------------------------.
1391 | Convert the rules into the representation using RRHS, RLHS and |
1393 `---------------------------------------------------------------*/
1398 unsigned int itemno
;
1402 ritem
= XCALLOC (item_number_t
, nritems
);
1403 rules
= XCALLOC (rule_t
, nrules
) - 1;
1411 symbol_t
*ruleprec
= p
->ruleprec
;
1412 rules
[ruleno
].user_number
= ruleno
;
1413 rules
[ruleno
].number
= ruleno
;
1414 rules
[ruleno
].lhs
= p
->sym
;
1415 rules
[ruleno
].rhs
= ritem
+ itemno
;
1416 rules
[ruleno
].line
= p
->line
;
1417 rules
[ruleno
].useful
= TRUE
;
1418 rules
[ruleno
].action
= p
->action
;
1419 rules
[ruleno
].action_line
= p
->action_line
;
1424 /* item_number_t = symbol_number_t.
1425 But the former needs to contain more: negative rule numbers. */
1426 ritem
[itemno
++] = symbol_number_as_item_number (p
->sym
->number
);
1427 /* A rule gets by default the precedence and associativity
1428 of the last token in it. */
1429 if (p
->sym
->class == token_sym
)
1430 rules
[ruleno
].prec
= p
->sym
;
1435 /* If this rule has a %prec,
1436 the specified symbol's precedence replaces the default. */
1439 rules
[ruleno
].precsym
= ruleprec
;
1440 rules
[ruleno
].prec
= ruleprec
;
1442 ritem
[itemno
++] = -ruleno
;
1449 assert (itemno
== nritems
);
1452 ritem_print (stderr
);
1455 /*------------------------------------------------------------------.
1456 | Read in the grammar specification and record it in the format |
1457 | described in gram.h. All actions are copied into ACTION_OBSTACK, |
1458 | in each case forming the body of a C function (YYACTION) which |
1459 | contains a switch statement to decide which action to execute. |
1460 `------------------------------------------------------------------*/
1468 /* Initialize the muscle obstack. */
1469 obstack_init (&muscle_obstack
);
1471 /* Initialize the symbol table. */
1474 /* Construct the axiom symbol. */
1475 axiom
= getsym ("$axiom");
1476 axiom
->class = nterm_sym
;
1477 axiom
->number
= nvars
++;
1479 /* Construct the error token */
1480 errtoken
= getsym ("error");
1481 errtoken
->class = token_sym
;
1482 errtoken
->number
= ntokens
++;
1484 /* Construct a token that represents all undefined literal tokens.
1485 It is always token number 2. */
1486 undeftoken
= getsym ("$undefined.");
1487 undeftoken
->class = token_sym
;
1488 undeftoken
->number
= ntokens
++;
1490 /* Initialize the obstacks. */
1491 obstack_init (&action_obstack
);
1492 obstack_init (&output_obstack
);
1493 obstack_init (&pre_prologue_obstack
);
1494 obstack_init (&post_prologue_obstack
);
1496 finput
= xfopen (infile
, "r");
1498 /* Read the declaration section. Copy %{ ... %} groups to
1499 TABLE_OBSTACK and FDEFINES file. Also notice any %token, %left,
1500 etc. found there. */
1501 read_declarations ();
1503 /* If the user did not define her EOFTOKEN, do it now. */
1506 eoftoken
= getsym ("$");
1507 eoftoken
->class = token_sym
;
1508 eoftoken
->number
= 0;
1509 /* Value specified by POSIX. */
1510 eoftoken
->user_token_number
= 0;
1513 /* Read in the grammar, build grammar in list form. Write out
1516 /* Some C code is given at the end of the grammar file. */
1517 read_additionnal_code ();
1522 /* Assign the symbols their symbol numbers. Write #defines for the
1523 token symbols into FDEFINES if requested. */
1526 /* Convert the grammar into the format described in gram.h. */
1529 /* The grammar as a symbol_list is no longer needed. */
1530 LIST_FREE (symbol_list
, grammar
);