The entry point is reader (). */
-#include <stdio.h>
#include "system.h"
+#include "getargs.h"
#include "files.h"
#include "alloc.h"
#include "symtab.h"
#include "lex.h"
#include "gram.h"
-#include "machine.h"
#include "complain.h"
+#include "output.h"
#define LTYPESTR "\
\n\
/* Number of slots allocated (but not necessarily used yet) in `rline' */
static int rline_allocated;
-extern int definesflag;
-extern int nolinesflag;
-extern int noparserflag;
-extern int rawtoknumflag;
extern bucket *symval;
extern int numval;
extern int expected_conflicts;
extern void init_lex PARAMS((void));
extern char *grow_token_buffer PARAMS((char *));
extern void tabinit PARAMS((void));
-extern void output_headers PARAMS((void));
-extern void output_trailers PARAMS((void));
extern void free_symtab PARAMS((void));
extern void open_extra_files PARAMS((void));
extern char *printable_version PARAMS((int));
static void packsymbols PARAMS((void));
static void output_token_defines PARAMS((FILE *));
static void packgram PARAMS((void));
-static int read_signed_integer PARAMS((FILE *));
#if 0
static int get_type PARAMS((void));
/* Nonzero if any action or guard uses the @n construct. */
static int yylsp_needed;
+\f
+/*===================\
+| Low level lexing. |
+\===================*/
static void
skip_to_char (int target)
complain (_(" Skipping to next %c"), target);
do
- c = skip_white_space();
+ c = skip_white_space ();
while (c != target && c != EOF);
if (c != EOF)
- ungetc(c, finput);
+ ungetc (c, finput);
}
-/* Dump the string from FIN to FOUT. MATCH is the delimiter of
- the string (either ' or "). */
+/*---------------------------------------------------------.
+| Read a signed integer from STREAM and return its value. |
+`---------------------------------------------------------*/
+
+static inline int
+read_signed_integer (FILE *stream)
+{
+ register int c = getc (stream);
+ register int sign = 1;
+ register int n = 0;
+
+ if (c == '-')
+ {
+ c = getc (stream);
+ sign = -1;
+ }
+
+ while (isdigit (c))
+ {
+ n = 10 * n + (c - '0');
+ c = getc (stream);
+ }
+
+ ungetc (c, stream);
+
+ return sign * n;
+}
+\f
+/*-------------------------------------------------------------------.
+| Dump the string from FINPUT to FOUTPUT. MATCH is the delimiter of |
+| the string (either ' or "). |
+`-------------------------------------------------------------------*/
static inline void
copy_string (FILE *fin, FILE *fout, int match)
}
-/* Dump the comment from IN to OUT1 and OUT2. C is either `*' or `/',
- depending upon the type of comments used. OUT2 might be NULL. */
+/*---------------------------------------------------------------.
+| Dump the comment from IN to OUT1 and OUT2. C is either `*' or |
+| `/', depending upon the type of comments used. OUT2 might be |
+| NULL. |
+`---------------------------------------------------------------*/
static inline void
copy_comment2 (FILE *in, FILE *out1, FILE* out2, int c)
startval = NULL; /* start symbol not specified yet. */
#if 0
- translations = 0; /* initially assume token number translation not needed. */
+ /* 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. */
+ /* 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;
nrules = 0;
nitems = 0;
rline_allocated = 10;
- rline = NEW2(rline_allocated, short);
+ rline = NEW2 (rline_allocated, short);
typed = 0;
lastprec = 0;
grammar = NULL;
- init_lex();
+ init_lex ();
lineno = 1;
- /* initialize the symbol table. */
- tabinit();
- /* construct the error token */
- errtoken = getsym("error");
+ /* Initialize the symbol table. */
+ tabinit ();
+ /* Construct the error token */
+ errtoken = getsym ("error");
errtoken->class = STOKEN;
- 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.");
+ 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 = STOKEN;
undeftoken->user_token_number = 2;
- /* Read the declaration section. Copy %{ ... %} groups to ftable and fdefines file.
- Also notice any %token, %left, etc. found there. */
- if (noparserflag)
- fprintf(ftable, "\n/* Bison-generated parse tables, made from %s\n",
- infile);
- else
- fprintf(ftable, "\n/* A Bison parser, made from %s\n", infile);
- fprintf(ftable, " by %s */\n\n", VERSION_STRING);
- fprintf(ftable, "#define YYBISON 1 /* Identify Bison output. */\n\n");
- 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. */
+
+ /* 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",
+ noparserflag ? "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();
+ reader_output_yylsp (fdefines);
+ /* Write closing delimiters for actions and guards. */
+ output_trailers ();
if (yylsp_needed)
- fprintf(ftable, "#define YYLSP_NEEDED\n\n");
- /* 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();
+ 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
ritem[itemno] = 0;
}
-\f
-/* Read a signed integer from STREAM and return its value. */
-
-static int
-read_signed_integer (FILE *stream)
-{
- register int c = getc(stream);
- register int sign = 1;
- register int n;
-
- if (c == '-')
- {
- c = getc(stream);
- sign = -1;
- }
- n = 0;
- while (isdigit(c))
- {
- n = 10*n + (c - '0');
- c = getc(stream);
- }
-
- ungetc(c, stream);
-
- return n * sign;
-}