Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Calc: Fixed handling of negative numbers without brackets

"5+-1" is now valid and equal to "5+(-1)".
  • Loading branch information...
commit 0b84213eb65534736bf639d3ca75a180e53aa9a6 1 parent 4e16218
@poiru poiru authored
Showing with 11 additions and 2 deletions.
  1. +11 −2 Library/MathParser.cpp
View
13 Library/MathParser.cpp
@@ -67,6 +67,7 @@ enum CharType
CH_DIGIT = 0x02,
CH_SEPARAT = 0x04,
CH_SYMBOL = 0x08,
+ CH_MINUS = 0x10,
CH_FINAL = 0x7F
};
@@ -598,7 +599,13 @@ MathTokenType GetNextToken(Lexer& lexer)
{
lexer.charType = GetCharType(*++lexer.string);
}
-
+
+ if (lexer.charType == CH_MINUS)
+ {
+ // If the - sign follows a symbol, it is treated as a (negative) number.
+ lexer.charType = (lexer.prevToken == TOK_SYMBOL) ? CH_DIGIT : CH_SYMBOL;
+ }
+
switch (lexer.charType)
{
case CH_FINAL:
@@ -705,8 +712,10 @@ CharType GetCharType(WCHAR ch)
case L'_':
return CH_LETTER;
- case L'+':
case L'-':
+ return CH_MINUS;
+
+ case L'+':
case L'/':
case L'*':
case L'~':

2 comments on commit 0b84213

@spx268
Collaborator

For instance, "W=(((#WORKAREAWIDTH#-228)/3)-125)" is broken.
"W=(((#WORKAREAWIDTH#-228)/3)+-125)" works.

@poiru
Owner

@spx268: Thanks, 0d8e8ac should fix it.

Please sign in to comment.
Something went wrong with that request. Please try again.