torero.model
Class Symbol

java.lang.Object
  |
  +--torero.model.Symbol
All Implemented Interfaces:
Comparable, Serializable
Direct Known Subclasses:
Epsilon, Nonterm, Token

public abstract class Symbol
extends Object
implements Comparable, Serializable

The Symbol Object is the base class for Token, Nonterm and Epsilon in Toreros Attribute Grammar Model. This Class encapsulates the general properties of symbols used in grammars. Symbols have a unique name and the capability to have Attributes (in terms of Attribute Grammars) assigned to it. Symbol Instances should be obtained via the SymbolMap that can guarantee their uniqueness. Additionally it redefines the equals and compareTo Operator for maintainig a well defined sort order and the uniqueness in java collection classes.

See Also:
AttributeGrammar, SymbolMap, Serialized Form

Constructor Summary
protected Symbol(String Name, SymbolMap k)
          This constuctor should not be called directly.
 
Method Summary
 boolean addAttribute(Attribute anAttribute)
          This method is used to add Attributes to this Symbol.
 void changeName(String name)
          This is a save method to change a Symbol name.
 int compareTo(Object o)
          Reimplemtented for a well defined sort order of Symbol objects.
 boolean equals(Object o)
          Reimplemtented for a uniqueness based on the symbols field name.
 int getAttributePos(Attribute atr)
          This method returns the position of the given Attribute in the symbols set of attributes.
 Object[] getAttributes()
          This method returns the Attributes of the Symbol as Array.
 int getAttributesSize()
          This method returns the Number of Attributes the Symbol has.
 String getName()
          Returns the Name of the Symbol and takes care of escaped characters.
 String getStringRep()
          Returns a String Representation of this Symbol including its attributes.
 boolean hasAttribute(Attribute attrib)
          This method is used to check if the Symbol contains the given Attribute.
 boolean isEpsilon()
          Is it the Epsilon Symbol ?
 boolean isLeaf()
          Is this Symbol a leaf ?
 boolean isLiteral()
          Is it a Literal Symbol ?
 void removeAttribute(Attribute anAttribute)
          This method is used to remove Attributes to this Symbol.
 String toDot()
          Returns the Dot Graph Representation of this Symbol.
 StringBuffer toOx(StringBuffer sb)
          It writes the Ox Representation of this Symbol on the given StringBuffer.
 StringBuffer toOxDecl(StringBuffer sb)
          It writes the Ox Declaration Section Representation of this Symbol on the given StringBuffer.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Symbol

protected Symbol(String Name,
                 SymbolMap k)
This constuctor should not be called directly. To get an instance of a Symbol use the SymbolMap class.
Method Detail

getName

public String getName()
Returns the Name of the Symbol and takes care of escaped characters.
Returns:
It returns the Name of the Symbol and takes care of escaped characters

getStringRep

public String getStringRep()
Returns a String Representation of this Symbol including its attributes.
Returns:
It returns a String Representation of this Symbol including its attributes

toOx

public StringBuffer toOx(StringBuffer sb)
It writes the Ox Representation of this Symbol on the given StringBuffer.
Parameters:
sb - the StringBuffer to write onto

toOxDecl

public StringBuffer toOxDecl(StringBuffer sb)
It writes the Ox Declaration Section Representation of this Symbol on the given StringBuffer.
Parameters:
sb - the StringBuffer to write onto

toDot

public String toDot()
Returns the Dot Graph Representation of this Symbol.
Returns:
It returns the Dot Graph Representation of this Symbol

changeName

public void changeName(String name)
                throws SymbolNameException
This is a save method to change a Symbol name. It takes care of unique Symbol names.
Parameters:
name - the new name for this Symbol

addAttribute

public boolean addAttribute(Attribute anAttribute)
This method is used to add Attributes to this Symbol.

hasAttribute

public boolean hasAttribute(Attribute attrib)
This method is used to check if the Symbol contains the given Attribute.

removeAttribute

public void removeAttribute(Attribute anAttribute)
This method is used to remove Attributes to this Symbol.

getAttributes

public Object[] getAttributes()
This method returns the Attributes of the Symbol as Array.
Returns:
array of Objects(Attributes)

getAttributesSize

public int getAttributesSize()
This method returns the Number of Attributes the Symbol has.
Returns:
number of attributes assigned to the symbol

getAttributePos

public int getAttributePos(Attribute atr)
This method returns the position of the given Attribute in the symbols set of attributes. If it doesn't contain the given Attribute it returns -1.
Returns:
attribute position or -1

isLeaf

public boolean isLeaf()
Is this Symbol a leaf ? In terms of Grammars "Is it a Terminal Symbol ?"

isLiteral

public boolean isLiteral()
Is it a Literal Symbol ? (implies being a Leaf)

isEpsilon

public boolean isEpsilon()
Is it the Epsilon Symbol ? (a Terminal Symbol that stands for no characters)

compareTo

public int compareTo(Object o)
Reimplemtented for a well defined sort order of Symbol objects.
Specified by:
compareTo in interface Comparable

equals

public boolean equals(Object o)
Reimplemtented for a uniqueness based on the symbols field name.
Overrides:
equals in class Object