X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/a44c227773ad3beed8774de4817acedde0452c20..9ee3c97bce44d60cbb1025f782bc3676aa23d395:/src/lex.c?ds=sidebyside diff --git a/src/lex.c b/src/lex.c index 7ae1387e..3a51c974 100644 --- a/src/lex.c +++ b/src/lex.c @@ -15,10 +15,11 @@ 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. */ +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ -/* +/* lex is the entry point. It is called from reader.c. It returns one of the token-type codes defined in lex.h. When an identifier is seen, the code IDENTIFIER is returned @@ -26,13 +27,12 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ symval is set to a pointer to the entry found. */ #include -#include #include "system.h" #include "files.h" #include "getopt.h" /* for optarg */ #include "symtab.h" #include "lex.h" -#include "new.h" +#include "alloc.h" /* flags set by % directives */ extern int definesflag; /* for -d */ @@ -50,19 +50,27 @@ extern char *spec_file_prefix; /* for -b */ extern int lineno; extern int translations; -int parse_percent_token(); +void init_lex PARAMS((void)); +char *grow_token_buffer PARAMS((char *)); +int skip_white_space PARAMS((void)); +int safegetc PARAMS((FILE *)); +int literalchar PARAMS((char **, int *, char)); +void unlex PARAMS((int)); +int lex PARAMS((void)); +int parse_percent_token PARAMS((void)); /* functions from main.c */ -extern char *printable_version(); -extern void fatal(); -extern void warni(); -extern void warn(); +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; /* Allocated size of token_buffer, not including space for terminator. */ -static int maxtoken; +int maxtoken; bucket *symval; int numval; @@ -72,7 +80,7 @@ static bucket *unlexed_symval; /* by the next call to lex */ void -init_lex() +init_lex (void) { maxtoken = 100; token_buffer = NEW2 (maxtoken + 1, char); @@ -80,9 +88,8 @@ init_lex() } -static char * -grow_token_buffer (p) - char *p; +char * +grow_token_buffer (char *p) { int offset = p - token_buffer; maxtoken *= 2; @@ -92,7 +99,7 @@ grow_token_buffer (p) int -skip_white_space() +skip_white_space (void) { register int c; register int inside; @@ -107,9 +114,9 @@ skip_white_space() { case '/': c = getc(finput); - if (c != '*' && c != '/') + if (c != '*' && c != '/') { - warn("unexpected `/' found and ignored"); + warn(_("unexpected `/' found and ignored")); break; } cplus_comment = (c == '/'); @@ -138,7 +145,7 @@ skip_white_space() c = getc(finput); } else if (c == EOF) - fatal("unterminated comment"); + fatal(_("unterminated comment")); else c = getc(finput); } @@ -162,12 +169,11 @@ skip_white_space() /* do a getc, but give error message if EOF encountered */ int -safegetc(f) - FILE *f; +safegetc (FILE *f) { register int c = getc(f); if (c == EOF) - fatal("Unexpected end of file"); + fatal(_("Unexpected end of file")); return c; } @@ -178,10 +184,7 @@ safegetc(f) report error for \n */ int -literalchar(pp, pcode, term) - char **pp; - int *pcode; - char term; +literalchar (char **pp, int *pcode, char term) { register int c; register char *p; @@ -189,9 +192,9 @@ literalchar(pp, pcode, term) int wasquote = 0; c = safegetc(finput); - if (c == '\n') + if (c == '\n') { - warn("unescaped newline in constant"); + warn(_("unescaped newline in constant")); ungetc(c, finput); code = '?'; wasquote = 1; @@ -199,7 +202,7 @@ literalchar(pp, pcode, term) else if (c != '\\') { code = c; - if (c == term) + if (c == term) wasquote = 1; } else @@ -211,7 +214,7 @@ literalchar(pp, pcode, term) else if (c == 'r') code = '\r'; else if (c == 'f') code = '\f'; else if (c == 'b') code = '\b'; - else if (c == 'v') code = 013; + else if (c == 'v') code = '\013'; else if (c == '\\') code = '\\'; else if (c == '\'') code = '\''; else if (c == '\"') code = '\"'; @@ -223,7 +226,7 @@ literalchar(pp, pcode, term) code = (code * 8) + (c - '0'); if (code >= 256 || code < 0) { - warni("octal value outside range 0...255: `\\%o'", code); + warni(_("octal value outside range 0...255: `\\%o'"), code); code &= 0xFF; break; } @@ -243,11 +246,11 @@ literalchar(pp, pcode, term) code *= 16, code += c - 'a' + 10; else if (c >= 'A' && c <= 'F') code *= 16, code += c - 'A' + 10; - else + else break; if (code >= 256 || code<0) { - warni("hexadecimal value above 255: `\\x%x'", code); + warni(_("hexadecimal value above 255: `\\x%x'"), code); code &= 0xFF; break; } @@ -257,7 +260,7 @@ literalchar(pp, pcode, term) } else { - warni ("unknown escape sequence: `\\' followed by `%s'", + warns (_("unknown escape sequence: `\\' followed by `%s'"), printable_version(c)); code = '?'; } @@ -268,11 +271,13 @@ literalchar(pp, pcode, term) so that `\012' and `\n' can be interchangeable. */ p = *pp; - if (code >= 040 && code < 0177) + 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) + *p++ = code; else if (code == '\t') {*p++ = '\\'; *p++ = 't';} else if (code == '\n') {*p++ = '\\'; *p++ = 'n';} else if (code == '\r') {*p++ = '\\'; *p++ = 'r';} @@ -293,8 +298,7 @@ literalchar(pp, pcode, term) void -unlex(token) - int token; +unlex (int token) { unlexed = token; unlexed_symval = symval; @@ -302,7 +306,7 @@ unlex(token) int -lex() +lex (void) { register int c; char *p; @@ -381,6 +385,7 @@ lex() { int code, discode; char discard[10], *dp; + p = token_buffer; *p++ = '\''; literalchar(&p, &code, '\''); @@ -388,9 +393,13 @@ lex() c = getc(finput); if (c != '\'') { - warn("use \"...\" for multi-character literal tokens"); - dp = discard; - while (literalchar(&dp, &discode, '\'')) {} + warn(_("use \"...\" for multi-character literal tokens")); + while (1) + { + dp = discard; + if (! literalchar(&dp, &discode, '\'')) + break; + } } *p++ = '\''; *p = 0; @@ -463,10 +472,10 @@ lex() while (c != '>') { if (c == EOF) - fatal("unterminated type name at end of file"); - if (c == '\n') + fatal(_("unterminated type name at end of file")); + if (c == '\n') { - warn("unterminated type name"); + warn(_("unterminated type name")); ungetc(c, finput); break; } @@ -479,7 +488,7 @@ lex() } *p = 0; return (TYPENAME); - + case '%': return (parse_percent_token()); @@ -489,13 +498,13 @@ lex() } } -/* the following table dictates the action taken for the various +/* the following table dictates the action taken for the various % directives. A setflag value causes the named flag to be set. A retval action returns the code. */ struct percent_table_struct { char *name; - void *setflag; + void *setflag; int retval; } percent_table[] = { @@ -537,8 +546,8 @@ struct percent_table_struct { /* These would be acceptable, but they do not affect processing */ {"verbose", &verboseflag, NOOP}, /* -v */ {"debug", &debugflag, NOOP}, /* -t */ - /* {"help", , NOOP}, /* -h */ - /* {"version", , NOOP}, /* -V */ + /* {"help", , NOOP},*/ /* -h */ + /* {"version", , NOOP},*/ /* -V */ #endif {NULL, NULL, ILLEGAL} @@ -548,7 +557,7 @@ struct percent_table_struct { Assumes the % has already been read and discarded. */ int -parse_percent_token () +parse_percent_token (void) { register int c; register char *p; @@ -583,7 +592,7 @@ parse_percent_token () case '=': return (PREC); } - if (!isalpha(c)) + if (!isalpha(c)) return (ILLEGAL); p = token_buffer;