scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit c7bc9f60fb5f56e9640a46e7dba71326b173ffe0
parent 69a0a3e07aee3304446942c49527d65ebc5f7c85
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 24 Sep 2017 08:33:17 +0200

[as] Fix end of string test in expr()

Diffstat:
Mas/expr.c | 26+++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/as/expr.c b/as/expr.c @@ -11,6 +11,7 @@ static char sccsid[] = "@(#) ./as/node.c"; #define NNODES 10 enum tokens { + EOS = -1, IDEN = 1, NUMBER, REG, @@ -244,21 +245,20 @@ next(void) endp = textp; if ((c = *textp) == '\0') { - strcpy(yytext, "EOF"); + strcpy(yytext, "EOS"); yylen = 3; - return EOF; - } - - if (isalpha(c) || c == '_' || c == '.') + c = EOS; + } else if (isalpha(c) || c == '_' || c == '.') { c = iden(); - else if (isdigit(c)) + } else if (isdigit(c)) { c = number(); - else if (c == '\"') + } else if (c == '\"') { c = string(); - else if (c == '\'') + } else if (c == '\'') { c = character(); - else + } else { c = operator(); + } return yytoken = c; } @@ -422,15 +422,15 @@ expr(char **s) { Node *np; - if (*s == '\0') + textp = *s; + if (*textp == '\0') return NULL; - textp = *s; next(); np = or(); - if (yytoken != ',' && yytoken != EOF) - error("trailing characters in expression '%s:%s'", *s, textp); + if (yytoken != ',' && yytoken != EOS) + error("trailing characters in expression '%s'", textp); *s = endp; return np;