Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 53 lines (42 sloc) 1.396 kb
65a2f05 @davedelong implementing group and function terms, primarily
authored
1 //
2 // _DDOperatorTerm.m
3 // DDMathParser
4 //
5 // Created by Dave DeLong on 7/12/11.
6 // Copyright 2011 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "_DDOperatorTerm.h"
10 #import "DDMathStringToken.h"
bf22144 @davedelong Fix edge case when an operator never correctly resolves
authored
11 #import "DDMathParserMacros.h"
65a2f05 @davedelong implementing group and function terms, primarily
authored
12
13 @implementation _DDOperatorTerm
14
74d8f6d @davedelong starting to add term resolution
authored
15 - (DDParserTermType)type { return DDParserTermTypeOperator; }
16
4ce5ae4 @davedelong A bit of refactoring of _DDOperatorInfo
authored
17 - (NSString *)operatorType {
65a2f05 @davedelong implementing group and function terms, primarily
authored
18 return [[self token] operatorType];
19 }
20
34c91e5 @davedelong Move information about operators into a separate class
authored
21 - (NSInteger)operatorPrecedence {
74d8f6d @davedelong starting to add term resolution
authored
22 return [[self token] operatorPrecedence];
65a2f05 @davedelong implementing group and function terms, primarily
authored
23 }
24
33bbe84 @davedelong Parity with the old term system
authored
25 - (DDOperatorArity)operatorArity {
26 return [[self token] operatorArity];
27 }
28
29 - (NSString *)operatorFunction {
34c91e5 @davedelong Move information about operators into a separate class
authored
30 return [[self token] operatorFunction];
33bbe84 @davedelong Parity with the old term system
authored
31 }
32
bf22144 @davedelong Fix edge case when an operator never correctly resolves
authored
33 - (BOOL)resolveWithParser:(DDParser *)parser error:(NSError *__autoreleasing *)error {
34 #pragma unused(parser)
35 ERR_ASSERT(error);
4636edb @davedelong slightly more descriptive error
authored
36 if ([self operatorArity] == DDOperatorArityUnary) {
37 if ([[self token] operatorAssociativity] == DDOperatorAssociativityLeft) {
38 *error = ERR(DDErrorCodeUnaryOperatorMissingLeftOperand, @"no left operand to unary %@", [self token]);
39 } else {
40 *error = ERR(DDErrorCodeUnaryOperatorMissingRightOperand, @"no right operand to unary %@", [self token]);
41 }
42 } else {
43 *error = ERR(DDErrorCodeOperatorMissingOperands, @"missing operands for operator: %@", [self token]);
44 }
bf22144 @davedelong Fix edge case when an operator never correctly resolves
authored
45 return NO;
46 }
47
33bbe84 @davedelong Parity with the old term system
authored
48 - (NSString *)description {
49 return [[self token] token];
50 }
51
65a2f05 @davedelong implementing group and function terms, primarily
authored
52 @end
Something went wrong with that request. Please try again.