X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/c49a8e71cec845d32366432b824a9317e4a80160..41aca2e038810d45e67d0348f3ca91ac6e0f0ff3:/src/reader.c diff --git a/src/reader.c b/src/reader.c index 33332b59..36af4646 100644 --- a/src/reader.c +++ b/src/reader.c @@ -1,30 +1,31 @@ /* Input parser for bison - Copyright (C) 1984, 1986, 1989, 1992, 1998 Free Software Foundation, Inc. + Copyright (C) 1984, 86, 89, 92, 98, 2000 Free Software Foundation, Inc. -This file is part of Bison, the GNU Compiler Compiler. + This file is part of Bison, the GNU Compiler Compiler. -Bison is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. + Bison is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. -Bison is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + Bison is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with Bison; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ + You should have received a copy of the GNU General Public License + along with Bison; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ -/* 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. +/* 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. -The entry point is reader(). */ + The entry point is reader (). */ #include #include "system.h" @@ -108,8 +109,10 @@ void packsymbols PARAMS((void)); void output_token_defines PARAMS((FILE *)); void packgram PARAMS((void)); int read_signed_integer PARAMS((FILE *)); -static int get_type PARAMS((void)); +#if 0 +static int get_type PARAMS((void)); +#endif int lineno; symbol_list *grammar; @@ -134,8 +137,6 @@ static bucket *undeftoken; /* Nonzero if any action or guard uses the @n construct. */ static int yylsp_needed; -extern char *version_string; - static void skip_to_char (int target) @@ -207,7 +208,7 @@ reader (void) infile); else fprintf(ftable, "\n/* A Bison parser, made from %s\n", infile); - fprintf(ftable, " by %s */\n\n", version_string); + 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. */ @@ -239,9 +240,9 @@ reader_output_yylsp (FILE *f) fprintf(f, LTYPESTR); } -/* read from finput until %% is seen. Discard the %%. -Handle any % declarations, -and copy the contents of any %{ ... %} groups to fattrs. */ +/* Read from finput until `%%' is seen. Discard the `%%'. Handle any + `%' declarations, and copy the contents of any `%{ ... %}' groups + to fattrs. */ void read_declarations (void) @@ -973,12 +974,12 @@ get_type_name (int n, symbol_list *rule) } -/* after %guard is seen in the input file, -copy the actual guard into the guards file. -If the guard is followed by an action, copy that into the actions file. -stack_offset is the number of values in the current rule so far, -which says where to find $0 with respect to the top of the stack, -for the simple parser in which the stack is not popped until after the guard is run. */ +/* After `%guard' is seen in the input file, copy the actual guard + into the guards file. If the guard is followed by an action, copy + that into the actions file. STACK_OFFSET is the number of values + in the current rule so far, which says where to find `$0' with + respect to the top of the stack, for the simple parser in which the + stack is not popped until after the guard is run. */ void copy_guard (symbol_list *rule, int stack_offset) @@ -997,7 +998,7 @@ copy_guard (symbol_list *rule, int stack_offset) fprintf(fguard, "\ncase %d:\n", nrules); if (!nolinesflag) - fprintf(fguard, "#line %d \"%s\"\n", lineno, infile); + fprintf (fguard, "#line %d \"%s\"\n", lineno, infile); putc('{', fguard); count = 0; @@ -1136,18 +1137,18 @@ copy_guard (symbol_list *rule, int stack_offset) if (c == '$') { fprintf(fguard, "yyval"); - if (!type_name) type_name = rule->sym->type_name; + if (!type_name) + type_name = rule->sym->type_name; if (type_name) fprintf(fguard, ".%s", type_name); if(!type_name && typed) warns(_("$$ of `%s' has no declared type"), rule->sym->tag); } - else if (isdigit(c) || c == '-') { ungetc (c, finput); - n = read_signed_integer(finput); - c = getc(finput); + n = read_signed_integer (finput); + c = getc (finput); if (!type_name && n > 0) type_name = get_type_name(n, rule); @@ -1211,10 +1212,10 @@ copy_guard (symbol_list *rule, int stack_offset) -/* Assuming that a { has just been seen, copy everything up to the matching } -into the actions file. -stack_offset is the number of values in the current rule so far, -which says where to find $0 with respect to the top of the stack. */ +/* Assuming that a `{' has just been seen, copy everything up to the + matching `}' into the actions file. STACK_OFFSET is the number of + values in the current rule so far, which says where to find `$0' + with respect to the top of the stack. */ void copy_action (symbol_list *rule, int stack_offset) @@ -1228,12 +1229,13 @@ copy_action (symbol_list *rule, int stack_offset) int cplus_comment; /* offset is always 0 if parser has already popped the stack pointer */ - if (semantic_parser) stack_offset = 0; + if (semantic_parser) + stack_offset = 0; - fprintf(faction, "\ncase %d:\n", nrules); + fprintf (faction, "\ncase %d:\n", nrules); if (!nolinesflag) - fprintf(faction, "#line %d \"%s\"\n", lineno, infile); - putc('{', faction); + fprintf (faction, "#line %d \"%s\"\n", lineno, infile); + putc ('{', faction); count = 1; c = getc(finput); @@ -1361,11 +1363,13 @@ copy_action (symbol_list *rule, int stack_offset) if (c == '$') { fprintf(faction, "yyval"); - if (!type_name) type_name = get_type_name(0, rule); + if (!type_name) + type_name = get_type_name(0, rule); if (type_name) fprintf(faction, ".%s", type_name); if(!type_name && typed) - warns(_("$$ of `%s' has no declared type"), rule->sym->tag); + warns(_("$$ of `%s' has no declared type"), + rule->sym->tag); } else if (isdigit(c) || c == '-') { @@ -1460,7 +1464,7 @@ void readgram (void) { register int t; - register bucket *lhs; + register bucket *lhs = NULL; register symbol_list *p; register symbol_list *p1; register bucket *bp; @@ -1763,6 +1767,7 @@ record_rule_line (void) } +#if 0 /* read in a %type declaration and record its information for get_type_name to access */ /* this is unused. it is only called from the #if 0 part of readgram */ static int @@ -1809,7 +1814,7 @@ get_type (void) } } } - +#endif /* assign symbol numbers, and write definition of token names into fdefines.