marf.nlp.Parsing.GrammarCompiler
Class GrammarElement

java.lang.Object
  extended by marf.nlp.Parsing.GrammarCompiler.GrammarElement
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
NonTerminal, SemanticToken, Terminal

public abstract class GrammarElement
extends java.lang.Object
implements java.io.Serializable

Generic grammar token that must be subclassed.

$Id: GrammarElement.java,v 1.12 2008/02/17 02:23:28 mokhov Exp $

Since:
0.3.0.2
Version:
$Revision: 1.12 $
Author:
Serguei Mokhov
See Also:
Serialized Form

Field Summary
protected  int iID
          ID to act as an index to table.
protected  java.util.Vector oFirstSet
          FirstSet of us.
protected  Token oToken
          A bit extra info in the encapsulated token.
protected  java.lang.String strName
          A name of a token to refer to.
 
Constructor Summary
protected GrammarElement(java.lang.String pstrName, int piID)
          Constructor by name; inner token is set to null.
protected GrammarElement(Token poToken, int piID)
          Preferred Constructor.
 
Method Summary
 boolean addToFirstSet(NonTerminal poNonTerminal)
          Adds a single non-terminal to the first set.
 boolean addToFirstSet(Terminal poTerminal)
          Adds a single terminal to the first set if it's not already there.
 boolean addToFirstSet(java.util.Vector poSet)
          Appends elements from the passed set to its current first set.
 java.util.Vector getFirstSet()
          Allows getting the first set of this grammar element.
 int getID()
          Allows querying this element's ID.
static java.lang.String getMARFSourceCodeRevision()
          Retrieves class' revision.
 java.lang.String getName()
          Allows querying this element's name.
 Token getToken()
          Allows querying this element's enclosed token.
 boolean isEqualByName(java.lang.String pstrName)
          Tests whether the parameter is equal to the internal name of the grammar element.
abstract  boolean isNonTerminal()
          Allows querying this grammar element for non-terminality.
abstract  boolean isTerminal()
          Allows querying this grammar element for terminality.
 java.lang.String toString()
          Overridden to return the grammar element's name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

strName

protected java.lang.String strName
A name of a token to refer to.


iID

protected int iID
ID to act as an index to table.


oToken

protected Token oToken
A bit extra info in the encapsulated token.


oFirstSet

protected java.util.Vector oFirstSet
FirstSet of us.

Constructor Detail

GrammarElement

protected GrammarElement(Token poToken,
                         int piID)
Preferred Constructor.

Parameters:
poToken - token corresponding to this grammar element
piID - element's ID

GrammarElement

protected GrammarElement(java.lang.String pstrName,
                         int piID)
Constructor by name; inner token is set to null.

Parameters:
pstrName - name of the grammar element
piID - element's ID
Method Detail

isTerminal

public abstract boolean isTerminal()
Allows querying this grammar element for terminality.

Returns:
true if this grammar element is a terminal

isNonTerminal

public abstract boolean isNonTerminal()
Allows querying this grammar element for non-terminality.

Returns:
true if this grammar element is a non-terminal

getID

public final int getID()
Allows querying this element's ID.

Returns:
the ID

getName

public final java.lang.String getName()
Allows querying this element's name.

Returns:
the name

getToken

public final Token getToken()
Allows querying this element's enclosed token.

Returns:
the token

addToFirstSet

public boolean addToFirstSet(java.util.Vector poSet)
Appends elements from the passed set to its current first set. Duplicates will not be added.

Parameters:
poSet - collection of grammar elements to add to the first set
Returns:
true if the underlying first set has change as a result of operation.

addToFirstSet

public boolean addToFirstSet(Terminal poTerminal)
Adds a single terminal to the first set if it's not already there.

Parameters:
poTerminal - the terminal element to add
Returns:
true if the terminal was added

addToFirstSet

public boolean addToFirstSet(NonTerminal poNonTerminal)
Adds a single non-terminal to the first set.

Parameters:
poNonTerminal - the non-terminal element to add
Returns:
true if the non-terminal was added

getFirstSet

public java.util.Vector getFirstSet()
Allows getting the first set of this grammar element.

Returns:
the first set of this element

toString

public java.lang.String toString()
Overridden to return the grammar element's name.

Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

isEqualByName

public boolean isEqualByName(java.lang.String pstrName)
Tests whether the parameter is equal to the internal name of the grammar element.

Parameters:
pstrName - name to test
Returns:
true if the names are equal

getMARFSourceCodeRevision

public static java.lang.String getMARFSourceCodeRevision()
Retrieves class' revision.

Returns:
revision string


SourceForge Logo