Overview   Project   Class   Tree   Deprecated   Index 
Grammatica 1.3 Documentation
FRAMES    NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD

PerCederberg.Grammatica.Parser
Class ProductionPatternAlternative

System.Object
   |
   +--ProductionPatternAlternative

   in ProductionPatternAlternative.cs

class ProductionPatternAlternative
extends System.Object

A production pattern alternative. This class represents a list of production pattern elements. In order to provide productions that cannot be represented with the element occurance counters, multiple alternatives must be created and added to the same production pattern. A production pattern alternative is always contained within a production pattern.


Constructor Summary
ProductionPatternAlternative()
          Creates a new production pattern alternative.
 
Method Summary
 void AddElement( ProductionPatternElement elem )
          Adds a production pattern element to this alternative.
 void AddElement( ProductionPatternElement elem, int min, int max )
          Adds a production pattern element to this alternative.
 void AddProduction( int id, int min, int max )
          Adds a production to this alternative.
 void AddToken( int id, int min, int max )
          Adds a token to this alternative.
 override bool Equals( object obj )
          Checks if this object is equal to another.
 bool Equals( ProductionPatternAlternative alt )
          Checks if this alternative is equal to another.
 ProductionPatternElement GetElement( int pos )
          Returns an element in this alternative.
 int GetElementCount()
          Returns the number of elements in this alternative.
 internal LookAheadSet GetLookAhead()
          Returns the look-ahead set associated with this alternative.
 int GetMaxElementCount()
          Returns the maximum number of elements needed to satisfy this alternative.
 int GetMinElementCount()
          Returns the minimum number of elements needed to satisfy this alternative.
 ProductionPattern GetPattern()
          Returns the production pattern containing this alternative.
 bool IsLeftRecursive()
          Checks if this alternative is recursive on the left-hand side.
 bool IsMatchingEmpty()
          Checks if this alternative would match an empty stream of tokens.
 bool IsRightRecursive()
          Checks if this alternative is recursive on the right-hand side.
 internal void SetLookAhead( LookAheadSet lookAhead )
          Sets the look-ahead set for this alternative.
 internal void SetPattern( ProductionPattern pattern )
          Changes the production pattern containing this alternative.
 override string ToString()
          Returns a string representation of this object.
 

Constructor Detail

ProductionPatternAlternative

public ProductionPatternAlternative();
Creates a new production pattern alternative.


Method Detail

AddElement

public void AddElement( ProductionPatternElement elem );
Adds a production pattern element to this alternative. The element is appended to the end of the element list.
Parameters:
elem - the production pattern element

AddElement

public void AddElement( ProductionPatternElement elem, int min, int max );
Adds a production pattern element to this alternative. The multiplicity values in the element will be overridden with the specified values. The element is appended to the end of the element list.
Parameters:
elem - the production pattern element
min - the minimum number of occurancies
max - the maximum number of occurancies, or -1 for infinite

AddProduction

public void AddProduction( int id, int min, int max );
Adds a production to this alternative. The production is appended to the end of the element list. The multiplicity values specified define if the production is optional or required, and if it can be repeated.
Parameters:
id - the production (pattern) id
min - the minimum number of occurancies
max - the maximum number of occurancies, or -1 for infinite

AddToken

public void AddToken( int id, int min, int max );
Adds a token to this alternative. The token is appended to the end of the element list. The multiplicity values specified define if the token is optional or required, and if it can be repeated.
Parameters:
id - the token (pattern) id
min - the minimum number of occurancies
max - the maximum number of occurancies, or -1 for infinite

Equals

public override bool Equals( object obj );
Checks if this object is equal to another. This method only returns true for another production pattern alternative with identical elements in the same order.
Parameters:
obj - the object to compare with
Returns:
true if the object is identical to this one, or false otherwise

Equals

public bool Equals( ProductionPatternAlternative alt );
Checks if this alternative is equal to another. This method returns true if the other production pattern alternative has identical elements in the same order.
Parameters:
alt - the alternative to compare with
Returns:
true if the object is identical to this one, or false otherwise

GetElement

public ProductionPatternElement GetElement( int pos );
Returns an element in this alternative.
Parameters:
pos - the element position, 0 <= pos < count
Returns:
the element found

GetElementCount

public int GetElementCount();
Returns the number of elements in this alternative.
Returns:
the number of elements in this alternative

GetLookAhead

 internal LookAheadSet GetLookAhead();
Returns the look-ahead set associated with this alternative.
Returns:
the look-ahead set associated with this alternative

GetMaxElementCount

public int GetMaxElementCount();
Returns the maximum number of elements needed to satisfy this alternative. The value returned is the sum of all the elements maximum count.
Returns:
the maximum number of elements

GetMinElementCount

public int GetMinElementCount();
Returns the minimum number of elements needed to satisfy this alternative. The value returned is the sum of all the elements minimum count.
Returns:
the minimum number of elements

GetPattern

public ProductionPattern GetPattern();
Returns the production pattern containing this alternative.
Returns:
the production pattern for this alternative

IsLeftRecursive

public bool IsLeftRecursive();
Checks if this alternative is recursive on the left-hand side. This method checks all the possible left side elements and returns true if the pattern itself is among them.
Returns:
true if the alternative is left side recursive, or false otherwise

IsMatchingEmpty

public bool IsMatchingEmpty();
Checks if this alternative would match an empty stream of tokens. This check is equivalent of getMinElementCount() returning zero (0).
Returns:
true if the rule can match an empty token stream, or false otherwise

IsRightRecursive

public bool IsRightRecursive();
Checks if this alternative is recursive on the right-hand side. This method checks all the possible right side elements and returns true if the pattern itself is among them.
Returns:
true if the alternative is right side recursive, or false otherwise

SetLookAhead

 internal void SetLookAhead( LookAheadSet lookAhead );
Sets the look-ahead set for this alternative.
Parameters:
lookAhead - the new look-ahead set

SetPattern

 internal void SetPattern( ProductionPattern pattern );
Changes the production pattern containing this alternative. This method should only be called by the production pattern class.
Parameters:
pattern - the new production pattern

ToString

public override string ToString();
Returns a string representation of this object.
Returns:
a token string representation

 Overview   Project   Class   Tree   Deprecated   Index 
Grammatica 1.3 Documentation
FRAMES    NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD