ftp.nice.ch/pub/next/developer/resources/classes/misckit/MiscKit.1.10.0.s.gnutar.gz#/MiscKit/Documentation/Classes/MiscIfStack.rtf

This is MiscIfStack.rtf in view mode; [Download] [Up]

Version 1.0 Copyright ©1995 by Don Yacktman, All Rights Reserved.




MiscIfStack 






Inherits From:	MiscStack
Declared In:	misckit/MiscIfStack.h





Class Description

A MiscIfStack is a specialized stack which may be used in a dynamic interpreter to implement if/then/else/endif constructs.  The syntax is expected to have an ªendifº match every single ªifº token.  The ªelseº token is optional.  The ªifº, ªelseº, and ªendifº divide the interpreted code into blocks.  The MiscIfStack can tell you whether or not the current block should be executed.  This includes correct handling of nested ifs.

To use a MiscIfStack, first send a -reset message.  Then, whenever an ªifº token is encountered in the parsing, send a -startIf: message to the MiscIfStack.  If the conditional evaluated true, use YES as the argument.  Us NO if it evaluated falsely.  When (and if) an ªelseº token is encountered, send a -startElse message.  Finally, when the ªendifº toekn is encountered, send a -endIf message.

To determine if the current block should be executed, simply query the MiscIfStack with a -currentConditionalIsActive message.  If YES is returned, then the code should be executed.




Instance Variables









Method Types

 Set up 	- reset

Handling statements 	- startIf:
- startElse
- endIf
- currentConditionalIsActive

Error notification 	- endWithoutIfError
- elseWithoutIfError
- doubleElseIfError





Instance Methods

currentConditionalIsActive
- (BOOL)currentConditionalIsActive

Returns YES if the ªifº or ªelseº block on top of the stack evaluates true and should be executed.  Returns NO otherwise. 




doubleElseIfError
- (void)doubleElseIfError

Prints a diagnostic error message to the console if two ªelseº tokens are found in a row.  This is syntactically the same as having an ªelseº without a matching ªifº. 




elseWithoutIfError
- (void)elseWithoutIfError

Prints a diagnostic error message to the console if an ªelseº token is found that does not have a matching ªifº token. 




endIf
- endIf

Ends an ªif-elseº block, returning the MiscIfStack to the status of the block before the ªifº to be cleared was encountered.  Returns self if successful and nil if there was an error, such as an ªendifº without a matching ªifº. 




endWithoutIfError
- (void)endWithoutIfError

Prints a diagnostic error message to the console if an ªendifº token is found that does not have a matching ªifº token. 




reset
- reset

Clears the MiscIfStack.  This should be called whenever a new program is started.  Returns self. 




startElse
- startElse

Begins an ªelseº block, changing the status to be the opposite of the ªifº block this is paired to.  Returns self if successful and nil if an error occurs.  Errors include two ªelseº tokens in a row or an ªelseº without an accompanying ªifº token. 




startIf:
- startIf:(BOOL)isActive

Starts an ªifº block.  If the ªifº evaluates to true, then isActive should be YES, NO otherwise.  This will be used to determine the current status of the MiscIfStack.  Returns self, or nil if an error occurs. 

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.