From ed213deadb3271a512746d1d405a03ae41979db0 Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Thu, 23 Dec 2010 11:03:56 +0100 Subject: [PATCH] Getting rid of -CPStack position, using isEmpty instead --- CPStack.h | 1 - CPStack.m | 7 +------ CPTokenizer.m | 6 +++--- Tests/TestStack.m | 1 - 4 files changed, 4 insertions(+), 11 deletions(-) diff --git a/CPStack.h b/CPStack.h index 43374e1..d12d622 100644 --- a/CPStack.h +++ b/CPStack.h @@ -27,7 +27,6 @@ - (CPToken *) tokenAtIndex:(NSInteger)index; - (NSInteger) count; -- (NSInteger) position; - (NSArray *) popUpToToken: (CPToken *) search; - (NSArray *) popUpToOperator: (CPOperator) op; diff --git a/CPStack.m b/CPStack.m index 2140712..8f8ced4 100644 --- a/CPStack.m +++ b/CPStack.m @@ -70,18 +70,13 @@ - (CPToken *) tokenAtIndex:(NSInteger)index } #pragma mark - -#pragma mark count / position +#pragma mark count - (NSInteger) count { return [stack count]; } -- (NSInteger) position -{ - return [stack count]; -} - #pragma mark - #pragma mark description diff --git a/CPTokenizer.m b/CPTokenizer.m index 64c15db..7b2046d 100644 --- a/CPTokenizer.m +++ b/CPTokenizer.m @@ -70,7 +70,7 @@ - (NSArray *) processCommaOperatorStack: (CPStack *) stack; { NSArray *ops = [stack popUpToOperator: CPOperatorLBrace]; - if (nil == ops || [stack position] == 0 || [[stack lastToken] type] != CPTokenFunction) { + if (nil == ops || [stack isEmpty] || [[stack lastToken] type] != CPTokenFunction) { NSException *exception = [NSException exceptionWithName:CPSyntaxErrorException reason:@"function missing" userInfo:nil]; @@ -88,7 +88,7 @@ - (NSArray *) processRBraceOperatorStack: (CPStack *) stack; [NSException raise: CPSyntaxErrorException format: @"Missing '('"]; } - if ([stack position] != 0 && [[stack lastToken] type] == CPTokenFunction) { + if (![stack isEmpty] && [[stack lastToken] type] == CPTokenFunction) { ops = [ops arrayByAddingObject: [stack pop]]; } @@ -100,7 +100,7 @@ - (NSArray *) processDefaultOperator: (CPToken *) token stack: (CPStack *) stack NSMutableArray *output = [NSMutableArray array]; CPOperator operator = [token operatorValue]; - while ([stack position] > 0) { + while (![stack isEmpty]) { const bool leftAssoc = [Operators associativity: operator] == CPOperatorAssocLeft; const unsigned priority = [Operators priority: operator]; const unsigned lastStackPriority = [Operators priority: [[stack lastToken] operatorValue]]; diff --git a/Tests/TestStack.m b/Tests/TestStack.m index 5aa8a94..4434011 100644 --- a/Tests/TestStack.m +++ b/Tests/TestStack.m @@ -23,7 +23,6 @@ - (void) testEmpty; STAssertTrue( [stack isEmpty], @"Should be empty" ); STAssertTrue( [stack count] == 0, @"Should be empty" ); - STAssertTrue( [stack position] == 0, @"Should be empty" ); STAssertNil( [stack pop], @"Should be empty" ); STAssertNil( [stack lastToken], @"Should be empty" );