]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
Expression eval: Repair unary + and -
authorLeo C <erbl259-lmu@yahoo.de>
Tue, 21 Jun 2016 21:14:01 +0000 (23:14 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Tue, 21 Jun 2016 21:14:01 +0000 (23:14 +0200)
avr/eval_arg.c

index 020dd98369346808dde400ba53ee39c2166f8737..b93150935cdb1983dabf8b66ff2ee39b3d81307d 100644 (file)
@@ -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;