Browse files

Added support for the ÷ and × signs as operators

  • Loading branch information...
1 parent 5e8ddf0 commit 187c9023740f056a54fec2ec4a07f50b89a54a45 @davedelong committed Oct 18, 2011
Showing with 7 additions and 3 deletions.
  1. +2 −2 Command line demo/main.m
  2. +3 −1 DDMathParser/DDMathStringTokenizer.m
  3. +2 −0 DDMathParser/_DDOperatorInfo.m
View
4 Command line demo/main.m
@@ -6,15 +6,15 @@
void listFunctions(void);
NSString* readLine() {
- NSCharacterSet *valid = [DDMathStringTokenizer legalCharacters];
+// NSCharacterSet *valid = [DDMathStringTokenizer legalCharacters];
NSMutableData *data = [NSMutableData data];
do {
char c = getchar();
if (c > 0xffff) { continue; }
if ([[NSCharacterSet newlineCharacterSet] characterIsMember:(unichar)c]) { break; }
- if (![valid characterIsMember:(unichar)c]) { continue; }
+// if (![valid characterIsMember:(unichar)c]) { continue; }
[data appendBytes:&c length:sizeof(char)];
} while (1);
View
4 DDMathParser/DDMathStringTokenizer.m
@@ -60,7 +60,9 @@ + (NSCharacterSet *)_operatorCharacterSet {
// \u00AC is ¬
// \u2264 is ≤
// \u2265 is ≥
- _operatorSet = DD_RETAIN([NSCharacterSet characterSetWithCharactersInString:@"+-*/&|!%^~()<>,=\u2228\u2227\u00ac\u2264\u2265"]);
+ // \u00f7 is ÷
+ // \u00d7 is ×
+ _operatorSet = DD_RETAIN([NSCharacterSet characterSetWithCharactersInString:@"+-*/&|!%^~()<>,=\u2228\u2227\u00ac\u2264\u2265\u00f7\u00d7"]);
});
return _operatorSet;
}
View
2 DDMathParser/_DDOperatorInfo.m
@@ -141,7 +141,9 @@ + (NSArray *)_buildOperators {
// multiplication and division have the same precedence
[operators addObject:[self infoForOperator:DDOperatorMultiply arity:DDOperatorArityBinary precedence:precedence token:@"*" function:@"multiply" associativity:DDOperatorAssociativityLeft]];
+ [operators addObject:[self infoForOperator:DDOperatorMultiply arity:DDOperatorArityBinary precedence:precedence token:@"\u00d7" function:@"multiply" associativity:DDOperatorAssociativityLeft]];
[operators addObject:[self infoForOperator:DDOperatorDivide arity:DDOperatorArityBinary precedence:precedence token:@"/" function:@"divide" associativity:DDOperatorAssociativityLeft]];
+ [operators addObject:[self infoForOperator:DDOperatorDivide arity:DDOperatorArityBinary precedence:precedence token:@"\u00f7" function:@"divide" associativity:DDOperatorAssociativityLeft]];
precedence++;
[operators addObject:[self infoForOperator:DDOperatorModulo arity:DDOperatorArityBinary precedence:precedence token:@"%" function:@"mod" associativity:DDOperatorAssociativityLeft]];

0 comments on commit 187c902

Please sign in to comment.