-
-static void
-readgram (void)
-{
- token_t t;
- symbol_t *lhs = NULL;
-
- t = lex ();
-
- while (t != tok_two_percents && t != tok_eof)
- if (t == tok_identifier || t == tok_bar)
- {
- if (t == tok_identifier)
- {
- lhs = symval;
-
- t = lex ();
- if (t != tok_colon)
- {
- complain (_("ill-formed rule: initial symbol not followed by colon"));
- unlex (t);
- }
- }
- if (nrules == 0 && t == tok_bar)
- {
- complain (_("grammar starts with vertical bar"));
- lhs = symval; /* BOGUS: use a random symval */
- }
-
- grammar_rule_begin (lhs);
- /* read the rhs of the rule. */
-
- for (;;)
- {
- t = lex ();
- if (t == tok_prec)
- {
- t = lex ();
- grammar_current_rule_prec_set (symval);
- t = lex ();
- }
-
- if (!(t == tok_identifier || t == tok_left_curly))
- break;
-
- /* If next token is an identifier, see if a colon follows it.
- If one does, exit this rule now. */
- if (t == tok_identifier)
- {
- symbol_t *ssave;
- token_t t1;
-
- ssave = symval;
- t1 = lex ();
- unlex (t1);
- symval = ssave;
- if (t1 == tok_colon)
- {
- warn (_("previous rule lacks an ending `;'"));
- break;
- }
- /* Not followed by colon => process as part of this
- rule's rhs. */
- }
-
- if (t == tok_identifier)
- {
- grammar_current_rule_symbol_append (symval);
- }
- else /* handle an action. */
- {
- int action_line = lineno;
- char *action = parse_action (current_rule);
- grammar_current_rule_action_append (action, action_line);
- }
- } /* end of read rhs of rule */
-
- /* Put an empty link in the list to mark the end of this rule */
- grammar_symbol_append (NULL);
-
- if (t == tok_prec)
- {
- t = lex ();
- grammar_current_rule_prec_set (symval);
- t = lex ();
- }
-
- if (t == tok_left_curly)
- {
- int action_line = lineno;
- char *action = parse_action (current_rule);
- grammar_current_rule_action_append (action, action_line);
- t = lex ();
- }
-
- grammar_current_rule_check ();
-
- if (t == tok_two_percents || t == tok_eof)
- warn (_("previous rule lacks an ending `;'"));
- if (t == tok_semicolon)
- t = lex ();
- }
- else
- {
- complain (_("invalid input: %s"), quote (token_buffer));
- t = lex ();
- }
-
- /* grammar has been read. Do some checking */
-
- if (nrules == 0)
- fatal (_("no rules in the input grammar"));
-
- /* Report any undefined symbols and consider them nonterminals. */
- symbols_check_defined ();
-
- /* Insert the initial rule, which line is that of the first rule
- (not that of the start symbol):
-
- axiom: %start EOF. */
- {
- symbol_list *p = symbol_list_new (axiom);
- p->line = grammar->line;
- p->next = symbol_list_new (startsymbol);
- p->next->next = symbol_list_new (eoftoken);
- p->next->next->next = symbol_list_new (NULL);
- p->next->next->next->next = grammar;
- nrules += 1;
- nritems += 3;
- grammar = p;
- }
-
- if (nsyms > SHRT_MAX)
- fatal (_("too many symbols (tokens plus nonterminals); maximum %d"),
- SHRT_MAX);
-
- assert (nsyms == ntokens + nvars);
-}
-
-/* At the end of the grammar file, some C source code must
- be stored. It is going to be associated to the epilogue
- directive. */
-static void
-read_additionnal_code (void)