+ nritems = itemno;
+ assert (nritems == nitems);
+
+ if (trace_flag)
+ ritem_print (stderr);
+}
+\f
+/*-------------------------------------------------------------------.
+| Read in the grammar specification and record it in the format |
+| described in gram.h. All guards are copied into the GUARD_OBSTACK |
+| and all actions into ACTION_OBSTACK, in each case forming the body |
+| of a C function (YYGUARD or YYACTION) which contains a switch |
+| statement to decide which guard or action to execute. |
+`-------------------------------------------------------------------*/
+
+void
+reader (void)
+{
+ start_flag = 0;
+ startval = NULL; /* start symbol not specified yet. */
+
+ nsyms = 0;
+ nvars = 0;
+ nrules = 0;
+ nitems = 0;
+
+ typed = 0;
+ lastprec = 0;
+
+ semantic_parser = 0;
+ pure_parser = 0;
+
+ grammar = NULL;
+
+ lex_init ();
+ lineno = 1;
+
+ /* Initialize the muscle obstack. */
+ obstack_init (&muscle_obstack);
+
+ /* Initialize the symbol table. */
+ tabinit ();
+
+ /* Construct the axiom symbol. */
+ axiom = getsym ("$axiom");
+ axiom->class = nterm_sym;
+ axiom->value = nvars++;
+
+ /* Construct the error token */
+ errtoken = getsym ("error");
+ errtoken->class = token_sym;
+ errtoken->user_token_number = 256; /* Value specified by POSIX. */
+
+ /* Construct a token that represents all undefined literal tokens.
+ It is always token number 2. */
+ undeftoken = getsym ("$undefined.");
+ undeftoken->class = token_sym;
+ undeftoken->user_token_number = 2;
+
+ /* Initialize the obstacks. */
+ obstack_init (&action_obstack);
+ obstack_init (&attrs_obstack);
+ obstack_init (&output_obstack);
+
+ finput = xfopen (infile, "r");
+
+ /* Read the declaration section. Copy %{ ... %} groups to
+ TABLE_OBSTACK and FDEFINES file. Also notice any %token, %left,
+ etc. found there. */
+ read_declarations ();
+
+ /* If the user did not define her EOFTOKEN, do it now. */
+ if (!eoftoken)
+ {
+ eoftoken = getsym ("$");
+ eoftoken->class = token_sym;
+ /* Value specified by POSIX. */
+ eoftoken->user_token_number = 0;
+ }
+
+ /* Read in the grammar, build grammar in list form. Write out
+ guards and actions. */
+ readgram ();
+ /* Some C code is given at the end of the grammar file. */
+ read_additionnal_code ();
+
+ lex_free ();
+ xfclose (finput);
+
+ /* Assign the symbols their symbol numbers. Write #defines for the
+ token symbols into FDEFINES if requested. */
+ packsymbols ();
+
+ /* Convert the grammar into the format described in gram.h. */
+ packgram ();
+
+ /* The grammar as a symbol_list is no longer needed. */
+ LIST_FREE (symbol_list, grammar);