X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/118fb2053c4c335c7d85dd117783fe4edca2be09..41aca2e038810d45e67d0348f3ca91ac6e0f0ff3:/src/reader.c?ds=inline diff --git a/src/reader.c b/src/reader.c index d3b4caf0..36af4646 100644 --- a/src/reader.c +++ b/src/reader.c @@ -1,29 +1,31 @@ /* Input parser for bison - Copyright (C) 1984, 1986, 1989, 1992 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, 675 Mass Ave, Cambridge, MA 02139, 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" @@ -107,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; @@ -133,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) @@ -206,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. */ @@ -238,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) @@ -488,8 +490,13 @@ parse_token_decl (int what_is, int what_is_not) for (;;) { - if(ungetc(skip_white_space(), finput) == '%') + int tmp_char = ungetc (skip_white_space (), finput); + + if (tmp_char == '%') return; + if (tmp_char == EOF) + fatals ("Premature EOF after %s", token_buffer); + token = lex(); if (token == COMMA) { @@ -671,9 +678,12 @@ parse_type_decl (void) for (;;) { register int t; + int tmp_char = ungetc (skip_white_space (), finput); - if(ungetc(skip_white_space(), finput) == '%') + if (tmp_char == '%') return; + if (tmp_char == EOF) + fatals ("Premature EOF after %s", token_buffer); t = lex(); @@ -716,9 +726,12 @@ parse_assoc_decl (int assoc) for (;;) { register int t; + int tmp_char = ungetc (skip_white_space (), finput); - if(ungetc(skip_white_space(), finput) == '%') + if (tmp_char == '%') return; + if (tmp_char == EOF) + fatals ("Premature EOF after %s", token_buffer); t = lex(); @@ -961,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) @@ -985,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; @@ -1124,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); @@ -1199,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) @@ -1216,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); @@ -1349,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 == '-') { @@ -1448,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; @@ -1751,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 @@ -1797,7 +1814,7 @@ get_type (void) } } } - +#endif /* assign symbol numbers, and write definition of token names into fdefines.