net.percederberg.grammatica.parser
Class ProductionPatternElement

java.lang.Object
  |
  +--net.percederberg.grammatica.parser.ProductionPatternElement

public class ProductionPatternElement
extends java.lang.Object

A production pattern element. This class represents a reference to either a token or a production. Each element also contains minimum and maximum occurence counters, controlling the number of repetitions allowed. A production pattern element is always contained within a production pattern rule.


Constructor Summary
ProductionPatternElement(boolean isToken, int id, int min, int max)
          Creates a new element.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Checks if this object is equal to another.
 int getId()
          Returns the node identity.
 int getMaxCount()
          Returns the maximum occurence count.
 int getMinCount()
          Returns the minimum occurence count.
 boolean isMatch(Token token)
          Checks if a specific token matches this element.
 boolean isProduction()
          Returns true if this element represents a production.
 boolean isToken()
          Returns true if this element represents a token.
 java.lang.String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ProductionPatternElement

public ProductionPatternElement(boolean isToken,
                                int id,
                                int min,
                                int max)
Creates a new element. If the maximum value if zero (0) or negative, it will be set to Integer.MAX_VALUE.

Parameters:
isToken - the token flag
id - the node identity
min - the minimum number of occurancies
max - the maximum number of occurancies, or negative for infinite
Method Detail

isToken

public boolean isToken()
Returns true if this element represents a token.

Returns:
true if the element is a token, or false otherwise

isProduction

public boolean isProduction()
Returns true if this element represents a production.

Returns:
true if the element is a production, or false otherwise

isMatch

public boolean isMatch(Token token)
Checks if a specific token matches this element. This method will only return true if this element is a token element, and the token has the same id and this element.

Parameters:
token - the token to check
Returns:
true if the token matches this element, or false otherwise

getId

public int getId()
Returns the node identity.

Returns:
the node identity

getMinCount

public int getMinCount()
Returns the minimum occurence count.

Returns:
the minimum occurence count

getMaxCount

public int getMaxCount()
Returns the maximum occurence count.

Returns:
the maximum occurence count

equals

public boolean equals(java.lang.Object obj)
Checks if this object is equal to another. This method only returns true for another identical production pattern element.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to compare with
Returns:
true if the object is identical to this one, or false otherwise

toString

public java.lang.String toString()
Returns a string representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this object