Archived
1

Started to Implement the Parser

This commit is contained in:
Kim Wittenburg
2014-09-06 01:54:15 +02:00
parent 6aafbf9d2e
commit 8df8317413
10 changed files with 570 additions and 16 deletions

60
MathPad/MPParsedElement.m Normal file
View 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