CPRule Class Reference
| Inherits from | NSObject | 
| Conforms to | NSCoding | 
| Declared in | CPRule.h CPRule.m  | 
Overview
The CPRule class represents a context free rule.
Rules are used to specify how your language is structured – each rule specifies that the non-terminal on their left can be constructed by finding the sequence specified on the right hand side.
Rules are added to CPGrammars to construct a language to parse.
During parsing, a CPParser will inform its delegate of which CPRule it has matched to form a reduction. The tag property is provided to allow you to easily identify which rule has been matched.
Tasks
Creating and Initialising a Rule
- 
	
		
+ ruleWithName:rightHandSideElements:Creates a rule based on a non-terminal name and an array of grammar symbols to make up the right hand side.
 - 
	
		
+ ruleWithName:rightHandSideElements:tag:Creates a rule based on a non-terminal name and an array of grammar symbols to make up the right hand side. Also specifies a tag by which the rule can be identified in a parser delegate
 - 
	
		
+ ruleWithName:rightHandSideElements:representitiveClass:Creates a rule based on a non-terminal name and an array of grammar symbols to make up the right hand side. Also specifies the class to allocate to represent this rule.
 - 
	
		
– initWithName:rightHandSideElements:Initialises a rule based on a non-terminal name and an array of grammar symbols to make up the right hand side.
 - 
	
		
– initWithName:rightHandSideElements:tag:Initialises a rule based on a non-terminal name and an array of grammar symbols to make up the right hand side. Also specifies a tag by which the rule can be identified in a parser delegate
 - 
	
		
– initWithName:rightHandSideElements:representitiveClass:Initialises a rule based on a non-terminal name and an array of grammar symbols to make up the right hand side. Also specifies the class to allocate to represent this rule.
 
Configuring a Rule
- 
	
		
nameSpecifies the name of the non-terminal this rule describes.
property - 
	
		
rightHandSideElementsSpecifies the right hand side of the rule.
property - 
	
		
tagA tag used to identify the rule in the parser delegate.
property - 
	
		
representitiveClassThe class used to represent syntax trees based off this rule.
property 
Properties
name
Specifies the name of the non-terminal this rule describes.
@property (readwrite, retain) NSString *nameDiscussion
Specifies the name of the non-terminal this rule describes.
Declared In
CPRule.hrepresentitiveClass
The class used to represent syntax trees based off this rule.
@property (readwrite, assign) Class representitiveClassDiscussion
The class used to represent syntax trees based off this rule.
Declared In
CPRule.hClass Methods
ruleWithName:rightHandSideElements:
Creates a rule based on a non-terminal name and an array of grammar symbols to make up the right hand side.
+ (id)ruleWithName:(NSString *)name rightHandSideElements:(NSArray *)rightHandSideElementsParameters
- name
 The non-terminal the rule reduces.
- rightHandSideElements
 An array of CPGrammarSymbols that make up the right hand side of the rule.
Return Value
Returns a CPRule based on the right hand side and non-terminal name.
Discussion
Creates a rule based on a non-terminal name and an array of grammar symbols to make up the right hand side.
See Also
Declared In
CPRule.hruleWithName:rightHandSideElements:representitiveClass:
Creates a rule based on a non-terminal name and an array of grammar symbols to make up the right hand side. Also specifies the class to allocate to represent this rule.
+ (id)ruleWithName:(NSString *)name rightHandSideElements:(NSArray *)rightHandSideElements representitiveClass:(Class)representitiveClassParameters
- name
 The non-terminal the rule reduces.
- rightHandSideElements
 An array of CPGrammarSymbols that make up the right hand side of the rule.
- representitiveClass
 The class used to represent this rule.
Return Value
Returns a CPRule based on the right hand side and non-terminal name.
Discussion
Creates a rule based on a non-terminal name and an array of grammar symbols to make up the right hand side. Also specifies the class to allocate to represent this rule.
See Also
Declared In
CPRule.hruleWithName:rightHandSideElements:tag:
Creates a rule based on a non-terminal name and an array of grammar symbols to make up the right hand side. Also specifies a tag by which the rule can be identified in a parser delegate
+ (id)ruleWithName:(NSString *)name rightHandSideElements:(NSArray *)rightHandSideElements tag:(NSUInteger)tagParameters
- name
 The non-terminal the rule reduces.
- rightHandSideElements
 An array of CPGrammarSymbols that make up the right hand side of the rule.
- tag
 A tag to identify the rule by.
Return Value
Returns a CPRule based on the right hand side and non-terminal name.
Discussion
Creates a rule based on a non-terminal name and an array of grammar symbols to make up the right hand side. Also specifies a tag by which the rule can be identified in a parser delegate
See Also
Declared In
CPRule.hInstance Methods
initWithName:rightHandSideElements:
Initialises a rule based on a non-terminal name and an array of grammar symbols to make up the right hand side.
- (id)initWithName:(NSString *)name rightHandSideElements:(NSArray *)rightHandSideElementsParameters
- name
 The non-terminal the rule reduces.
- rightHandSideElements
 An array of CPGrammarSymbols that make up the right hand side of the rule.
Return Value
Returns a CPRule based on the right hand side and non-terminal name.
Discussion
Initialises a rule based on a non-terminal name and an array of grammar symbols to make up the right hand side.
Declared In
CPRule.hinitWithName:rightHandSideElements:representitiveClass:
Initialises a rule based on a non-terminal name and an array of grammar symbols to make up the right hand side. Also specifies the class to allocate to represent this rule.
- (id)initWithName:(NSString *)name rightHandSideElements:(NSArray *)rightHandSideElements representitiveClass:(Class)representitiveClassParameters
- name
 The non-terminal the rule reduces.
- rightHandSideElements
 An array of CPGrammarSymbols that make up the right hand side of the rule.
- representitiveClass
 The class used to represent this rule.
Return Value
Returns a CPRule based on the right hand side and non-terminal name.
Discussion
Initialises a rule based on a non-terminal name and an array of grammar symbols to make up the right hand side. Also specifies the class to allocate to represent this rule.
See Also
Declared In
CPRule.hinitWithName:rightHandSideElements:tag:
Initialises a rule based on a non-terminal name and an array of grammar symbols to make up the right hand side. Also specifies a tag by which the rule can be identified in a parser delegate
- (id)initWithName:(NSString *)name rightHandSideElements:(NSArray *)rightHandSideElements tag:(NSUInteger)tagParameters
- name
 The non-terminal the rule reduces.
- rightHandSideElements
 An array of CPGrammarSymbols that make up the right hand side of the rule.
- tag
 A tag to identify the rule by.
Return Value
Returns a CPRule based on the right hand side and non-terminal name.
Discussion
Initialises a rule based on a non-terminal name and an array of grammar symbols to make up the right hand side. Also specifies a tag by which the rule can be identified in a parser delegate
Declared In
CPRule.h