From 4bc2fdead1e517e235faa0a347b51e05800f2abb Mon Sep 17 00:00:00 2001 From: Kim Wittenburg Date: Tue, 25 Nov 2014 23:59:28 +0100 Subject: [PATCH] Added/Corrected Documentation --- MathKit/MathKit.h | 1 - MathPad.xcodeproj/project.pbxproj | 12 +- .../xcschemes/MathKit.xcscheme | 11 +- .../xcschemes/MathPad.xcscheme | 2 +- MathPad/Base.lproj/MPDocument.xib | 9 - MathPad/Base.lproj/MainMenu.xib | 281 ------------------ MathPad/MPElementaryFunctionTerm.h | 5 +- MathPad/MPElementaryFunctionTerm.m | 1 - MathPad/MPEvaluationContext.h | 3 + MathPad/MPExpression.h | 122 +++++--- MathPad/MPExpressionLayout.h | 2 + MathPad/MPExpressionParser.h | 6 +- MathPad/MPExpressionParser.m | 2 +- MathPad/MPExpressionStorage.h | 3 + MathPad/MPExpressionTokenizer.h | 4 +- MathPad/MPExpressionTokenizer.m | 3 +- MathPad/MPExpressionView.h | 5 +- MathPad/MPFactorialTerm.h | 5 + MathPad/MPFractionFunction.h | 24 ++ MathPad/MPFractionFunctionLayout.h | 3 + MathPad/MPFractionTerm.h | 5 + MathPad/MPFractionTerm.m | 2 + MathPad/MPFunction+MPToken.m | 2 + MathPad/MPFunction.h | 42 ++- MathPad/MPFunction.m | 8 +- MathPad/MPFunctionLayout.h | 3 + MathPad/MPFunctionTerm.h | 4 +- MathPad/MPFunctionTerm.m | 4 +- MathPad/MPFunctionsViewController.h | 3 + MathPad/MPLayout.h | 3 + MathPad/MPMathRules.h | 4 + MathPad/MPNegatedTerm.h | 5 + MathPad/MPNumber.h | 3 + MathPad/MPNumber.m | 1 - MathPad/MPParenthesisFunction.h | 18 ++ MathPad/MPParenthesisFunction.m | 2 + MathPad/MPParenthesisFunctionLayout.h | 3 + MathPad/MPParenthesisTerm.h | 5 + MathPad/MPParenthesisTerm.m | 2 + MathPad/MPParsedExpression.h | 6 +- MathPad/MPParsedExpression.m | 1 - MathPad/MPPowerFunction.h | 16 +- MathPad/MPPowerFunctionLayout.h | 3 + MathPad/MPPowerTerm.h | 5 + MathPad/MPProductTerm.h | 5 + MathPad/MPProductTerm.m | 1 - MathPad/MPRangePath.h | 12 +- MathPad/MPSumFunction.h | 18 +- MathPad/MPSumFunction.m | 3 - MathPad/MPSumFunctionLayout.h | 3 + MathPad/MPSumFunctionTerm.h | 5 + MathPad/MPSumFunctionTerm.m | 2 + MathPad/MPSumTerm.h | 5 + MathPad/MPSumTerm.m | 1 - MathPad/MPTerm.h | 4 +- MathPad/MPToken.h | 13 +- MathPad/MPToken.m | 34 +-- MathPad/MPTokenStream.h | 137 --------- MathPad/MPTokenStream.m | 140 --------- MathPad/MPVariable.h | 3 + MathPad/MPVariable.m | 1 - MathPad/MPWhiteView.h | 3 + MathPad/MPWhiteView.m | 2 + MathPad/MathPad-Info.plist | 6 +- MathPad/NSIndexPath+MPAdditions.h | 10 +- MathPad/en.lproj/Credits.rtf | 28 +- 66 files changed, 380 insertions(+), 710 deletions(-) delete mode 100644 MathPad/MPTokenStream.h delete mode 100644 MathPad/MPTokenStream.m diff --git a/MathKit/MathKit.h b/MathKit/MathKit.h index 29a4216..8af35b7 100644 --- a/MathKit/MathKit.h +++ b/MathKit/MathKit.h @@ -18,7 +18,6 @@ #import "MPToken.h" #import "MPFunction+MPToken.h" -#import "MPTokenStream.h" #import "MPEvaluationContext.h" diff --git a/MathPad.xcodeproj/project.pbxproj b/MathPad.xcodeproj/project.pbxproj index 5042cad..e7cc05b 100644 --- a/MathPad.xcodeproj/project.pbxproj +++ b/MathPad.xcodeproj/project.pbxproj @@ -63,9 +63,7 @@ 3B85834C19BB661100D76A8D /* MathKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B85833219BB5F2D00D76A8D /* MathKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3B9265C71A2147DF00AD2809 /* MPNegatedTerm.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B9265C51A2147DF00AD2809 /* MPNegatedTerm.h */; }; 3B9265C81A2147DF00AD2809 /* MPNegatedTerm.m in Sources */ = {isa = PBXBuildFile; fileRef = 3B9265C61A2147DF00AD2809 /* MPNegatedTerm.m */; }; - 3BB18AA519CDB3A900986DA0 /* MPTokenStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 3BB18AA319CDB3A900986DA0 /* MPTokenStream.h */; }; - 3BB18AA619CDB3A900986DA0 /* MPTokenStream.m in Sources */ = {isa = PBXBuildFile; fileRef = 3BB18AA419CDB3A900986DA0 /* MPTokenStream.m */; }; - 3BBEA92C19BB680B00133766 /* MathKit.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3B85830D19BB5E5500D76A8D /* MathKit.framework */; }; + 3BBEA92C19BB680B00133766 /* MathKit.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3B85830D19BB5E5500D76A8D /* MathKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; 3BBEA93519BB79A700133766 /* MPExpression.m in Sources */ = {isa = PBXBuildFile; fileRef = 3BFAC38E1997B61300B3EF67 /* MPExpression.m */; }; 3BBEA93619BB79A700133766 /* MPFunction.m in Sources */ = {isa = PBXBuildFile; fileRef = 3B87E35F19009D5F00259938 /* MPFunction.m */; }; 3BBEA93A19BB79A700133766 /* MPSumFunction.m in Sources */ = {isa = PBXBuildFile; fileRef = 3BB09EC81906FD830080A5ED /* MPSumFunction.m */; }; @@ -223,8 +221,6 @@ 3BB09EDD190728220080A5ED /* NSIndexPath+MPAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSIndexPath+MPAdditions.m"; sourceTree = ""; }; 3BB09EDF190736160080A5ED /* MPSumFunctionLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPSumFunctionLayout.h; sourceTree = ""; }; 3BB09EE0190736160080A5ED /* MPSumFunctionLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPSumFunctionLayout.m; sourceTree = ""; }; - 3BB18AA319CDB3A900986DA0 /* MPTokenStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPTokenStream.h; sourceTree = ""; }; - 3BB18AA419CDB3A900986DA0 /* MPTokenStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPTokenStream.m; sourceTree = ""; }; 3BBBA3941905704200824E74 /* MPRangeTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MPRangeTests.m; path = ../MathPadTests/MPRangeTests.m; sourceTree = ""; }; 3BC4661319B245C60033F13A /* Fonts */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Fonts; sourceTree = ""; }; 3BC4661519B365070033F13A /* MPArrayCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPArrayCache.h; sourceTree = ""; }; @@ -483,8 +479,6 @@ 3B7B3A2B19CC467E005849E5 /* MPToken.m */, 3B7B3A5219CC50B1005849E5 /* MPFunction+MPToken.h */, 3B7B3A5319CC50B1005849E5 /* MPFunction+MPToken.m */, - 3BB18AA319CDB3A900986DA0 /* MPTokenStream.h */, - 3BB18AA419CDB3A900986DA0 /* MPTokenStream.m */, 3BB09EBC1905EF210080A5ED /* Functions */, 3BC46B4F19B506F20033F13A /* Evaluation */, ); @@ -671,7 +665,6 @@ 3B85834619BB655C00D76A8D /* MPExpressionView.h in Headers */, 3B85834719BB655F00D76A8D /* MPExpressionStorage.h in Headers */, 3B9265C71A2147DF00AD2809 /* MPNegatedTerm.h in Headers */, - 3BB18AA519CDB3A900986DA0 /* MPTokenStream.h in Headers */, 3BF59AFE19D80ECC00E54292 /* MPFunctionsViewController.h in Headers */, 3B7B3A2C19CC467E005849E5 /* MPToken.h in Headers */, 3B7B3A1819CC44E4005849E5 /* MPExpressionTokenizer.h in Headers */, @@ -774,7 +767,7 @@ isa = PBXProject; attributes = { CLASSPREFIX = MP; - LastUpgradeCheck = 0510; + LastUpgradeCheck = 0610; ORGANIZATIONNAME = "Kim Wittenburg"; TargetAttributes = { 3B85831C19BB5E5500D76A8D = { @@ -890,7 +883,6 @@ 3BEFF74E1A16A4DA00301C0C /* MPSumTerm.m in Sources */, 3BF59AFF19D80ECC00E54292 /* MPFunctionsViewController.m in Sources */, 3BCA0C861A1405C000C9E3E0 /* MPFunctionTerm.m in Sources */, - 3BB18AA619CDB3A900986DA0 /* MPTokenStream.m in Sources */, 3BCA0C811A12619500C9E3E0 /* MPTerm.m in Sources */, 3B69B66D19DB41B90028E608 /* MPPowerFunctionLayout.m in Sources */, 3BBEA93619BB79A700133766 /* MPFunction.m in Sources */, diff --git a/MathPad.xcodeproj/xcuserdata/kim.xcuserdatad/xcschemes/MathKit.xcscheme b/MathPad.xcodeproj/xcuserdata/kim.xcuserdatad/xcschemes/MathKit.xcscheme index f1cab0e..06d3917 100644 --- a/MathPad.xcodeproj/xcuserdata/kim.xcuserdatad/xcschemes/MathKit.xcscheme +++ b/MathPad.xcodeproj/xcuserdata/kim.xcuserdatad/xcschemes/MathKit.xcscheme @@ -1,6 +1,6 @@ + + + + diff --git a/MathPad.xcodeproj/xcuserdata/kim.xcuserdatad/xcschemes/MathPad.xcscheme b/MathPad.xcodeproj/xcuserdata/kim.xcuserdatad/xcschemes/MathPad.xcscheme index 0b9f9dc..ed6cab6 100644 --- a/MathPad.xcodeproj/xcuserdata/kim.xcuserdatad/xcschemes/MathPad.xcscheme +++ b/MathPad.xcodeproj/xcuserdata/kim.xcuserdatad/xcschemes/MathPad.xcscheme @@ -1,6 +1,6 @@ - - - - - - - - - diff --git a/MathPad/Base.lproj/MainMenu.xib b/MathPad/Base.lproj/MainMenu.xib index 90d7a26..dabd55e 100644 --- a/MathPad/Base.lproj/MainMenu.xib +++ b/MathPad/Base.lproj/MainMenu.xib @@ -338,287 +338,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/MathPad/MPElementaryFunctionTerm.h b/MathPad/MPElementaryFunctionTerm.h index 31c986a..8921f78 100644 --- a/MathPad/MPElementaryFunctionTerm.h +++ b/MathPad/MPElementaryFunctionTerm.h @@ -8,7 +8,10 @@ #import "MPTerm.h" -@class MPElementaryFunctionTerm, MPValueGroup; + + +@class MPElementaryFunctionTerm; + @interface MPElementaryFunctionTerm : MPTerm diff --git a/MathPad/MPElementaryFunctionTerm.m b/MathPad/MPElementaryFunctionTerm.m index 3f337ed..17f063c 100644 --- a/MathPad/MPElementaryFunctionTerm.m +++ b/MathPad/MPElementaryFunctionTerm.m @@ -11,7 +11,6 @@ #import "MPParsedExpression.h" #import "MPPowerFunction.h" #import "MPProductTerm.h" -#import "MPTokenStream.h" #import "MPToken.h" #import "MPExpression.h" diff --git a/MathPad/MPEvaluationContext.h b/MathPad/MPEvaluationContext.h index d75c672..843a148 100644 --- a/MathPad/MPEvaluationContext.h +++ b/MathPad/MPEvaluationContext.h @@ -6,8 +6,11 @@ // Copyright (c) 2014 Kim Wittenburg. All rights reserved. // + + @class MPEvaluationContext; + @interface MPEvaluationContext : NSObject + (MPEvaluationContext *)sharedContext; diff --git a/MathPad/MPExpression.h b/MathPad/MPExpression.h index a5cbac4..ad7479f 100644 --- a/MathPad/MPExpression.h +++ b/MathPad/MPExpression.h @@ -33,12 +33,22 @@ FOUNDATION_EXPORT NSString *const MPIllegalElementExceptionElementKey; /*! @typedef MPReferenceFrame - @brief A reference frame describes what an @em item is. + @brief A reference frame describes what an @em item in an expression is. - @discussion An item may be an element, a symbol or a token. A symbol is the - smallest possible size for an item. An element as well as a token - consist of one or more symbols. Similarly an element consists of - one or more tokens. + @discussion Reference frames have to be passed in multiple methods of the @c + MPExpression class. You can convert between reference frames + using the following methods: +
+ @textblock
+- convertIndexFromReferenceFrame:toReferenceFrame:
+  - convertIndexFromReferenceFrame:toReferenceFrame:offset:
+ @/textblock
+                
+ + There are three different types of items (reference frames): + symbols, tokens and elements. A symbol is the smalles possible + unit in an expression. Thus a token consists of one or more + symbols. Similarly an element consists of one or more tokens. @constant MPElementReferenceFrame Specifies that items should be interpreted as elements. An @@ -46,8 +56,8 @@ FOUNDATION_EXPORT NSString *const MPIllegalElementExceptionElementKey; @constant MPSymbolReferenceFrame Specifies that items should be interpreted as symbols. A symbol - can be a single character (as they are for example typed in by - the user) or a @c MPFunction object. + can be a single character (represented by the @c NSString class) + or a @c MPFunction object. @constant MPTokenReferenceFrame Specifies that items should be interpreted as tokens. A token is @@ -55,7 +65,7 @@ FOUNDATION_EXPORT NSString *const MPIllegalElementExceptionElementKey; character (e.g. '+'), an arbitrary number of characters (e.g. a number) or a @c MPFunction object. - All tokens must conform to the @c MPToken protocol. + All tokens conform to the @c MPToken protocol. */ typedef NS_ENUM(NSUInteger, MPReferenceFrame) { MPElementReferenceFrame, @@ -68,6 +78,7 @@ typedef NS_ENUM(NSUInteger, MPReferenceFrame) { @class MPExpression, MPFunction, MPRangePath, MPParsedExpression; @protocol MPExpressionElement, MPToken; + /*! @class MPExpression @brief An @c MPExpression object is the base object for any mathematical @@ -76,15 +87,11 @@ typedef NS_ENUM(NSUInteger, MPReferenceFrame) { @discussion Every expression consists of string elements (represented by the @c NSString class) and function elements (represented by the @c MPFunction class). Functions likewise can have expressions as - elements (also called @em children in this context). Both + elements (also called children in this context). Both expressions and functions are mutable. Through this organization expression are organized in a tree-like structure called the 'expression tree'. - @note There is also the @c MPExpressionTree class. That class provides - an alternative representation of an expression. The 'expression - tree' does not refer to that class. - An expression can evaluate itself giving you either a result or possibly an error if the expression was not constructed correctly or could not be evaluated. @@ -128,7 +135,8 @@ typedef NS_ENUM(NSUInteger, MPReferenceFrame) { /*! @method initWithElements: - @brief Initializes a newly created expression with the given elements. + @brief Initializes a newly created expression with the specified + elements. @discussion All elements must conform to the @c MPExpressionElement protocol. If one or more objects do not conform to that protocol an @c @@ -206,8 +214,8 @@ typedef NS_ENUM(NSUInteger, MPReferenceFrame) { @param referenceFrame The reference frame that should be used to count the items. - @return The current number of items in the receiver counted in the given - reference frame. + @return The current number of items in the receiver counted in the + specified reference frame. */ - (NSUInteger)countItemsInReferenceFrame:(MPReferenceFrame)referenceFrame; @@ -472,8 +480,8 @@ typedef NS_ENUM(NSUInteger, MPReferenceFrame) { /*! @method replaceItemsInRange:referenceFrame:withElements: - @brief Replaces the elements in the given range with the contents of the - @c elements array. + @brief Replaces the elements in the specified range with the contents of + the @c elements array. @discussion This is the most primitive mutation method of @c MPExpression. Every other mutating method utlimately must call this method. @@ -515,8 +523,8 @@ typedef NS_ENUM(NSUInteger, MPReferenceFrame) { @param referenceFrame The reference frame @c from is specified in. - @return An expression containing the items from the given index to the - end. + @return An expression containing the items from the specified index to + the end of the receiver. */ - (MPExpression *)subexpressionFromIndex:(NSUInteger)from referenceFrame:(MPReferenceFrame)referenceFrame; @@ -537,8 +545,8 @@ typedef NS_ENUM(NSUInteger, MPReferenceFrame) { @param referenceFrame The reference frame @c to is specified in. - @return An expression containing the items from the first item to the - given index. + @return An expression containing the items from the first item to the one + at the specified index. */ - (MPExpression *)subexpressionToIndex:(NSUInteger)to referenceFrame:(MPReferenceFrame)referenceFrame; @@ -572,7 +580,7 @@ typedef NS_ENUM(NSUInteger, MPReferenceFrame) { /*! - @method evaluateWitError: + @method evaluateWitErrors: @brief Evaluates the receiver. @discussion This is a convenience method for evaluating an expression. If you @@ -580,34 +588,66 @@ typedef NS_ENUM(NSUInteger, MPReferenceFrame) { instead. @param errors - If the receiver (or any of its elements) contains a syntax error - or can not be evaluated this parameter is set to an appropriate - value. Pass @c NULL if you are not interested in any errors that - might occur. + If the receiver (or any of its elements) contain syntax errors or + can not be evaluated this parameter is set to an appropriate + value. All items in the array are @c NSError instances. This + parameter is never set to an empty array. + Pass @c NULL if you are not interested in any errors that might + occur. @return The result of the evaluation or @c nil of the receiver could not be evaluated. In that case the @c error parameter is set to an - appropriate value. If @c NaN is returned it means there was a - math error. In most cases the error parameter contains an - appropriate description of the problem. + appropriate value. */ - (NSDecimalNumber *)evaluateWithErrors:(NSArray *__autoreleasing *)errors; /*! - @method parse + @method parse: @brief Parses the receiver. - @discussion This method returns a valid object even if the expression - contains syntax errors. Send the returned object a @c -validate: - message to check for syntax errors before you evaluate it. For - more information on evaluation see the documentation of @c - MPExpressionTree. + @discussion This is a convenience method that calls @c + -parseExpectingVariable:errors: with @c NO as the first argument. + + @param errors + If the receiver (or any of its elements) contain syntax errors + this parameter is set to an appropriate value. All items in the + array are @c NSError instances. This parameter is never set to an + empty array. + Pass @c NULL if you are not interested in any errors that might + occur. - @return A @c MPExpressionTree object that can evaluate the receiver. + @return A @c MPParsedExpression object that represents the receiver and + can be evaluated or @c nil if an error occurs. In that case the + @c errors parameter is set to an array containing at least one + @c NSError instance. */ - (MPParsedExpression *)parse:(NSArray *__autoreleasing *)errors; + +/*! + @method parseExpectingVariable:errors: + @brief Parses the receiver. + + @param flag + If @c YES the receiver must (exept for whitespaces) begin with a + single letter followed by an equals sign. If it doesn't the + expression is considered invalid. Specify @c NO If the expression + should be evaluatable by itself. + + @param errors + If the receiver (or any of its elements) contain syntax errors + this parameter is set to an appropriate value. All items in the + array are @c NSError instances. This parameter is never set to an + empty array. + Pass @c NULL if you are not interested in any errors that might + occur. + + @return A @c MPParsedExpression object that represents the receiver and + can be evaluated or @c nil if an error occurs. In that case the + @c errors parameter is set to an array containing at least one + @c NSError instance. + */ - (MPParsedExpression *)parseExpectingVariable:(BOOL)flag errors:(NSArray *__autoreleasing *)errors; @@ -645,6 +685,14 @@ typedef NS_ENUM(NSUInteger, MPReferenceFrame) { +/*! + @category MPExpression (MPExpressionConvenience) + @brief This category defines convenience methods for the @c MPExpression + class. + + @discussion All convenience methods are completely defined in terms of other + methods of the @c MPExpression class. + */ @interface MPExpression (MPExpressionConvenience) #pragma mark Querying Expressions diff --git a/MathPad/MPExpressionLayout.h b/MathPad/MPExpressionLayout.h index 8e6a267..cc8d52c 100644 --- a/MathPad/MPExpressionLayout.h +++ b/MathPad/MPExpressionLayout.h @@ -8,6 +8,8 @@ #import "MPLayout.h" + + @class MPExpressionLayout, MPExpression, MPFunctionLayout; @interface MPExpressionLayout : MPLayout diff --git a/MathPad/MPExpressionParser.h b/MathPad/MPExpressionParser.h index dc39db0..6fa89f6 100644 --- a/MathPad/MPExpressionParser.h +++ b/MathPad/MPExpressionParser.h @@ -6,8 +6,10 @@ // Copyright (c) 2014 Kim Wittenburg. All rights reserved. // -#import "MPExpression.h" -#import "MPParsedExpression.h" + + +@class MPExpressionParser, MPExpression, MPParsedExpression; + @interface MPExpressionParser : NSObject diff --git a/MathPad/MPExpressionParser.m b/MathPad/MPExpressionParser.m index f01f890..7e5e84c 100644 --- a/MathPad/MPExpressionParser.m +++ b/MathPad/MPExpressionParser.m @@ -9,7 +9,6 @@ #import "MPExpressionParser.h" #import "MPExpression.h" -#import "MPTokenStream.h" #import "MPTerm.h" #import "MPToken.h" #import "MPSumTerm.h" @@ -18,6 +17,7 @@ #import "MPElementaryFunctionTerm.h" #import "MPFunctionTerm.h" #import "MPPowerTerm.h" +#import "MPParsedExpression.h" #import "MPNegatedTerm.h" #import "MPNumber.h" diff --git a/MathPad/MPExpressionStorage.h b/MathPad/MPExpressionStorage.h index 7ad5fd6..df100b0 100644 --- a/MathPad/MPExpressionStorage.h +++ b/MathPad/MPExpressionStorage.h @@ -8,8 +8,11 @@ #import "MPExpression.h" + + @class MPExpressionStorage, MPExpressionView, MPExpressionLayout; + @interface MPExpressionStorage : MPExpression - (instancetype)initWithElements:(NSArray *)elements; diff --git a/MathPad/MPExpressionTokenizer.h b/MathPad/MPExpressionTokenizer.h index 53d7d80..035d504 100644 --- a/MathPad/MPExpressionTokenizer.h +++ b/MathPad/MPExpressionTokenizer.h @@ -1,5 +1,5 @@ // -// MPExpressionLexer.h +// MPExpressionTokenizer.h // MathPad // // Created by Kim Wittenburg on 19.09.14. @@ -32,6 +32,6 @@ @return An array of objects that conform to the @c MPToken protocol. */ -+ (NSArray *)tokenizeExpression:(MPExpression *)expression; // Returns MPToken's ++ (NSArray *)tokenizeExpression:(MPExpression *)expression; @end diff --git a/MathPad/MPExpressionTokenizer.m b/MathPad/MPExpressionTokenizer.m index a66c411..665b7d2 100644 --- a/MathPad/MPExpressionTokenizer.m +++ b/MathPad/MPExpressionTokenizer.m @@ -1,5 +1,5 @@ // -// MPExpressionLexer.m +// MPExpressionTokenizer.m // MathPad // // Created by Kim Wittenburg on 19.09.14. @@ -40,7 +40,6 @@ } - + (NSArray *)tokenizeElement:(NSString *)element elementSymbolIndex:(NSUInteger)symbolIndex { diff --git a/MathPad/MPExpressionView.h b/MathPad/MPExpressionView.h index 65d41e2..c7b7ab4 100644 --- a/MathPad/MPExpressionView.h +++ b/MathPad/MPExpressionView.h @@ -8,7 +8,10 @@ // TODO: Undo/Redo + Delegate (evaluateExpressionView:evaluate...) -@class MPExpressionView, MPExpressionStorage, MPExpressionLayout, MPRangePath; + + +@class MPExpressionView, MPExpressionStorage, MPRangePath; + @interface MPExpressionView : NSView diff --git a/MathPad/MPFactorialTerm.h b/MathPad/MPFactorialTerm.h index e9cd26c..3e4f304 100644 --- a/MathPad/MPFactorialTerm.h +++ b/MathPad/MPFactorialTerm.h @@ -8,6 +8,11 @@ #import "MPTerm.h" + + +@class MPFactorialTerm; + + @interface MPFactorialTerm : MPTerm - (instancetype)initWithTerm:(MPTerm *)term; /* designated initializer */ diff --git a/MathPad/MPFractionFunction.h b/MathPad/MPFractionFunction.h index 3b9a3ba..5667b6c 100644 --- a/MathPad/MPFractionFunction.h +++ b/MathPad/MPFractionFunction.h @@ -8,11 +8,35 @@ #import "MPFunction.h" + + @class MPFractionFunction, MPExpression; + +/*! + @class MPFractionFunction + @brief This class represents a fraction. + + @discussion When a fraction is evaluated the nominator is divided by the + denominator. + */ @interface MPFractionFunction : MPFunction +/*! + @property nominatorExpression + @brief The receiver's nominator. + + @discussion The nominator must not define a variable. + */ @property (nonatomic, strong) MPExpression *nominatorExpression; + + +/*! + @property denominatorExpression + @brief The receiver's denominator. + + @discussion The denominator must not define a variable. + */ @property (nonatomic, strong) MPExpression *denominatorExpression; @end diff --git a/MathPad/MPFractionFunctionLayout.h b/MathPad/MPFractionFunctionLayout.h index c71597f..ec361b5 100644 --- a/MathPad/MPFractionFunctionLayout.h +++ b/MathPad/MPFractionFunctionLayout.h @@ -8,8 +8,11 @@ #import "MPFunctionLayout.h" + + @class MPFractionFunctionLayout, MPFractionFunction; + @interface MPFractionFunctionLayout : MPFunctionLayout - (MPFractionFunction *)fractionFunction; diff --git a/MathPad/MPFractionTerm.h b/MathPad/MPFractionTerm.h index 0bcbb18..0c35590 100644 --- a/MathPad/MPFractionTerm.h +++ b/MathPad/MPFractionTerm.h @@ -8,6 +8,11 @@ #import "MPFunctionTerm.h" + + +@class MPFractionTerm; + + @interface MPFractionTerm : MPFunctionTerm @end diff --git a/MathPad/MPFractionTerm.m b/MathPad/MPFractionTerm.m index 6b5928d..a76ef42 100644 --- a/MathPad/MPFractionTerm.m +++ b/MathPad/MPFractionTerm.m @@ -8,6 +8,8 @@ #import "MPFractionTerm.h" +#import "MPParsedExpression.h" + @implementation MPFractionTerm - (NSDecimalNumber *)doEvaluation:(NSError *__autoreleasing *)error diff --git a/MathPad/MPFunction+MPToken.m b/MathPad/MPFunction+MPToken.m index 5b83b43..ed51e3b 100644 --- a/MathPad/MPFunction+MPToken.m +++ b/MathPad/MPFunction+MPToken.m @@ -11,6 +11,8 @@ #import "MPExpression.h" #import "MPPowerFunction.h" + + @implementation MPFunction (MPToken) - (MPTokenType)tokenType diff --git a/MathPad/MPFunction.h b/MathPad/MPFunction.h index 0b1c341..6285397 100644 --- a/MathPad/MPFunction.h +++ b/MathPad/MPFunction.h @@ -26,7 +26,7 @@ -@class MPFunction, MPExpression, MPRangePath, MPFunctionTerm; +@class MPFunction, MPExpression, MPRangePath; @protocol MPExpressionElement; @@ -119,7 +119,7 @@ /*! @method childAtIndex: - @brief Returns the child at the given index. + @brief Returns the child at the specified index. @discussion The ordering of children is determined by the order of the children returned from the @c -childrenAccessors method. @@ -243,9 +243,29 @@ #pragma mark Evaluating Functions +/*! + @methodgroup Evaluating Functions + */ -- (BOOL)expectsVariableDefinitionInChildAtIndex:(NSUInteger)index; +/*! + @method expectsVariableDefinitionInChildAtIndex: + @brief Returns whether the child at @c anIndex is supposed to contain a + variable definition. + + @discussion This method is automatically called during expression parsing. + You can override this method to opt into the default behaviour. + If you override this method you do not need to call super. + + The default implementation just returns @c NO for every index. + + @param anIndex + The index of the child to check. + + @return @c YES if the child at @c anIndex is supposed to contain a + variable definition, @c NO otherwise. + */ +- (BOOL)expectsVariableDefinitionInChildAtIndex:(NSUInteger)anIndex; @end @@ -263,7 +283,9 @@ @interface MPFunction (MPSubclassOverride) /* In Addition to the methods listed below MPFunction subclasses should also - * override the NSObject methods -description and -hash. + * override the NSObject method -description. + * Also -expectsVariabledefinitionInChildAtIndex: can be overridden if one of the + * children should contain a variable definition. */ #pragma mark Working With the Expression Tree @@ -291,6 +313,18 @@ @methodgroup Evaluating Functions */ + +/*! + @method functionTermClass + @brief Returns the class that represents the receiver's evaluation + behaviour. + + @discussion The class returned must be a subclass of @c MPFunctionTerm. That + class must not implement a custom initializer. + + @return The @c MPFunctionTerm subclass that can evaluate instances of the + receiver's class. + */ - (Class)functionTermClass; @end diff --git a/MathPad/MPFunction.m b/MathPad/MPFunction.m index 8b8a47a..104aa1e 100644 --- a/MathPad/MPFunction.m +++ b/MathPad/MPFunction.m @@ -18,6 +18,7 @@ @implementation MPFunction + #pragma mark Creation Methods @@ -151,13 +152,6 @@ } -- (NSUInteger)hash -{ -#warning Unimplemented Method - return 0; -} - - #pragma mark - NSCopying diff --git a/MathPad/MPFunctionLayout.h b/MathPad/MPFunctionLayout.h index 8b2927a..e2b0933 100644 --- a/MathPad/MPFunctionLayout.h +++ b/MathPad/MPFunctionLayout.h @@ -8,8 +8,11 @@ #import "MPLayout.h" + + @class MPFunctionLayout, MPFunction, MPExpressionLayout; + @interface MPFunctionLayout : MPLayout + (MPFunctionLayout *)functionLayoutForFunction:(MPFunction *)function diff --git a/MathPad/MPFunctionTerm.h b/MathPad/MPFunctionTerm.h index 1725501..f33fe3e 100644 --- a/MathPad/MPFunctionTerm.h +++ b/MathPad/MPFunctionTerm.h @@ -8,10 +8,10 @@ #import "MPTerm.h" -#import "MPParsedExpression.h" -#import "MPFunction.h" +@class MPFunctionTerm, MPFunction, MPParsedExpression; + @interface MPFunctionTerm : MPTerm diff --git a/MathPad/MPFunctionTerm.m b/MathPad/MPFunctionTerm.m index 5fea915..bfc9249 100644 --- a/MathPad/MPFunctionTerm.m +++ b/MathPad/MPFunctionTerm.m @@ -8,11 +8,11 @@ #import "MPFunctionTerm.h" +#import "MPFunction.h" +#import "MPExpression.h" #import "MPParsedExpression.h" #import "MPToken.h" -#import "MPTokenStream.h" -#import "MPExpression.h" diff --git a/MathPad/MPFunctionsViewController.h b/MathPad/MPFunctionsViewController.h index 490c785..204bb57 100644 --- a/MathPad/MPFunctionsViewController.h +++ b/MathPad/MPFunctionsViewController.h @@ -6,8 +6,11 @@ // Copyright (c) 2014 Kim Wittenburg. All rights reserved. // + + @class MPFunctionsViewController, MPFunctionsCollectionView; + @interface MPFunctionsViewController : NSViewController - (id)init; diff --git a/MathPad/MPLayout.h b/MathPad/MPLayout.h index 259da07..fff345e 100644 --- a/MathPad/MPLayout.h +++ b/MathPad/MPLayout.h @@ -14,8 +14,11 @@ #define kMPEmptyBoxDrawingHeight (CTFontGetDescent((CTFontRef)self.font) + CTFontGetAscent((CTFontRef)self.font)) #define kMPEmptyBoxDrawingYOrigin (-(CTFontGetDescent((CTFontRef)self.font) + CTFontGetLeading((CTFontRef)self.font)/2)) + + @class MPLayout, MPRangePath; + @interface MPLayout : NSObject #pragma mark Creation Methods diff --git a/MathPad/MPMathRules.h b/MathPad/MPMathRules.h index 0f9b0b0..78afc0d 100644 --- a/MathPad/MPMathRules.h +++ b/MathPad/MPMathRules.h @@ -6,12 +6,16 @@ // Copyright (c) 2014 Kim Wittenburg. All rights reserved. // + + FOUNDATION_EXPORT NSString *MPMathRulesMaximumOperatorChainLengthKey; FOUNDATION_EXPORT NSString *MPMathRulesMaximumOperatorChainLengthInMultiplicationKey; FOUNDATION_EXPORT NSString *MPMathRulesIsUsingDegreesKey; + @class MPMathRules; + @interface MPMathRules : NSObject + (MPMathRules *)sharedRules; diff --git a/MathPad/MPNegatedTerm.h b/MathPad/MPNegatedTerm.h index 3b4c180..49ec16c 100644 --- a/MathPad/MPNegatedTerm.h +++ b/MathPad/MPNegatedTerm.h @@ -8,6 +8,11 @@ #import "MPTerm.h" + + +@class MPNegatedTerm; + + @interface MPNegatedTerm : MPTerm - (instancetype)initWithTerm:(MPTerm *)term; /* designated initializer */ diff --git a/MathPad/MPNumber.h b/MathPad/MPNumber.h index 5a9b062..e9d1f1e 100644 --- a/MathPad/MPNumber.h +++ b/MathPad/MPNumber.h @@ -8,8 +8,11 @@ #import "MPTerm.h" + + @class MPNumber; + @interface MPNumber : MPTerm - (instancetype)initWithNumber:(NSDecimalNumber *)number; /* designated initializer */ diff --git a/MathPad/MPNumber.m b/MathPad/MPNumber.m index 2596593..4d69957 100644 --- a/MathPad/MPNumber.m +++ b/MathPad/MPNumber.m @@ -10,7 +10,6 @@ #import "MPParsedExpression.h" -#import "MPTokenStream.h" #import "MPToken.h" @implementation MPNumber diff --git a/MathPad/MPParenthesisFunction.h b/MathPad/MPParenthesisFunction.h index 0c82fe2..128ae70 100644 --- a/MathPad/MPParenthesisFunction.h +++ b/MathPad/MPParenthesisFunction.h @@ -8,10 +8,28 @@ #import "MPFunction.h" + + @class MPParenthesisFunction, MPExpression; + +/*! + @class MPParenthesisFunction + @brief A parenthesis function encapsulates a single expression and thus + prioritizes it in evaluation. + + @discussion Prioritizing the expression means that the complete expression + must be evaluated 'as is'. No part of it can be 'used' elsewhere + before the parenthesis function has been evaluated. + */ @interface MPParenthesisFunction : MPFunction +/*! + @property expression + @brief The expression encapsulated by the parenthesis. + + @discussion The expression must not define a variable. + */ @property (nonatomic, strong) MPExpression *expression; @end diff --git a/MathPad/MPParenthesisFunction.m b/MathPad/MPParenthesisFunction.m index 78d0eaf..19bd785 100644 --- a/MathPad/MPParenthesisFunction.m +++ b/MathPad/MPParenthesisFunction.m @@ -12,6 +12,8 @@ #import "MPExpression.h" #import "MPParenthesisTerm.h" + + @implementation MPParenthesisFunction MPFunctionAccessorImplementation(Expression, _expression) diff --git a/MathPad/MPParenthesisFunctionLayout.h b/MathPad/MPParenthesisFunctionLayout.h index a1b6037..a83d78a 100644 --- a/MathPad/MPParenthesisFunctionLayout.h +++ b/MathPad/MPParenthesisFunctionLayout.h @@ -8,8 +8,11 @@ #import "MPFunctionLayout.h" + + @class MPParenthesisFunctionLayout, MPParenthesisFunction; + @interface MPParenthesisFunctionLayout : MPFunctionLayout - (MPParenthesisFunction *)parenthesisFunction; diff --git a/MathPad/MPParenthesisTerm.h b/MathPad/MPParenthesisTerm.h index 2aace2f..185ea47 100644 --- a/MathPad/MPParenthesisTerm.h +++ b/MathPad/MPParenthesisTerm.h @@ -8,6 +8,11 @@ #import "MPFunctionTerm.h" + + +@class MPParenthesisTerm; + + @interface MPParenthesisTerm : MPFunctionTerm @end diff --git a/MathPad/MPParenthesisTerm.m b/MathPad/MPParenthesisTerm.m index 474e234..8e100e1 100644 --- a/MathPad/MPParenthesisTerm.m +++ b/MathPad/MPParenthesisTerm.m @@ -8,6 +8,8 @@ #import "MPParenthesisTerm.h" +#import "MPParsedExpression.h" + @implementation MPParenthesisTerm - (NSDecimalNumber *)doEvaluation:(NSError *__autoreleasing *)error diff --git a/MathPad/MPParsedExpression.h b/MathPad/MPParsedExpression.h index deabfc1..56794e9 100644 --- a/MathPad/MPParsedExpression.h +++ b/MathPad/MPParsedExpression.h @@ -6,8 +6,10 @@ // Copyright (c) 2014 Kim Wittenburg. All rights reserved. // -@class MPParsedExpression, MPTokenStream, MPTerm; -@protocol MPToken; + + +@class MPParsedExpression, MPTerm; + /*! @const MPMathKitErrorDomain diff --git a/MathPad/MPParsedExpression.m b/MathPad/MPParsedExpression.m index dcc305b..03671c1 100644 --- a/MathPad/MPParsedExpression.m +++ b/MathPad/MPParsedExpression.m @@ -8,7 +8,6 @@ #import "MPParsedExpression.h" -#import "MPTokenStream.h" #import "MPToken.h" #import "MPTerm.h" diff --git a/MathPad/MPPowerFunction.h b/MathPad/MPPowerFunction.h index 61e4c06..38c68fc 100644 --- a/MathPad/MPPowerFunction.h +++ b/MathPad/MPPowerFunction.h @@ -8,16 +8,24 @@ #import "MPFunction.h" + + @class MPPowerFunction, MPExpression; + +/*! + @class MPPowerFunction + @brief This class represents a power. + */ @interface MPPowerFunction : MPFunction /*! - @property baseValue - @brief The receiver's base value. + @property exponentExpression + @brief The receiver's exponent. - @discussion The base value is the thing a suffix function applies to (e.g. - a power's base). + @discussion The base of the power can only be set during evaluation because + it is not actually part of the function element. + The exponent must not define a variable. */ @property (nonatomic, strong) MPExpression *exponentExpression; diff --git a/MathPad/MPPowerFunctionLayout.h b/MathPad/MPPowerFunctionLayout.h index 9d12caa..1c9a2c0 100644 --- a/MathPad/MPPowerFunctionLayout.h +++ b/MathPad/MPPowerFunctionLayout.h @@ -8,8 +8,11 @@ #import "MPFunctionLayout.h" + + @class MPPowerFunctionLayout, MPPowerFunction; + @interface MPPowerFunctionLayout : MPFunctionLayout @property (nonatomic) NSRect baseBounds; diff --git a/MathPad/MPPowerTerm.h b/MathPad/MPPowerTerm.h index af169bc..045114b 100644 --- a/MathPad/MPPowerTerm.h +++ b/MathPad/MPPowerTerm.h @@ -8,6 +8,11 @@ #import "MPFunctionTerm.h" + + +@class MPPowerTerm, MPTerm; + + @interface MPPowerTerm : MPFunctionTerm @property (nonatomic, strong) MPTerm *baseTerm; diff --git a/MathPad/MPProductTerm.h b/MathPad/MPProductTerm.h index b830563..6dbb2ba 100644 --- a/MathPad/MPProductTerm.h +++ b/MathPad/MPProductTerm.h @@ -8,6 +8,11 @@ #import "MPTerm.h" + + +@class MPProductTerm; + + @interface MPProductTerm : MPTerm - (instancetype)initWithFactors:(NSArray *)factors; /* designated initializer */ diff --git a/MathPad/MPProductTerm.m b/MathPad/MPProductTerm.m index 3dfc636..3590fd9 100644 --- a/MathPad/MPProductTerm.m +++ b/MathPad/MPProductTerm.m @@ -18,7 +18,6 @@ #import "MPPowerTerm.h" #import "MPVariable.h" -#import "MPTokenStream.h" #import "MPToken.h" @implementation MPProductTerm diff --git a/MathPad/MPRangePath.h b/MathPad/MPRangePath.h index 6c797bd..1ee1de6 100644 --- a/MathPad/MPRangePath.h +++ b/MathPad/MPRangePath.h @@ -8,6 +8,8 @@ #import "MPExpression.h" + + /// Convenience Constructor Macro #define MPMakeRangePath(loc, len) [MPRangePath rangePathWithLocation:(loc) length:(len)] @@ -50,7 +52,7 @@ /*! @method initWithRange: - @brief Initializes a newly created range path with the given range. + @brief Initializes a newly created range path with the specified range. @discussion This method is a convenience initializer to convert from a @c NSRange to a @c MPRangePath. The location of @c aRange is @@ -66,7 +68,7 @@ /*! @method initWithLocation:lenght: - @brief Initializes a newly created range path with the given location + @brief Initializes a newly created range path with the specified location and length. @discussion The last index in the @c location should address the first item @@ -100,7 +102,7 @@ /*! @method rangePathWithRange: @brief Allocates a new @c MPRangePath instance and initializes it with - the given location and length. + the specified location and length. @discussion The location of @c aRange is translated into an index path for the range path. @@ -116,7 +118,7 @@ /*! @method rangePathWithLocation:length: @brief Allocates a new @c MPRangePath instance and initializes it with - the given location and length. + the specified location and length. @param location The location of the first element that should be addressed by the @@ -254,7 +256,7 @@ new exoression. The range path is specified in the length reference frame. - If the given range exceeds the receiver's bounds a @c + If the specified range exceeds the receiver's bounds a @c NSRangeException is raised. @param aRangePath diff --git a/MathPad/MPSumFunction.h b/MathPad/MPSumFunction.h index 560b8b6..7f88369 100644 --- a/MathPad/MPSumFunction.h +++ b/MathPad/MPSumFunction.h @@ -6,6 +6,13 @@ // Copyright (c) 2014 Kim Wittenburg. All rights reserved. // +/*! + @header + This is a description of the MPFunction class. + + It has multiple lines. + */ + #import "MPFunction.h" @@ -15,8 +22,8 @@ /*! @class MPSumFunction - @brief A sum function (generally noted using a capital sigma) evaluates - a term repeatedly and sums up the results. + @brief This class represents a sum function (generally noted using a + capital sigma). @discussion A sum function has a start and a target expression indicating how often the sum expression should be evaluated. Both the value of @@ -37,13 +44,16 @@ @discussion The start expression must define a variable that may be used in the sum expression. If the start expression does not define a variable the sum function will fail on validation. + @code Some samples */ @property (nonatomic, strong) MPExpression *startExpression; /* Index 0 */ /*! - @property startExpression + @property targetExpression @brief The value if the last iteration. + + @discussion The target expression must not define a variable. */ @property (nonatomic, strong) MPExpression *targetExpression; /* Index 1 */ @@ -55,6 +65,8 @@ @discussion During evaluation of the sum expression the variable defined in the start expression is available. That variable always contains the value of the current iteration. + + The sum expression itself must not define a variable. */ @property (nonatomic, strong) MPExpression *sumExpression; /* Index 2 */ diff --git a/MathPad/MPSumFunction.m b/MathPad/MPSumFunction.m index 184d996..cedc69a 100644 --- a/MathPad/MPSumFunction.m +++ b/MathPad/MPSumFunction.m @@ -10,7 +10,6 @@ #import "MPSumFunctionTerm.h" #import "MPExpression.h" -#import "MPEvaluationContext.h" @@ -37,8 +36,6 @@ MPFunctionAccessorImplementation(SumExpression, _sumExpression) return [MPSumFunctionTerm class]; } -#pragma mark Working With Functions - - (NSString *)description { diff --git a/MathPad/MPSumFunctionLayout.h b/MathPad/MPSumFunctionLayout.h index 9750f51..e530a19 100644 --- a/MathPad/MPSumFunctionLayout.h +++ b/MathPad/MPSumFunctionLayout.h @@ -8,8 +8,11 @@ #import "MPFunctionLayout.h" + + @class MPSumFunctionLayout, MPSumFunction; + @interface MPSumFunctionLayout : MPFunctionLayout - (MPSumFunction *)sumFunction; diff --git a/MathPad/MPSumFunctionTerm.h b/MathPad/MPSumFunctionTerm.h index 34f31f8..6768030 100644 --- a/MathPad/MPSumFunctionTerm.h +++ b/MathPad/MPSumFunctionTerm.h @@ -8,6 +8,11 @@ #import "MPFunctionTerm.h" + + +@class MPSumFunctionTerm; + + @interface MPSumFunctionTerm : MPFunctionTerm @end diff --git a/MathPad/MPSumFunctionTerm.m b/MathPad/MPSumFunctionTerm.m index 95866ed..7505dc8 100644 --- a/MathPad/MPSumFunctionTerm.m +++ b/MathPad/MPSumFunctionTerm.m @@ -8,6 +8,8 @@ #import "MPSumFunctionTerm.h" +#import "MPParsedExpression.h" + @implementation MPSumFunctionTerm - (NSDecimalNumber *)doEvaluation:(NSError *__autoreleasing *)error diff --git a/MathPad/MPSumTerm.h b/MathPad/MPSumTerm.h index 25834fe..e6b79ce 100644 --- a/MathPad/MPSumTerm.h +++ b/MathPad/MPSumTerm.h @@ -8,6 +8,11 @@ #import "MPTerm.h" + + +@class MPSumTerm; + + @interface MPSumTerm : MPTerm - (instancetype)initWithSummands:(NSArray *)summands; /* designated initializer */ diff --git a/MathPad/MPSumTerm.m b/MathPad/MPSumTerm.m index 14e9322..5ba87e0 100644 --- a/MathPad/MPSumTerm.m +++ b/MathPad/MPSumTerm.m @@ -11,7 +11,6 @@ #import "MPParsedExpression.h" #import "MPProductTerm.h" -#import "MPTokenStream.h" #import "MPToken.h" @implementation MPSumTerm diff --git a/MathPad/MPTerm.h b/MathPad/MPTerm.h index 9aa9e08..188547d 100644 --- a/MathPad/MPTerm.h +++ b/MathPad/MPTerm.h @@ -7,8 +7,8 @@ // -@class MPTerm, MPTokenStream; -@protocol MPToken; +@class MPTerm; + @interface MPTerm : NSObject diff --git a/MathPad/MPToken.h b/MathPad/MPToken.h index d117d8b..96387be 100644 --- a/MathPad/MPToken.h +++ b/MathPad/MPToken.h @@ -14,9 +14,16 @@ /*! @typedef MPTokenType - @brief A type of a token identifies its behaviour in a mathematical + @brief The type of a token identifies its behaviour in a mathematical context. + @constant MPEOFToken + A token that represents the end of the input. This token should + not be used to create a @c MPToken instance. It exists so that + you can safely send a @c tokenType message to @c nil without + getting confusing results. A token with this token type should be + interpreted as 'no token'. + @constant MPMultiplicationSymbolToken A multiplication symbol. @@ -82,8 +89,8 @@ typedef NS_ENUM(NSUInteger, MPTokenType) { @brief Returns the receiver's token type. @discussion The token type identifies what kind of token the receiver is. For - more information see the documentation on the @c MPTokenType - enum. + more information see the documentation on the MPTokenType + enum. @return The receiver's token type. */ diff --git a/MathPad/MPToken.m b/MathPad/MPToken.m index fcfc301..ce6bb8c 100644 --- a/MathPad/MPToken.m +++ b/MathPad/MPToken.m @@ -10,11 +10,17 @@ -@implementation MPToken { - NSRange _range; - MPTokenType _tokenType; - NSString *_stringValue; -} +@interface MPToken () + +@property (readonly, nonatomic) NSRange range; +@property (readonly, nonatomic, strong) NSString *stringValue; +@property (readonly, nonatomic) MPTokenType tokenType; + +@end + + + +@implementation MPToken - (instancetype)initWithTokenType:(MPTokenType)tokenType range:(NSRange)range @@ -30,24 +36,6 @@ } -- (NSRange)range -{ - return _range; -} - - -- (MPTokenType)tokenType -{ - return _tokenType; -} - - -- (NSString *)stringValue -{ - return _stringValue; -} - - - (NSString *)description { return self.stringValue; diff --git a/MathPad/MPTokenStream.h b/MathPad/MPTokenStream.h deleted file mode 100644 index 6deec6f..0000000 --- a/MathPad/MPTokenStream.h +++ /dev/null @@ -1,137 +0,0 @@ -// -// MPTokenStream.h -// MathPad -// -// Created by Kim Wittenburg on 20.09.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - - - -@class MPTokenStream; -@protocol MPToken; - - -/*! - @class MPTokenStream - @brief This class is a helper class for processing tokens from the - beginning of an expression to the end. - - @discussion A token stream is a single-use object. After the stream has - reached the end there is no way to reset it. - */ -@interface MPTokenStream : NSObject - - -/*! - @method initWithTokens: - @brief Creates a new token stream that @em streams the contents of the - @c tokens array. - - @param tokens - The tokens to be @em streamed. All objects in the array must - conform to the @c MPToken protocol. - - @return A new token stream. - */ -- (instancetype)initWithTokens:(NSArray *)tokens; /* designated initializer */ - - -/*! - @method beginIgnoringWhitespaceTokens - @brief After calling this method a @c -currentToken message will skip - whitespace characters before returning the current token. - - @discussion Any call to this method or @c -beginAcceptingWhitespaceTokens - must be matched by a @c -endIgnoringOrAcceptingWhitespaceTokens - message. Calls to both methods can be nested. - - By default whitespace tokens are accepted. - - @see -beginAcceptingWhitespaceTokens - @see -endIgnoringOrAcceptingWhitespaceTokens - */ -- (void)beginIgnoringWhitespaceTokens; - - -/*! - @method beginAcceptingWhitespaceTokens - @brief After calling this method @c -currentToken may return a token of - type @c MPWhitespaceToken. - - @discussion Any call to this method or @c -beginAcceptingWhitespaceTokens - must be matched by a @c -endIgnoringOrAcceptingWhitespaceTokens - message. Calls to both methods can be nested. - - By default whitespace tokens are accepted. - - @see -beginIgnoringWhitespaceTokens - @see -endIgnoringOrAcceptingWhitespaceTokens - */ -- (void)beginAcceptingWhitespaceTokens; - - -/*! - @method endIgnoringOrAcceptingWhitespaceTokens - @brief This method balances @c -beginIgnoringWhitespaceTokens and @c - -beginAcceptingWhitespaceTokens messages. - - @discussion After this method was - calles the whitespace behaviour falls back to the way it behaved - before the last @c -beginIgnoringWhitespaceTokens or @c - -beginAcceptingWhitespaceTokens message was sent. - */ -- (void)endIgnoringOrAcceptingWhitespaceTokens; - - - -/*! - @method hasMoreTokens - @brief Use this method to check wether there are any tokens left. - - @discussion This method repects the whitespace skipping behaviour. That means - that if the token stream currently ignores whitespaces and there - are only whitespaces left in the stream this method returns @c - NO. - - @return @c YES if there are more tokens, @c NO otherwise. - */ -- (BOOL)hasMoreTokens; - - -/*! - @method currentToken - @brief Returns the receiver's current token. - - @discussion This is one of the core methods of @c MPTokenStream. Subsequent - calls to this method will return the same value until @c - -currentTokenConsumed is called. - - @return The current token or @c nil if there are no more tokens. - */ -- (id)currentToken; - - -/*! - @method peekNextToken - @brief Looks at the next token and returns it. - - @discussion This method behaves as if you called @c -currentTokenConsumed - followed by @c -currentToken except that it does not consume the - current token. That means that you can use this method to look at - the next token (respecting the current whitespace ignoring - behaviour) without changing the @c currentToken. - - @return The next token or @c nil if there is no token after the current - one. - */ -- (id)peekNextToken; - - -/*! - @method currentTokenConsumed - @brief Marks the current token as consumed and discards it. - */ -- (void)currentTokenConsumed; - -@end diff --git a/MathPad/MPTokenStream.m b/MathPad/MPTokenStream.m deleted file mode 100644 index 1d85393..0000000 --- a/MathPad/MPTokenStream.m +++ /dev/null @@ -1,140 +0,0 @@ -// -// MPTokenStream.m -// MathPad -// -// Created by Kim Wittenburg on 20.09.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import "MPTokenStream.h" - -#import "MPToken.h" - - - -@interface MPTokenStream () - -@property (nonatomic, copy) NSArray *tokens; -@property (nonatomic) NSUInteger currentTokenIndex; -@property (nonatomic) NSUInteger eofLocation; - -@property (nonatomic) BOOL *whitespaceStates; -@property (nonatomic) NSUInteger maxWhitespaceIgnores; -@property (nonatomic) NSUInteger currentWhitespaceIgnoreState; - -- (void)pushWhitespaceState:(BOOL)state; - -@end - - -@implementation MPTokenStream - -- (instancetype)initWithTokens:(NSArray *)tokens -{ - self = [super init]; - if (self) { - self.tokens = tokens; - self.whitespaceStates = malloc(10 * sizeof(BOOL)); - self.maxWhitespaceIgnores = 10; - self.currentWhitespaceIgnoreState = 0; - [self beginAcceptingWhitespaceTokens]; - _currentTokenIndex = 0; - if (tokens.count > 0) { - self.eofLocation = NSMaxRange([tokens.lastObject range]); - } else { - self.eofLocation = 0; - } - } - return self; -} - - -- (void)beginAcceptingWhitespaceTokens -{ - [self pushWhitespaceState:YES]; -} - - -- (void)beginIgnoringWhitespaceTokens -{ - [self pushWhitespaceState:NO]; -} - - -- (void)pushWhitespaceState:(BOOL)state -{ - self.currentWhitespaceIgnoreState++; - if (self.currentWhitespaceIgnoreState >= self.maxWhitespaceIgnores) { - self.maxWhitespaceIgnores += 10; - BOOL *reallocatedWhitespaceIgnores = realloc(self.whitespaceStates, self.maxWhitespaceIgnores); - if (reallocatedWhitespaceIgnores) { - self.whitespaceStates = reallocatedWhitespaceIgnores; - } else { - @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"Realloc Failed" userInfo:nil]; - } - } - self.whitespaceStates[self.currentWhitespaceIgnoreState] = state; -} - - -- (void)endIgnoringOrAcceptingWhitespaceTokens -{ - self.currentWhitespaceIgnoreState--; -} - - -- (void)skipWhitespaces -{ - if (self.whitespaceStates[self.currentWhitespaceIgnoreState]) { - return; - } - while (_currentTokenIndex < self.tokens.count) { - MPToken *token = self.tokens[_currentTokenIndex]; - if (token.tokenType != MPWhitespaceToken) { - return; - } - _currentTokenIndex++; - } -} - - -- (BOOL)hasMoreTokens -{ - [self skipWhitespaces]; - return _currentTokenIndex < self.tokens.count; -} - - -- (id)currentToken -{ - [self skipWhitespaces]; - if (_currentTokenIndex >= _tokens.count) { - return nil; - } - return _tokens[_currentTokenIndex]; -} - - -- (id)peekNextToken -{ - NSUInteger currentTokenIndex = _currentTokenIndex; - [self currentTokenConsumed]; // Pretend the current token has been consumed - id token = [self currentToken]; - _currentTokenIndex = currentTokenIndex; // Undo the lookahead - return token; -} - - -- (void)currentTokenConsumed -{ - [self currentToken]; - ++_currentTokenIndex; -} - - -- (void)dealloc -{ - free(self.whitespaceStates); -} - -@end diff --git a/MathPad/MPVariable.h b/MathPad/MPVariable.h index c12ed26..9f884cc 100644 --- a/MathPad/MPVariable.h +++ b/MathPad/MPVariable.h @@ -8,8 +8,11 @@ #import "MPTerm.h" + + @class MPVariable; + @interface MPVariable : MPTerm - (instancetype)initWithVariableName:(NSString *)variableName; /* designated initializer */ diff --git a/MathPad/MPVariable.m b/MathPad/MPVariable.m index b29e0f3..3f8a2a1 100644 --- a/MathPad/MPVariable.m +++ b/MathPad/MPVariable.m @@ -10,7 +10,6 @@ #import "MPParsedExpression.h" -#import "MPTokenStream.h" #import "MPToken.h" #import "MPExpression.h" diff --git a/MathPad/MPWhiteView.h b/MathPad/MPWhiteView.h index a0b5457..5de222e 100644 --- a/MathPad/MPWhiteView.h +++ b/MathPad/MPWhiteView.h @@ -6,8 +6,11 @@ // Copyright (c) 2014 Kim Wittenburg. All rights reserved. // + + @class MPWhiteView; + @interface MPWhiteView : NSView @end diff --git a/MathPad/MPWhiteView.m b/MathPad/MPWhiteView.m index 2923a9c..449ef89 100644 --- a/MathPad/MPWhiteView.m +++ b/MathPad/MPWhiteView.m @@ -8,6 +8,8 @@ #import "MPWhiteView.h" + + @implementation MPWhiteView - (void)drawRect:(NSRect)dirtyRect { diff --git a/MathPad/MathPad-Info.plist b/MathPad/MathPad-Info.plist index d26f8e5..2baf4b7 100644 --- a/MathPad/MathPad-Info.plist +++ b/MathPad/MathPad-Info.plist @@ -2,6 +2,8 @@ + ATSApplicationFontsPath + Fonts CFBundleDevelopmentRegion en CFBundleDocumentTypes @@ -42,7 +44,7 @@ CFBundleSignature ???? CFBundleVersion - 1 + 42 LSApplicationCategoryType public.app-category.education LSMinimumSystemVersion @@ -51,8 +53,6 @@ Copyright © 2014 Kim Wittenburg. All rights reserved. NSMainNibFile MainMenu - ATSApplicationFontsPath - Fonts NSPrincipalClass NSApplication diff --git a/MathPad/NSIndexPath+MPAdditions.h b/MathPad/NSIndexPath+MPAdditions.h index 500a702..157c203 100644 --- a/MathPad/NSIndexPath+MPAdditions.h +++ b/MathPad/NSIndexPath+MPAdditions.h @@ -63,11 +63,11 @@ /*! @method indexPathByPreceedingIndex: - @brief Provides an index path with the given index followed by the + @brief Provides an index path with the specified index followed by the indexes of the receiver. - @discussion If the receiver does not contain any indexes the given index is - the only index contained in the returned index path. + @discussion If the receiver does not contain any indexes the specified index + is the only index contained in the returned index path. @param index The index new index preceeding all others @@ -109,7 +109,7 @@ /*! @method indexPathByRemovingIndexesFrom: @brief Provides an index path with the indexes in the recieving index - path up to the index at the given position. + path up to the index at the specified position. @discussion If @c from is greater or equal to the number of indexes in the receiving index path only the indexes to the end of the receiver @@ -147,7 +147,7 @@ /*! @method commonIndexPathWith: @brief Provides an index path that contains the first indexes of the - receiver that are equal to the given index path. + receiver that are equal to the specified index path. @discussion If one index path is completely included in the other a new index path is returned that is equal to the contained index path. diff --git a/MathPad/en.lproj/Credits.rtf b/MathPad/en.lproj/Credits.rtf index 46576ef..5c436e9 100644 --- a/MathPad/en.lproj/Credits.rtf +++ b/MathPad/en.lproj/Credits.rtf @@ -1,29 +1,37 @@ -{\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} +{\rtf1\ansi\ansicpg1252\cocoartf1343\cocoasubrtf160 +{\fonttbl\f0\fswiss\fcharset0 Helvetica;} {\colortbl;\red255\green255\blue255;} -\paperw9840\paperh8400 -\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural +\paperw11904\paperh16836\vieww9600\viewh8400\viewkind0 +\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural -\f0\b\fs24 \cf0 Engineering: +\f0\fs24 \cf0 This application was created by Kim Wittenburg as part of the final exam. +\b \ +\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720 +\cf0 \ +Engineering: \b0 \ - Some people\ + Kim Wittenburg\ \ \b Human Interface Design: \b0 \ - Some other people\ + Kim Wittenburg\ \ \b Testing: \b0 \ - Hopefully not nobody\ + Kim Wittenburg\ + Vincent Bettaque\ + Nils Burmeister\ + Jonas Rittmeyer\ \ \b Documentation: \b0 \ - Whoever\ + Kim Wittenburg\ \ \b With special thanks to: \b0 \ - Mom\ -} + 13n, Gymnasium Wentorf\ +} \ No newline at end of file