diff options
author | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2016-02-12 13:56:29 -0500 |
---|---|---|
committer | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2016-02-12 13:56:29 -0500 |
commit | 8b81a5acc680aa5ceb788f6be4b90620839e983a (patch) | |
tree | 3e717be39b1ca33fce00eaa035248df8326e6300 | |
parent | 7b5e84a5d0338067389bd95761fa8f5a40fe871d (diff) | |
download | roux-8b81a5acc680aa5ceb788f6be4b90620839e983a.tar.gz |
scan ints using scanf
-rw-r--r-- | lisc/parse.c | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/lisc/parse.c b/lisc/parse.c index a77904c..9b820e4 100644 --- a/lisc/parse.c +++ b/lisc/parse.c @@ -165,7 +165,7 @@ lex() { 0, TXXX } }; static char tok[NString]; - int c, i, sgn; + int c, i; int t; do @@ -188,7 +188,7 @@ lex() return TEq; case '`': if (fscanf(inf, "%lf", &tokval.flt) != 1) - err("invalid floating point"); + err("invalid floating point literal"); return TFlt; case '%': t = TTmp; @@ -209,23 +209,10 @@ lex() lnum++; return TNL; } - if (isdigit(c) || c == '-') { - if (c == '-') { - tokval.num = 0; - sgn = -1; - } else { - tokval.num = c - '0'; - sgn = 1; - } - for (;;) { - c = fgetc(inf); - if (!isdigit(c)) - break; - tokval.num *= 10; - tokval.num += c - '0'; - } + if (isdigit(c) || c == '-' || c == '+') { ungetc(c, inf); - tokval.num *= sgn; + if (fscanf(inf, "%"SCNd64, &tokval.num) != 1) + err("invalid integer literal"); return TInt; } if (c == '"') { |