Skip to content

Commit

Permalink
Added support for the ÷ and × signs as operators
Browse files Browse the repository at this point in the history
  • Loading branch information
davedelong committed Oct 18, 2011
1 parent 5e8ddf0 commit 187c902
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Command line demo/main.m
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion DDMathParser/DDMathStringTokenizer.m
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions DDMathParser/_DDOperatorInfo.m
Expand Up @@ -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]];
Expand Down

0 comments on commit 187c902

Please sign in to comment.