Archived
1

Added the MPExpressionTree Classes

This commit is contained in:
Kim Wittenburg
2014-10-13 23:53:04 +02:00
parent 82259f87e2
commit 5592128926
60 changed files with 1981 additions and 725 deletions

View File

@@ -42,16 +42,19 @@
NSString *decimalSeparator = [NSRegularExpression escapedPatternForString:[[NSLocale currentLocale] objectForKey:NSLocaleDecimalSeparator]];
NSString *regexStringFormat = @"\\A(?:"
@"(\\*)|"
@"([\\*∙⋅])|"
@"([+-](?:\\s*[+-])*)|"
@"((?:\\d+(?:%@\\d+)?)|(?:%@\\d+))|"
@"(sin)|"
@"(cos)|"
@"(tan)|"
@"(asin)|"
@"(acos)|"
@"(atan)|"
@"([A-Za-z])|"
@"(!)|"
@"(=)|"
@"(\\s)"
@"(\\s+)"
@")";
NSString *regexString = [NSString stringWithFormat:regexStringFormat, decimalSeparator, decimalSeparator];
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexString
@@ -70,10 +73,13 @@
NSRange sinRange = [match rangeAtIndex:4];
NSRange cosRange = [match rangeAtIndex:5];
NSRange tanRange = [match rangeAtIndex:6];
NSRange variableRange = [match rangeAtIndex:7];
NSRange factorialRange = [match rangeAtIndex:8];
NSRange equalsRange = [match rangeAtIndex:9];
NSRange whitespaceRange = [match rangeAtIndex:10];
NSRange asinRange = [match rangeAtIndex:7];
NSRange acosRange = [match rangeAtIndex:8];
NSRange atanRange = [match rangeAtIndex:9];
NSRange variableRange = [match rangeAtIndex:10];
NSRange factorialRange = [match rangeAtIndex:11];
NSRange equalsRange = [match rangeAtIndex:12];
NSRange whitespaceRange = [match rangeAtIndex:13];
if (MPRangeExists(multiplicationSymbolRange)) {
range = multiplicationSymbolRange;
@@ -93,6 +99,15 @@
} else if (MPRangeExists(tanRange)) {
range = tanRange;
tokenType = MPTanToken;
} else if (MPRangeExists(asinRange)) {
range = asinRange;
tokenType = MPASinToken;
} else if (MPRangeExists(acosRange)) {
range = acosRange;
tokenType = MPACosToken;
} else if (MPRangeExists(atanRange)) {
range = atanRange;
tokenType = MPATanToken;
} else if (MPRangeExists(variableRange)) {
range = variableRange;
tokenType = MPVariableToken;