Archived
1

Added Factorial, added parts of exponents

This commit is contained in:
Kim Wittenburg
2014-09-30 22:18:51 +02:00
parent 7d48d85dfb
commit a382b1f10b
8 changed files with 55 additions and 27 deletions

View File

@@ -15,6 +15,7 @@
#import "MPTokenStream.h"
#import "MPEvaluationContext.h"
#import "MPPowerFunction.h"
@@ -171,7 +172,7 @@
switch (token.tokenType) {
case MPNumberToken:
{
return [[MPTerm alloc] initWithNumber:token.number];
return [self decoratedTerm:[[MPTerm alloc] initWithNumber:token.number]];
}
case MPVariableToken:
@@ -180,12 +181,12 @@
self.error = MPParseError(token.range, @"Undefined Variable");
return nil;
}
return [[MPTerm alloc] initWithVariable:token.variable];
return [self decoratedTerm:[[MPTerm alloc] initWithVariable:token.variable]];
}
case MPGenericFunctionToken:
{
return [((MPFunction *)token) parseWithError:_error];
return [self decoratedTerm:[((MPFunction *)token) parseWithError:_error]];
}
case MPSinToken:
@@ -241,4 +242,22 @@
}
}
- (MPTerm *)decoratedTerm:(MPTerm *)term
{
MPTerm *decoratedTerm = term;
MPToken *facultyToken = [tokenStream nextTokenOfType:MPFactorialToken];
if (facultyToken) {
decoratedTerm = [[MPTerm alloc] initWithFactorialOfTerm:term];
}
MPToken *powerToken = [tokenStream nextTokenOfType:MPGenericFunctionToken];
if ([powerToken isKindOfClass:[MPPowerFunction class]]) {
MPPowerFunction *powerFunction = (MPPowerFunction *)powerToken;
powerFunction.baseTerm = decoratedTerm;
return [powerFunction parseWithError:_error];
} else {
tokenStream.currentLocation--;
}
return decoratedTerm;
}
@end