net.percederberg.grammatica.parser
Class ProductionPattern

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

public class ProductionPattern
extends java.lang.Object

A production pattern. This class represents a set of alternative production rules 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.

Version:
1.0
Author:
Per Cederberg,

Constructor Summary
ProductionPattern(int id, java.lang.String name)
          Creates a new production pattern.
 
Method Summary
 void addRule(ProductionPatternRule rule)
          Adds a production pattern rule.
 int getId()
          Returns the unique production pattern identity value.
 java.lang.String getName()
          Returns the production pattern name.
 ProductionPatternRule getRule(int pos)
          Returns a rule in this pattern.
 int getRuleCount()
          Returns the number of rules in this pattern.
 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 rules is left-recursive.

Returns:
true if at least one rule is left side 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 rules is right-recursive.

Returns:
true if at least one rule is right side 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 rules would match the empty token stream.

Returns:
true if at least one rule can match an empty stream, 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

getRuleCount

public int getRuleCount()
Returns the number of rules in this pattern.

Returns:
the number of rules in this pattern

getRule

public ProductionPatternRule getRule(int pos)
Returns a rule in this pattern.

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

addRule

public void addRule(ProductionPatternRule rule)
Adds a production pattern rule.

Parameters:
rule - the production pattern rule to add

toString

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

Overrides:
toString in class java.lang.Object
Returns:
a token string representation