Started to Implement the Parser
This commit is contained in:
60
MathPad/MPParsedElement.m
Normal file
60
MathPad/MPParsedElement.m
Normal file
@@ -0,0 +1,60 @@
|
||||
//
|
||||
// MPParsedElement.m
|
||||
// MathPad
|
||||
//
|
||||
// Created by Kim Wittenburg on 05.09.14.
|
||||
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPParsedElement.h"
|
||||
|
||||
@implementation MPParsedElement
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_summands = [[NSMutableArray alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (double)standaloneValue
|
||||
{
|
||||
if (self.isFactor) {
|
||||
return self.factor;
|
||||
}
|
||||
return self.prefixMultiplicator + [[self.summands valueForKeyPath:@"@sum.self"] doubleValue];
|
||||
}
|
||||
|
||||
- (BOOL)isValidElementAtBeginning
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)isValidElementInBetween
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)isValidElementAtEnd
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
#pragma mark NSCopying
|
||||
- (id)copyWithZone:(NSZone *)zone
|
||||
{
|
||||
MPParsedElement *copy = [[MPParsedElement allocWithZone:zone] init];
|
||||
copy.isFactor = self.isFactor;
|
||||
copy.factor = self.factor;
|
||||
copy.summands = self.summands.mutableCopy;
|
||||
copy.prefixMultiplicator = self.prefixMultiplicator;
|
||||
copy.hasPrefixMultiplicator = self.hasPrefixMultiplicator;
|
||||
copy.prefixOperatorExplicit = self.prefixOperatorExplicit;
|
||||
copy.suffixMultiplicator = self.suffixMultiplicator;
|
||||
copy.hasSuffixMultiplicator = self.hasSuffixMultiplicator;
|
||||
return copy;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user