summaryrefslogtreecommitdiffstats
path: root/contrib/one-true-awk/lex.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/one-true-awk/lex.c')
-rw-r--r--contrib/one-true-awk/lex.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/contrib/one-true-awk/lex.c b/contrib/one-true-awk/lex.c
index a947109..2b16b25 100644
--- a/contrib/one-true-awk/lex.c
+++ b/contrib/one-true-awk/lex.c
@@ -105,7 +105,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;
@@ -133,6 +133,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 */
@@ -151,11 +152,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 *);
@@ -186,7 +193,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);
@@ -311,6 +318,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);
@@ -366,6 +376,8 @@ int string(void)
case 0:
SYNTAX( "non-terminated string %.10s...", buf );
lineno++;
+ if (c == 0) /* hopeless */
+ FATAL( "giving up" );
break;
case '\\':
c = input();
OpenPOWER on IntegriCloud