+\f
+/*-------------------------------------------------------------------.
+| Read in the grammar specification and record it in the format |
+| described in gram.h. All guards are copied into the FGUARD file |
+| and all actions into FACTION, 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. */
+
+#if 0
+ /* initially assume token number translation not needed. */
+ translations = 0;
+#endif
+ /* Nowadays translations is always set to 1, since we give `error' a
+ user-token-number to satisfy the Posix demand for YYERRCODE==256.
+ */
+ translations = 1;
+
+ nsyms = 1;
+ nvars = 0;
+ nrules = 0;
+ nitems = 0;
+ rline_allocated = 10;
+ rline = XCALLOC (short, rline_allocated);
+
+ typed = 0;
+ lastprec = 0;
+
+ gensym_count = 0;
+
+ semantic_parser = 0;
+ pure_parser = 0;
+
+ grammar = NULL;
+
+ init_lex ();
+ lineno = 1;
+
+ /* Initialize the symbol table. */
+ tabinit ();
+ /* 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;
+
+ /* Read the declaration section. Copy %{ ... %} groups to FTABLE
+ and FDEFINES file. Also notice any %token, %left, etc. found
+ there. */
+ putc ('\n', ftable);
+ fprintf (ftable, "\
+/* %s, made from %s\n\
+ by GNU bison %s. */\n\
+\n", no_parser_flag ? "Bison-generated parse tables" : "A Bison parser", infile, VERSION);
+
+ fputs ("#define YYBISON 1 /* Identify Bison output. */\n\n", ftable);
+ read_declarations ();
+ /* Start writing the guard and action files, if they are needed. */
+ output_headers ();
+ /* Read in the grammar, build grammar in list form. Write out
+ guards and actions. */
+ readgram ();
+ /* Now we know whether we need the line-number stack. If we do,
+ write its type into the .tab.h file. */
+ if (fdefines)
+ reader_output_yylsp (fdefines);
+ /* Write closing delimiters for actions and guards. */
+ output_trailers ();
+ if (locations_flag)
+ fputs ("#define YYLSP_NEEDED\n\n", ftable);
+ /* 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 ();
+ /* Free the symbol table data structure since symbols are now all
+ referred to by symbol number. */
+ free_symtab ();
+}
+
+
+void
+reader_output_yylsp (FILE *f)
+{
+ if (locations_flag)
+ fputs ("\
+\n\
+#ifndef YYLTYPE\n\
+typedef struct yyltype\n\
+{\n\
+ int timestamp;\n\
+ int first_line;\n\
+ int first_column;\
+\n\
+ int last_line;\n\
+ int last_column;\n\
+ char *text;\n\
+} yyltype;\n\
+\n\
+# define YYLTYPE yyltype\n\
+#endif\n\
+\n",
+ f);
+}