X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/d2729d44ab05f89e96d199ad6b10e127c1cb0a38..3628146521aa93cdd499fa5058d21c7be33014bf:/src/lex.c diff --git a/src/lex.c b/src/lex.c index f0fbf485..b59793bc 100644 --- a/src/lex.c +++ b/src/lex.c @@ -1,21 +1,22 @@ /* Token-reader for Bison's input parser, - Copyright (C) 1984, 1986, 1989, 1992 Free Software Foundation, Inc. + Copyright (C) 1984, 1986, 1989, 1992, 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. */ /* @@ -32,6 +33,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "symtab.h" #include "lex.h" #include "alloc.h" +#include "complain.h" /* flags set by % directives */ extern int definesflag; /* for -d */ @@ -46,7 +48,6 @@ extern char *spec_name_prefix; /* for -p */ extern char *spec_file_prefix; /* for -b */ /*spec_outfile is declared in files.h, for -o */ -extern int lineno; extern int translations; void init_lex PARAMS((void)); @@ -60,10 +61,6 @@ int parse_percent_token PARAMS((void)); /* functions from main.c */ extern char *printable_version PARAMS((int)); -extern void fatal PARAMS((char *)); -extern void warn PARAMS((char *)); -extern void warni PARAMS((char *, int)); -extern void warns PARAMS((char *, char *)); /* Buffer for storing the current token. */ char *token_buffer; @@ -115,7 +112,7 @@ skip_white_space (void) c = getc(finput); if (c != '*' && c != '/') { - warn(_("unexpected `/' found and ignored")); + complain (_("unexpected `/' found and ignored")); break; } cplus_comment = (c == '/'); @@ -144,7 +141,7 @@ skip_white_space (void) c = getc(finput); } else if (c == EOF) - fatal(_("unterminated comment")); + fatal (_("unterminated comment")); else c = getc(finput); } @@ -161,7 +158,7 @@ skip_white_space (void) break; default: - return (c); + return c; } } } @@ -172,7 +169,7 @@ safegetc (FILE *f) { register int c = getc(f); if (c == EOF) - fatal(_("Unexpected end of file")); + fatal (_("unexpected end of file")); return c; } @@ -193,7 +190,7 @@ literalchar (char **pp, int *pcode, char term) c = safegetc(finput); if (c == '\n') { - warn(_("unescaped newline in constant")); + complain (_("unescaped newline in constant")); ungetc(c, finput); code = '?'; wasquote = 1; @@ -225,7 +222,8 @@ literalchar (char **pp, int *pcode, char term) code = (code * 8) + (c - '0'); if (code >= 256 || code < 0) { - warni(_("octal value outside range 0...255: `\\%o'"), code); + complain (_("octal value outside range 0...255: `\\%o'"), + code); code &= 0xFF; break; } @@ -249,7 +247,8 @@ literalchar (char **pp, int *pcode, char term) break; if (code >= 256 || code<0) { - warni(_("hexadecimal value above 255: `\\x%x'"), code); + complain (_("hexadecimal value above 255: `\\x%x'"), + code); code &= 0xFF; break; } @@ -259,8 +258,8 @@ literalchar (char **pp, int *pcode, char term) } else { - warns (_("unknown escape sequence: `\\' followed by `%s'"), - printable_version(c)); + complain (_("unknown escape sequence: `\\' followed by `%s'"), + printable_version(c)); code = '?'; } } /* has \ */ @@ -270,7 +269,9 @@ literalchar (char **pp, int *pcode, char term) so that `\012' and `\n' can be interchangeable. */ p = *pp; - if (code == '\\') {*p++ = '\\'; *p++ = '\\';} + if (code == term && wasquote) + *p++ = code; + else if (code == '\\') {*p++ = '\\'; *p++ = '\\';} else if (code == '\'') {*p++ = '\\'; *p++ = '\'';} else if (code == '\"') {*p++ = '\\'; *p++ = '\"';} else if (code >= 040 && code < 0177) @@ -313,7 +314,7 @@ lex (void) symval = unlexed_symval; c = unlexed; unlexed = -1; - return (c); + return c; } c = skip_white_space(); @@ -324,7 +325,7 @@ lex (void) { case EOF: strcpy(token_buffer, "EOF"); - return (ENDFILE); + return ENDFILE; case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': @@ -352,7 +353,7 @@ lex (void) *p = 0; ungetc(c, finput); symval = getsym(token_buffer); - return (IDENTIFIER); + return IDENTIFIER; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': @@ -371,7 +372,7 @@ lex (void) } *p = 0; ungetc(c, finput); - return (NUMBER); + return NUMBER; } case '\'': @@ -390,7 +391,7 @@ lex (void) c = getc(finput); if (c != '\'') { - warn(_("use \"...\" for multi-character literal tokens")); + complain (_("use \"...\" for multi-character literal tokens")); while (1) { dp = discard; @@ -404,7 +405,7 @@ lex (void) symval->class = STOKEN; if (! symval->user_token_number) symval->user_token_number = code; - return (IDENTIFIER); + return IDENTIFIER; } case '\"': @@ -426,23 +427,23 @@ lex (void) symval = getsym(token_buffer); symval->class = STOKEN; - return (IDENTIFIER); + return IDENTIFIER; } case ',': - return (COMMA); + return COMMA; case ':': - return (COLON); + return COLON; case ';': - return (SEMICOLON); + return SEMICOLON; case '|': - return (BAR); + return BAR; case '{': - return (LEFT_CURLY); + return LEFT_CURLY; case '=': do @@ -455,12 +456,12 @@ lex (void) if (c == '{') { strcpy(token_buffer, "={"); - return(LEFT_CURLY); + return LEFT_CURLY; } else { ungetc(c, finput); - return(ILLEGAL); + return ILLEGAL; } case '<': @@ -469,10 +470,10 @@ lex (void) while (c != '>') { if (c == EOF) - fatal(_("unterminated type name at end of file")); + fatal (_("unterminated type name at end of file")); if (c == '\n') { - warn(_("unterminated type name")); + complain (_("unterminated type name")); ungetc(c, finput); break; } @@ -484,14 +485,14 @@ lex (void) c = getc(finput); } *p = 0; - return (TYPENAME); + return TYPENAME; case '%': - return (parse_percent_token()); + return parse_percent_token(); default: - return (ILLEGAL); + return ILLEGAL; } } @@ -569,28 +570,28 @@ parse_percent_token (void) switch (c) { case '%': - return (TWO_PERCENTS); + return TWO_PERCENTS; case '{': - return (PERCENT_LEFT_CURLY); + return PERCENT_LEFT_CURLY; case '<': - return (LEFT); + return LEFT; case '>': - return (RIGHT); + return RIGHT; case '2': - return (NONASSOC); + return NONASSOC; case '0': - return (TOKEN); + return TOKEN; case '=': - return (PREC); + return PREC; } if (!isalpha(c)) - return (ILLEGAL); + return ILLEGAL; p = token_buffer; *p++ = '%';