1 /* Input parser for Bison
3 Copyright (C) 1984, 1986, 1989, 1992, 1998, 2000-2003, 2005-2007,
4 2009-2015, 2018-2021 Free Software Foundation, Inc.
6 This file is part of Bison, the GNU Compiler Compiler.
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <https://www.gnu.org/licenses/>. */
27 #include "conflicts.h"
32 #include "muscle-tab.h"
36 #include "scan-gram.h"
37 #include "scan-code.h"
39 static void prepare_percent_define_front_end_variables (void);
40 static void check_and_convert_grammar (void);
42 static symbol_list
*grammar
= NULL
;
43 static bool start_flag
= false;
44 merger_list
*merge_functions
= NULL
;
46 /* Was %union seen? */
47 bool union_seen
= false;
49 /* Should rules have a default precedence? */
50 bool default_prec
= true;
52 /*-----------------------.
53 | Set the start symbol. |
54 `-----------------------*/
57 grammar_start_symbol_set (symbol
*sym
, location loc
)
60 complain (&loc
, complaint
, _("multiple %s declarations"), "%start");
65 startsymbol_loc
= loc
;
71 /*------------------------------------------------------------------------.
72 | Return the merger index for a merging function named NAME. Records the |
73 | function, if new, in MERGER_LIST. |
74 `------------------------------------------------------------------------*/
77 get_merge_function (uniqstr name
)
86 head
.next
= merge_functions
;
87 for (syms
= &head
, n
= 1; syms
->next
; syms
= syms
->next
, n
+= 1)
88 if (UNIQSTR_EQ (name
, syms
->next
->name
))
90 if (syms
->next
== NULL
)
92 syms
->next
= xmalloc (sizeof syms
->next
[0]);
93 syms
->next
->name
= uniqstr_new (name
);
94 /* After all symbol type declarations have been parsed, packgram invokes
95 record_merge_function_type to set the type. */
96 syms
->next
->sym
= NULL
;
97 syms
->next
->next
= NULL
;
98 merge_functions
= head
.next
;
103 /*-------------------------------------------------------------------.
104 | For the existing merging function with index MERGER, record that |
105 | the result type is that of SYM, as required by the lhs (i.e., SYM) |
106 | of the rule whose %merge declaration is at DECLARATION_LOC. |
107 `-------------------------------------------------------------------*/
110 record_merge_function_type (int merger
, symbol
*sym
, location declaration_loc
)
116 = sym
->content
->type_name
? sym
->content
->type_name
: uniqstr_new ("");
118 merger_list
*merge_function
;
120 for (merge_function
= merge_functions
;
121 merge_function
!= NULL
&& merger_find
!= merger
;
122 merge_function
= merge_function
->next
)
124 aver (merge_function
!= NULL
&& merger_find
== merger
);
125 if (merge_function
->sym
&& merge_function
->sym
->content
->type_name
)
127 if (!UNIQSTR_EQ (merge_function
->sym
->content
->type_name
, type
))
129 complain (&declaration_loc
, complaint
,
130 _("result type clash on merge function %s: "
132 quote (merge_function
->name
), type
,
133 merge_function
->sym
->content
->type_name
);
134 subcomplain (&merge_function
->type_declaration_loc
, complaint
,
135 _("previous declaration"));
140 merge_function
->sym
= sym
;
141 merge_function
->type_declaration_loc
= declaration_loc
;
145 /*--------------------------------------.
146 | Free all merge-function definitions. |
147 `--------------------------------------*/
150 free_merger_functions (void)
152 merger_list
*L0
= merge_functions
;
155 merger_list
*L1
= L0
->next
;
162 /*-------------------------------------------------------------------.
163 | Parse the input grammar into a one symbol_list structure. Each |
164 | rule is represented by a sequence of symbols: the left hand side |
165 | followed by the contents of the right hand side, followed by a |
166 | null pointer instead of a symbol to terminate the rule. The next |
167 | symbol is the lhs of the following rule. |
169 | All actions are copied out, labelled by the rule number they apply |
171 `-------------------------------------------------------------------*/
173 /* The (currently) last symbol of GRAMMAR. */
174 static symbol_list
*grammar_end
= NULL
;
176 /* Append SYM to the grammar. */
178 grammar_symbol_append (symbol
*sym
, location loc
)
180 symbol_list
*p
= symbol_list_sym_new (sym
, loc
);
183 grammar_end
->next
= p
;
189 /* A null SYM stands for an end of rule; it is not an actual
198 assign_named_ref (symbol_list
*p
, named_ref
*name
)
200 symbol
*sym
= p
->content
.sym
;
202 if (name
->id
== sym
->tag
)
204 complain (&name
->loc
, Wother
,
205 _("duplicated symbol name for %s ignored"),
207 named_ref_free (name
);
214 /* The rule currently being defined, and the previous rule.
215 CURRENT_RULE points to the first LHS of the current rule, while
216 PREVIOUS_RULE_END points to the *end* of the previous rule (NULL). */
217 static symbol_list
*current_rule
= NULL
;
218 static symbol_list
*previous_rule_end
= NULL
;
221 /*----------------------------------------------.
222 | Create a new rule for LHS in to the GRAMMAR. |
223 `----------------------------------------------*/
226 grammar_current_rule_begin (symbol
*lhs
, location loc
,
229 /* Start a new rule and record its lhs. */
231 previous_rule_end
= grammar_end
;
233 current_rule
= grammar_symbol_append (lhs
, loc
);
235 assign_named_ref (current_rule
, named_ref_copy (lhs_name
));
237 /* Mark the rule's lhs as a nonterminal if not already so. */
238 if (lhs
->content
->class == unknown_sym
|| lhs
->content
->class == pct_type_sym
)
239 symbol_class_set (lhs
, nterm_sym
, empty_loc
, false);
240 else if (lhs
->content
->class == token_sym
)
241 complain (&loc
, complaint
, _("rule given for %s, which is a token"),
246 /*----------------------------------------------------------------------.
247 | A symbol should be used if either: |
248 | 1. It has a destructor. |
249 | 2. The symbol is a midrule symbol (i.e., the generated LHS |
250 | replacing a midrule action) that was assigned to or used, as in |
251 | "exp: { $$ = 1; } { $$ = $1; }". |
252 `----------------------------------------------------------------------*/
255 symbol_should_be_used (symbol_list
const *s
, bool *midrule_warning
)
257 if (symbol_code_props_get (s
->content
.sym
, destructor
)->code
)
259 if ((s
->midrule
&& s
->midrule
->action_props
.is_value_used
)
260 || (s
->midrule_parent_rule
261 && (symbol_list_n_get (s
->midrule_parent_rule
,
262 s
->midrule_parent_rhs_index
)
263 ->action_props
.is_value_used
)))
265 *midrule_warning
= true;
271 /*-----------------------------------------------------------------.
272 | Check that the rule R is properly defined. For instance, there |
273 | should be no type clash on the default action. Possibly install |
274 | the default action. |
275 `-----------------------------------------------------------------*/
278 grammar_rule_check_and_complete (symbol_list
*r
)
282 If there is an action, then there is nothing we can do: the user
283 is allowed to shoot herself in the foot.
285 Don't worry about the default action if $$ is untyped, since $$'s
286 value can't be used. */
287 if (!r
->action_props
.code
&& r
->content
.sym
->content
->type_name
)
289 symbol
*first_rhs
= r
->next
->content
.sym
;
290 /* If $$ is being set in default way, report if any type mismatch. */
293 char const *lhs_type
= r
->content
.sym
->content
->type_name
;
294 char const *rhs_type
=
295 first_rhs
->content
->type_name
? first_rhs
->content
->type_name
: "";
296 if (!UNIQSTR_EQ (lhs_type
, rhs_type
))
297 complain (&r
->rhs_loc
, Wother
,
298 _("type clash on default action: <%s> != <%s>"),
302 /* Install the default action only for C++. */
304 STREQ (language
->language
, "c++")
305 || (skeleton
&& (STREQ (skeleton
, "glr.cc")
306 || STREQ (skeleton
, "lalr1.cc")));
309 code_props_rule_action_init (&r
->action_props
, "{ $$ = $1; }",
313 /* is_predicate */ false);
314 code_props_translate_code (&r
->action_props
);
318 /* Warn if there is no default for $$ but we need one. */
320 complain (&r
->rhs_loc
, Wother
,
321 _("empty rule for typed nonterminal, and no action"));
324 /* Check that symbol values that should be used are in fact used. */
327 for (symbol_list
const *l
= r
; l
&& l
->content
.sym
; l
= l
->next
, ++n
)
329 bool midrule_warning
= false;
330 if (!l
->action_props
.is_value_used
331 && symbol_should_be_used (l
, &midrule_warning
)
332 /* The default action, $$ = $1, 'uses' both. */
333 && (r
->action_props
.code
|| (n
!= 0 && n
!= 1)))
335 warnings warn_flag
= midrule_warning
? Wmidrule_values
: Wother
;
337 complain (&l
->sym_loc
, warn_flag
, _("unused value: $%d"), n
);
339 complain (&l
->rhs_loc
, warn_flag
, _("unset value: $$"));
344 /* Check that %empty => empty rule. */
345 if (r
->percent_empty_loc
.start
.file
346 && r
->next
&& r
->next
->content
.sym
)
348 complain (&r
->percent_empty_loc
, complaint
,
349 _("%%empty on non-empty rule"));
350 fixits_register (&r
->percent_empty_loc
, "");
353 /* Check that empty rule => %empty. */
354 if (!(r
->next
&& r
->next
->content
.sym
)
355 && !r
->midrule_parent_rule
356 && !r
->percent_empty_loc
.start
.file
357 && warning_is_enabled (Wempty_rule
))
359 complain (&r
->rhs_loc
, Wempty_rule
, _("empty rule without %%empty"));
360 if (feature_flag
& feature_caret
)
361 location_caret_suggestion (r
->rhs_loc
, "%empty", stderr
);
362 location loc
= r
->rhs_loc
;
364 fixits_register (&loc
, " %empty ");
367 /* See comments in grammar_current_rule_prec_set for how POSIX
368 mandates this complaint. It's only for identifiers, so skip
369 it for char literals and strings, which are always tokens. */
371 && r
->ruleprec
->tag
[0] != '\'' && r
->ruleprec
->tag
[0] != '"'
372 && r
->ruleprec
->content
->status
!= declared
373 && !r
->ruleprec
->content
->prec
)
374 complain (&r
->rhs_loc
, Wother
,
375 _("token for %%prec is not defined: %s"), r
->ruleprec
->tag
);
377 /* Check that the (main) action was not typed. */
378 if (r
->action_props
.type
)
379 complain (&r
->rhs_loc
, Wother
,
380 _("only midrule actions can be typed: %s"), r
->action_props
.type
);
384 /*-------------------------------------.
385 | End the currently being grown rule. |
386 `-------------------------------------*/
389 grammar_current_rule_end (location loc
)
391 /* Put an empty link in the list to mark the end of this rule */
392 grammar_symbol_append (NULL
, grammar_end
->rhs_loc
);
393 current_rule
->rhs_loc
= loc
;
397 /*-------------------------------------------------------------------.
398 | The previous action turns out to be a midrule action. Attach it |
399 | to the current rule, i.e., create a dummy symbol, attach it this |
400 | midrule action, and append this dummy nonterminal to the current |
402 `-------------------------------------------------------------------*/
405 grammar_midrule_action (void)
407 /* Since the action was written out with this rule's number, we must
408 give the new rule this number by inserting the new rule before
411 /* Make a DUMMY nonterminal, whose location is that of the midrule
412 action. Create the MIDRULE. */
413 location dummy_loc
= current_rule
->action_props
.location
;
414 symbol
*dummy
= dummy_symbol_get (dummy_loc
);
415 symbol_type_set (dummy
,
416 current_rule
->action_props
.type
, current_rule
->action_props
.location
);
417 symbol_list
*midrule
= symbol_list_sym_new (dummy
, dummy_loc
);
419 /* Remember named_ref of previous action. */
420 named_ref
*action_name
= current_rule
->action_props
.named_ref
;
422 /* Make a new rule, whose body is empty, before the current one, so
423 that the action just read can belong to it. */
426 /* Attach its location and actions to that of the DUMMY. */
427 midrule
->rhs_loc
= dummy_loc
;
428 code_props_rule_action_init (&midrule
->action_props
,
429 current_rule
->action_props
.code
,
430 current_rule
->action_props
.location
,
434 current_rule
->action_props
.is_predicate
);
435 code_props_none_init (¤t_rule
->action_props
);
437 midrule
->expected_sr_conflicts
= current_rule
->expected_sr_conflicts
;
438 midrule
->expected_rr_conflicts
= current_rule
->expected_rr_conflicts
;
439 current_rule
->expected_sr_conflicts
= -1;
440 current_rule
->expected_rr_conflicts
= -1;
442 if (previous_rule_end
)
443 previous_rule_end
->next
= midrule
;
447 /* End the dummy's rule. */
448 midrule
->next
= symbol_list_sym_new (NULL
, dummy_loc
);
449 midrule
->next
->next
= current_rule
;
451 previous_rule_end
= midrule
->next
;
453 /* Insert the dummy nonterminal replacing the midrule action into
454 the current rule. Bind it to its dedicated rule. */
455 grammar_current_rule_symbol_append (dummy
, dummy_loc
,
457 grammar_end
->midrule
= midrule
;
458 midrule
->midrule_parent_rule
= current_rule
;
459 midrule
->midrule_parent_rhs_index
= symbol_list_length (current_rule
->next
);
462 /* Set the precedence symbol of the current rule to PRECSYM. */
465 grammar_current_rule_prec_set (symbol
*precsym
, location loc
)
467 /* POSIX says that any identifier is a nonterminal if it does not
468 appear on the LHS of a grammar rule and is not defined by %token
469 or by one of the directives that assigns precedence to a token.
470 We ignore this here because the only kind of identifier that
471 POSIX allows to follow a %prec is a token and because assuming
472 it's a token now can produce more logical error messages.
473 Nevertheless, grammar_rule_check_and_complete does obey what we
474 believe is the real intent of POSIX here: that an error be
475 reported for any identifier that appears after %prec but that is
476 not defined separately as a token. */
477 symbol_class_set (precsym
, token_sym
, loc
, false);
478 if (current_rule
->ruleprec
)
479 duplicate_rule_directive ("%prec",
480 current_rule
->ruleprec
->location
, loc
);
482 current_rule
->ruleprec
= precsym
;
485 /* Set %empty for the current rule. */
488 grammar_current_rule_empty_set (location loc
)
490 /* If %empty is used and -Wno-empty-rule is not, then enable
492 if (warning_is_unset (Wempty_rule
))
493 warning_argmatch ("empty-rule", 0, 0);
494 if (current_rule
->percent_empty_loc
.start
.file
)
495 duplicate_rule_directive ("%empty",
496 current_rule
->percent_empty_loc
, loc
);
498 current_rule
->percent_empty_loc
= loc
;
501 /* Attach dynamic precedence DPREC to the current rule. */
504 grammar_current_rule_dprec_set (int dprec
, location loc
)
507 complain (&loc
, Wother
, _("%s affects only GLR parsers"),
510 complain (&loc
, complaint
, _("%s must be followed by positive number"),
512 else if (current_rule
->dprec
!= 0)
513 duplicate_rule_directive ("%dprec",
514 current_rule
->dprec_loc
, loc
);
517 current_rule
->dprec
= dprec
;
518 current_rule
->dprec_loc
= loc
;
522 /* Attach a merge function NAME with argument type TYPE to current
526 grammar_current_rule_merge_set (uniqstr name
, location loc
)
529 complain (&loc
, Wother
, _("%s affects only GLR parsers"),
531 if (current_rule
->merger
!= 0)
532 duplicate_rule_directive ("%merge",
533 current_rule
->merger_declaration_loc
, loc
);
536 current_rule
->merger
= get_merge_function (name
);
537 current_rule
->merger_declaration_loc
= loc
;
541 /* Attach SYM to the current rule. If needed, move the previous
542 action as a midrule action. */
545 grammar_current_rule_symbol_append (symbol
*sym
, location loc
,
548 if (current_rule
->action_props
.code
)
549 grammar_midrule_action ();
550 symbol_list
*p
= grammar_symbol_append (sym
, loc
);
552 assign_named_ref (p
, name
);
553 if (sym
->content
->status
== undeclared
|| sym
->content
->status
== used
)
554 sym
->content
->status
= needed
;
558 grammar_current_rule_action_append (const char *action
, location loc
,
559 named_ref
*name
, uniqstr type
)
561 if (current_rule
->action_props
.code
)
562 grammar_midrule_action ();
564 complain (&loc
, Wyacc
,
565 _("POSIX Yacc does not support typed midrule actions"));
566 /* After all symbol declarations have been parsed, packgram invokes
567 code_props_translate_code. */
568 code_props_rule_action_init (¤t_rule
->action_props
, action
, loc
,
571 /* is_predicate */ false);
575 grammar_current_rule_predicate_append (const char *pred
, location loc
)
577 if (current_rule
->action_props
.code
)
578 grammar_midrule_action ();
579 code_props_rule_action_init (¤t_rule
->action_props
, pred
, loc
,
582 /* is_predicate */ true);
585 /* Set the expected number of shift/reduce (reduce/reduce) conflicts
586 * for the current rule. If a midrule is encountered later, the count
587 * is transferred to it and reset in the current rule to -1. */
590 grammar_current_rule_expect_sr (int count
, location loc
)
593 current_rule
->expected_sr_conflicts
= count
;
597 grammar_current_rule_expect_rr (int count
, location loc
)
600 complain (&loc
, Wother
, _("%s affects only GLR parsers"),
603 current_rule
->expected_rr_conflicts
= count
;
607 /*---------------------------------------------.
608 | Build RULES and RITEM from what was parsed. |
609 `---------------------------------------------*/
615 ritem
= xnmalloc (nritems
+ 1, sizeof *ritem
);
616 /* This sentinel is used by build_relations() in lalr.c. */
619 rule_number ruleno
= 0;
620 rules
= xnmalloc (nrules
, sizeof *rules
);
622 for (symbol_list
*p
= grammar
; p
; p
= p
->next
)
624 symbol_list
*lhs
= p
;
625 record_merge_function_type (lhs
->merger
, lhs
->content
.sym
,
626 lhs
->merger_declaration_loc
);
627 /* If the midrule's $$ is set or its $n is used, remove the '$' from the
628 symbol name so that it's a user-defined symbol so that the default
629 %destructor and %printer apply. */
630 if (lhs
->midrule_parent_rule
/* i.e., symbol_is_dummy (lhs->content.sym). */
631 && (lhs
->action_props
.is_value_used
632 || (symbol_list_n_get (lhs
->midrule_parent_rule
,
633 lhs
->midrule_parent_rhs_index
)
634 ->action_props
.is_value_used
)))
635 lhs
->content
.sym
->tag
+= 1;
637 /* Don't check the generated rule 0. It has no action, so some rhs
638 symbols may appear unused, but the parsing algorithm ensures that
639 %destructor's are invoked appropriately. */
641 grammar_rule_check_and_complete (lhs
);
643 rules
[ruleno
].code
= ruleno
;
644 rules
[ruleno
].number
= ruleno
;
645 rules
[ruleno
].lhs
= lhs
->content
.sym
->content
;
646 rules
[ruleno
].rhs
= ritem
+ itemno
;
647 rules
[ruleno
].prec
= NULL
;
648 rules
[ruleno
].dprec
= lhs
->dprec
;
649 rules
[ruleno
].merger
= lhs
->merger
;
650 rules
[ruleno
].precsym
= NULL
;
651 rules
[ruleno
].location
= lhs
->rhs_loc
;
652 rules
[ruleno
].useful
= true;
653 rules
[ruleno
].action
= lhs
->action_props
.code
;
654 rules
[ruleno
].action_loc
= lhs
->action_props
.location
;
655 rules
[ruleno
].is_predicate
= lhs
->action_props
.is_predicate
;
656 rules
[ruleno
].expected_sr_conflicts
= lhs
->expected_sr_conflicts
;
657 rules
[ruleno
].expected_rr_conflicts
= lhs
->expected_rr_conflicts
;
659 /* Traverse the rhs. */
661 size_t rule_length
= 0;
662 for (p
= lhs
->next
; p
->content
.sym
; p
= p
->next
)
666 /* Don't allow rule_length == INT_MAX, since that might
667 cause confusion with strtol if INT_MAX == LONG_MAX. */
668 if (rule_length
== INT_MAX
)
669 complain (&rules
[ruleno
].location
, fatal
, _("rule is too long"));
671 /* item_number = symbol_number.
672 But the former needs to contain more: negative rule numbers. */
674 symbol_number_as_item_number (p
->content
.sym
->content
->number
);
675 /* A rule gets by default the precedence and associativity
676 of its last token. */
677 if (p
->content
.sym
->content
->class == token_sym
&& default_prec
)
678 rules
[ruleno
].prec
= p
->content
.sym
->content
;
682 /* If this rule has a %prec,
683 the specified symbol's precedence replaces the default. */
686 rules
[ruleno
].precsym
= lhs
->ruleprec
->content
;
687 rules
[ruleno
].prec
= lhs
->ruleprec
->content
;
690 /* An item ends by the rule number (negated). */
691 ritem
[itemno
++] = rule_number_as_item_number (ruleno
);
692 aver (itemno
< ITEM_NUMBER_MAX
);
694 aver (ruleno
< RULE_NUMBER_MAX
);
697 aver (itemno
== nritems
);
699 if (trace_flag
& trace_sets
)
700 ritem_print (stderr
);
704 /*--------------------------------------------------------------.
705 | Read in the grammar specification and record it in the format |
706 | described in gram.h. |
707 `--------------------------------------------------------------*/
710 reader (const char *gram
)
712 /* Set up symbol_table, semantic_type_table, and the built-in
716 gram_scanner_open (gram
);
719 gram_scanner_close ();
721 prepare_percent_define_front_end_variables ();
723 if (complaint_status
< status_complaint
)
724 check_and_convert_grammar ();
728 prepare_percent_define_front_end_variables (void)
730 /* Set %define front-end variable defaults. */
731 muscle_percent_define_default ("lr.keep-unreachable-state", "false");
733 /* IELR would be a better default, but LALR is historically the
735 muscle_percent_define_default ("lr.type", "lalr");
736 char *lr_type
= muscle_percent_define_get ("lr.type");
737 if (STRNEQ (lr_type
, "canonical-lr"))
738 muscle_percent_define_default ("lr.default-reduction", "most");
740 muscle_percent_define_default ("lr.default-reduction", "accepting");
744 /* Check %define front-end variables. */
746 static char const * const values
[] =
748 "lr.type", "lr""(0)", "lalr", "ielr", "canonical-lr", NULL
,
749 "lr.default-reduction", "most", "consistent", "accepting", NULL
,
752 muscle_percent_define_check_values (values
);
756 /* Find the first LHS which is not a dummy. */
759 find_start_symbol (void)
761 symbol_list
*res
= grammar
;
762 /* Skip all the possible dummy rules of the first rule. */
763 for (; symbol_is_dummy (res
->content
.sym
); res
= res
->next
)
764 /* Skip the LHS, and then all the RHS of the dummy rule. */
765 for (res
= res
->next
; res
->content
.sym
; res
= res
->next
)
767 return res
->content
.sym
;
771 /*-------------------------------------------------------------.
772 | Check the grammar that has just been read, and convert it to |
774 `-------------------------------------------------------------*/
777 check_and_convert_grammar (void)
779 /* Grammar has been read. Do some checking. */
781 complain (NULL
, fatal
, _("no rules in the input grammar"));
783 /* If the user did not define her EOFTOKEN, do it now. */
786 eoftoken
= symbol_get ("YYEOF", empty_loc
);
787 eoftoken
->content
->class = token_sym
;
788 eoftoken
->content
->number
= 0;
789 /* Value specified by POSIX. */
790 eoftoken
->content
->code
= 0;
792 symbol
*alias
= symbol_get ("$end", empty_loc
);
793 symbol_class_set (alias
, token_sym
, empty_loc
, false);
794 symbol_make_alias (eoftoken
, alias
, empty_loc
);
798 /* Report any undefined symbols and consider them nonterminals. */
799 symbols_check_defined ();
801 /* Find the start symbol if no %start. */
804 symbol
*start
= find_start_symbol ();
805 grammar_start_symbol_set (start
, start
->location
);
808 /* Insert the initial rule, whose line is that of the first rule
809 (not that of the start symbol):
811 $accept: %start $end. */
813 symbol_list
*p
= symbol_list_sym_new (acceptsymbol
, empty_loc
);
814 p
->rhs_loc
= grammar
->rhs_loc
;
815 p
->next
= symbol_list_sym_new (startsymbol
, empty_loc
);
816 p
->next
->next
= symbol_list_sym_new (eoftoken
, empty_loc
);
817 p
->next
->next
->next
= symbol_list_sym_new (NULL
, empty_loc
);
818 p
->next
->next
->next
->next
= grammar
;
824 if (SYMBOL_NUMBER_MAXIMUM
- nnterms
< ntokens
)
825 complain (NULL
, fatal
, "too many symbols in input grammar (limit is %d)",
826 SYMBOL_NUMBER_MAXIMUM
);
828 nsyms
= ntokens
+ nnterms
;
830 /* Assign the symbols their symbol numbers. */
833 /* Scan rule actions after invoking symbol_check_alias_consistency
834 (in symbols_pack above) so that token types are set correctly
835 before the rule action type checking.
837 Before invoking grammar_rule_check_and_complete (in packgram
838 below) on any rule, make sure all actions have already been
839 scanned in order to set 'used' flags. Otherwise, checking that a
840 midrule's $$ should be set will not always work properly because
841 the check must forward-reference the midrule's parent rule. For
842 the same reason, all the 'used' flags must be set before checking
843 whether to remove '$' from any midrule symbol name (also in
845 for (symbol_list
*sym
= grammar
; sym
; sym
= sym
->next
)
846 code_props_translate_code (&sym
->action_props
);
848 /* Convert the grammar into the format described in gram.h. */
851 /* The grammar as a symbol_list is no longer needed. */
852 symbol_list_free (grammar
);