diff options
author | Leo C | 2016-06-21 23:14:01 +0200 |
---|---|---|
committer | Leo C | 2016-06-21 23:14:01 +0200 |
commit | a11e60da10b1065dfcf57bb742670b74784703e2 (patch) | |
tree | 06356dbba5b8cec6aeb9bead4c4c039531acba65 | |
parent | 2d914b45c43c9a4c986e88428d1e28c0710ae298 (diff) | |
download | z180-stamp-a11e60da10b1065dfcf57bb742670b74784703e2.zip |
Expression eval: Repair unary + and -
-rw-r--r-- | avr/eval_arg.c | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/avr/eval_arg.c b/avr/eval_arg.c index 020dd98..b931509 100644 --- a/avr/eval_arg.c +++ b/avr/eval_arg.c @@ -38,7 +38,7 @@ static void next(void) { do ch = *bp++; - while (ch == ' ' || ch == '\n'); + while (isspace(ch)); } static long number (void) @@ -76,10 +76,15 @@ static long factor (void) next(); else error (); + } else { + char sign = ch; + if (sign == '+' || sign == '-') { + next(); + } + f = number(); + if (sign == '-') + f = -f; } - else - f = number (); - return f; } @@ -109,16 +114,7 @@ static long term (void) static long expr(void) { - long e; - - if (ch == '+') { - next(); - e = term (); - } else if (ch == '-') { - next(); - e = - term (); - } else - e = term (); + long e = term (); while (ch == '+' || ch == '-') { char op = ch; |