diff options
Diffstat (limited to 'usr.bin/awk/lex.c')
-rw-r--r-- | usr.bin/awk/lex.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/usr.bin/awk/lex.c b/usr.bin/awk/lex.c index 809e190af8f..96d61ebdfc0 100644 --- a/usr.bin/awk/lex.c +++ b/usr.bin/awk/lex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lex.c,v 1.5 2001/09/08 00:12:40 millert Exp $ */ +/* $OpenBSD: lex.c,v 1.6 2002/12/19 21:24:28 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -39,7 +39,7 @@ int brackcnt = 0; int parencnt = 0; typedef struct Keyword { - char *word; + const char *word; int sub; int type; } Keyword; @@ -106,7 +106,7 @@ int peek(void) int gettok(char **pbuf, int *psz) /* get next input token */ { - int c; + int c, retc; char *buf = *pbuf; int sz = *psz; char *bp = buf; @@ -134,6 +134,7 @@ int gettok(char **pbuf, int *psz) /* get next input token */ } } *bp = 0; + retc = 'a'; /* alphanumeric */ } else { /* it's a number */ char *rem; /* read input until can't be a number */ @@ -152,11 +153,17 @@ int gettok(char **pbuf, int *psz) /* get next input token */ *bp = 0; strtod(buf, &rem); /* parse the number */ unputstr(rem); /* put rest back for later */ - rem[0] = 0; + if (rem == buf) { /* it wasn't a valid number at all */ + buf[1] = 0; /* so return one character as token */ + retc = buf[0]; /* character is its own type */ + } else { /* some prefix was a number */ + rem[0] = 0; /* so truncate where failure started */ + retc = '0'; /* number */ + } } *pbuf = buf; *psz = sz; - return buf[0]; + return retc; } int word(char *); @@ -187,7 +194,7 @@ int yylex(void) return 0; if (isalpha(c) || c == '_') return word(buf); - if (isdigit(c) || c == '.') { + if (isdigit(c)) { yylval.cp = setsymtab(buf, tostring(buf), atof(buf), CON|NUM, symtab); /* should this also have STR set? */ RET(NUMBER); @@ -312,6 +319,9 @@ int yylex(void) } yylval.cp = setsymtab(buf, "", 0.0, STR|NUM, symtab); RET(IVAR); + } else if (c == 0) { /* */ + SYNTAX( "unexpected end of input after $" ); + RET(';'); } else { unputstr(buf); RET(INDIRECT); @@ -367,6 +377,8 @@ int string(void) case 0: SYNTAX( "non-terminated string %.10s...", buf ); lineno++; + if (c == 0) /* hopeless */ + FATAL( "giving up" ); break; case '\\': c = input(); @@ -488,7 +500,7 @@ int word(char *w) } } -void startreg(void) /* next call to yyles will return a regular expression */ +void startreg(void) /* next call to yylex will return a regular expression */ { reg = 1; } @@ -563,7 +575,7 @@ void unput(int c) /* put lexical character back on input */ ep = ebuf + sizeof(ebuf) - 1; } -void unputstr(char *s) /* put a string back on input */ +void unputstr(const char *s) /* put a string back on input */ { int i; |