Skip to content

Commit

Permalink
Getting rid of -CPStack position, using isEmpty instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Weidauer committed Dec 23, 2010
1 parent 049e17e commit ed213de
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 11 deletions.
1 change: 0 additions & 1 deletion CPStack.h
Expand Up @@ -27,7 +27,6 @@
- (CPToken *) tokenAtIndex:(NSInteger)index;

- (NSInteger) count;
- (NSInteger) position;

- (NSArray *) popUpToToken: (CPToken *) search;
- (NSArray *) popUpToOperator: (CPOperator) op;
Expand Down
7 changes: 1 addition & 6 deletions CPStack.m
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions CPTokenizer.m
Expand Up @@ -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];
Expand All @@ -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]];
}

Expand All @@ -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]];
Expand Down
1 change: 0 additions & 1 deletion Tests/TestStack.m
Expand Up @@ -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" );
Expand Down

0 comments on commit ed213de

Please sign in to comment.