net.percederberg.grammatica.parser
Class ProductionPattern

java.lang.Object
  extended bynet.percederberg.grammatica.parser.ProductionPattern

public class ProductionPattern
extends java.lang.Object

A production pattern. This class represents a set of production alternatives that together forms a single production. A production pattern is identified by an integer id and a name, both provided upon creation. The pattern id is used for referencing the production pattern from production pattern elements.


Constructor Summary
ProductionPattern(int id, java.lang.String name)
          Creates a new production pattern.
 
Method Summary
 void addAlternative(ProductionPatternAlternative alt)
          Adds a production pattern alternative.
 ProductionPatternAlternative getAlternative(int pos)
          Returns an alternative in this pattern.
 int getAlternativeCount()
          Returns the number of alternatives in this pattern.
 int getId()
          Returns the unique production pattern identity value.
 java.lang.String getName()
          Returns the production pattern name.
 boolean isLeftRecursive()
          Checks if this pattern is recursive on the left-hand side.
 boolean isMatchingEmpty()
          Checks if this pattern would match an empty stream of tokens.
 boolean isRightRecursive()
          Checks if this pattern is recursive on the right-hand side.
 boolean isSyntetic()
          Checks if the syntetic production flag is set.
 void setSyntetic(boolean syntetic)
          Sets the syntetic production pattern flag.
 java.lang.String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ProductionPattern

public ProductionPattern(int id,
                         java.lang.String name)
Creates a new production pattern.

Parameters:
id - the production pattern id
name - the production pattern name
Method Detail

isSyntetic

public boolean isSyntetic()
Checks if the syntetic production flag is set. If this flag is set, the production identified by this pattern has been artificially inserted into the grammar. No parse tree nodes will be created for such nodes, instead the child nodes will be added directly to the parent node.

Returns:
true if this production pattern is syntetic, or false otherwise

isLeftRecursive

public boolean isLeftRecursive()
Checks if this pattern is recursive on the left-hand side. This method checks if any of the production pattern alternatives is left-recursive.

Returns:
true if at least one alternative is left recursive, or false otherwise

isRightRecursive

public boolean isRightRecursive()
Checks if this pattern is recursive on the right-hand side. This method checks if any of the production pattern alternatives is right-recursive.

Returns:
true if at least one alternative is right recursive, or false otherwise

isMatchingEmpty

public boolean isMatchingEmpty()
Checks if this pattern would match an empty stream of tokens. This method checks if any one of the production pattern alternatives would match the empty token stream.

Returns:
true if at least one alternative match no tokens, or false otherwise

getId

public int getId()
Returns the unique production pattern identity value.

Returns:
the production pattern id

getName

public java.lang.String getName()
Returns the production pattern name.

Returns:
the production pattern name

setSyntetic

public void setSyntetic(boolean syntetic)
Sets the syntetic production pattern flag. If this flag is set, the production identified by this pattern has been artificially inserted into the grammar. By default this flag is set to false.

Parameters:
syntetic - the new value of the syntetic flag

getAlternativeCount

public int getAlternativeCount()
Returns the number of alternatives in this pattern.

Returns:
the number of alternatives in this pattern

getAlternative

public ProductionPatternAlternative getAlternative(int pos)
Returns an alternative in this pattern.

Parameters:
pos - the alternative position, 0 <= pos < count
Returns:
the alternative found

addAlternative

public void addAlternative(ProductionPatternAlternative alt)
                    throws ParserCreationException
Adds a production pattern alternative.

Parameters:
alt - the production pattern alternative to add
Throws:
ParserCreationException - if an identical alternative has already been added

toString

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

Returns:
a token string representation