torero.model
Class Grammar

java.lang.Object
  |
  +--torero.model.Grammar
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AttributeGrammar

public class Grammar
extends Object
implements Serializable

This class represents a complete Grammar consisting of Symbols, Productions (Rules) and a Start Symbol. It has some Methods to build a full Grammar step-by-step. This methods a mainly called by the yacc file parser.

See Also:
Serialized Form

Field Summary
 AdditionalGrammarInfo addinfo
           
 
Constructor Summary
Grammar()
          This is an ordinary constructor to get a new instance of an empty Grammar.
 
Method Summary
 void addProduction(String LHSString, String[] RHSStrings, String PrecString)
          This method allows to add a new Production to the grammar.
 void declareLiteral(String literal)
          A new Literal (Token Symbol) is created and added to the SymbolMap.
 void declareLiteral(String literal, int toknum)
          A new Literal (Token Symbol) is created and added to the SymbolMap.
 void declareLiteral(String literal, String assocType, int precLevel)
          A new Literal (Token Symbol) is created and added to the SymbolMap.
 void declareLiteral(String literal, String assocType, int precLevel, int toknum)
          A new Literal (Token Symbol) is created and added to the SymbolMap.
 void declareStartSymbol(String ssymbol)
          Use this method to define the Start Symbol for the Grammar (it's created as NonTerm).
 void declareToken(String token)
          A new Token Symbol is created and added to the SymbolMap.
 void declareToken(String token, int toknum)
          A new Token Symbol is created and added to the SymbolMap.
 void declareToken(String token, String assocType, int precLevel)
          A new Token Symbol is created and added to the SymbolMap.
 void declareToken(String token, String assocType, int precLevel, int toknum)
          A new Token Symbol is created and added to the SymbolMap.
 ProductionMap getProductionMap()
          Returns the ProductionMap that contains all Productions defined in this Grammar.
 Nonterm getStartSymbol()
          Returns the Start Symbol of this Grammar.
 SymbolMap getSymbolMap()
          Returns the SymbolMap that contains all Symbols defined in this Grammar.
 String toString()
          Returns a String Representation of this grammar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

addinfo

public AdditionalGrammarInfo addinfo
Constructor Detail

Grammar

public Grammar()
This is an ordinary constructor to get a new instance of an empty Grammar.
Method Detail

declareToken

public void declareToken(String token)
A new Token Symbol is created and added to the SymbolMap.
Parameters:
token - takes the name of the token that will be created

declareLiteral

public void declareLiteral(String literal)
A new Literal (Token Symbol) is created and added to the SymbolMap.
Parameters:
literal - takes the name of the Token that will be created - the name is also used as word expression of the Token

declareToken

public void declareToken(String token,
                         String assocType,
                         int precLevel)
A new Token Symbol is created and added to the SymbolMap.
Parameters:
token - takes the name of the token that will be created
assocType - takes the Association Type for the Symbol (Yacc Specific)
precLevel - takes the Precedence Level for the Symbol (Yacc Specific)

declareLiteral

public void declareLiteral(String literal,
                           String assocType,
                           int precLevel)
A new Literal (Token Symbol) is created and added to the SymbolMap.
Parameters:
literal - takes the name of the Token that will be created - the name is also used as word expression of the Token
assocType - takes the Association Type for the Symbol (Yacc Specific)
precLevel - takes the Precedence Level for the Symbol (Yacc Specific)

declareToken

public void declareToken(String token,
                         int toknum)
A new Token Symbol is created and added to the SymbolMap.
Parameters:
token - takes the name of the token that will be created
toknum - takes the Token Number for the Symbol (Yacc Specific)

declareLiteral

public void declareLiteral(String literal,
                           int toknum)
A new Literal (Token Symbol) is created and added to the SymbolMap.
Parameters:
literal - takes the name of the Token that will be created - the name is also used as word expression of the Token
toknum - takes the Token Number for the Symbol (Yacc Specific)

declareToken

public void declareToken(String token,
                         String assocType,
                         int precLevel,
                         int toknum)
A new Token Symbol is created and added to the SymbolMap.
Parameters:
token - takes the name of the token that will be created
assocType - takes the Association Type for the Symbol (Yacc Specific)
precLevel - takes the Precedence Level for the Symbol (Yacc Specific)
toknum - takes the Token Number for the Symbol (Yacc Specific)

declareLiteral

public void declareLiteral(String literal,
                           String assocType,
                           int precLevel,
                           int toknum)
A new Literal (Token Symbol) is created and added to the SymbolMap.
Parameters:
literal - takes the name of the Token that will be created - the name is also used as word expression of the Token
assocType - takes the Association Type for the Symbol (Yacc Specific)
precLevel - takes the Precedence Level for the Symbol (Yacc Specific)
toknum - takes the Token Number for the Symbol (Yacc Specific)

declareStartSymbol

public void declareStartSymbol(String ssymbol)
Use this method to define the Start Symbol for the Grammar (it's created as NonTerm).

getStartSymbol

public Nonterm getStartSymbol()
Returns the Start Symbol of this Grammar.
Returns:
returns the Start Symbol of this Grammar

getProductionMap

public ProductionMap getProductionMap()
Returns the ProductionMap that contains all Productions defined in this Grammar.
Returns:
returns the ProductionMap that contains all Productions defined in this Grammar

getSymbolMap

public SymbolMap getSymbolMap()
Returns the SymbolMap that contains all Symbols defined in this Grammar.
Returns:
returns the SymbolMap that contains all Symbols defined in this Grammar

addProduction

public void addProduction(String LHSString,
                          String[] RHSStrings,
                          String PrecString)
This method allows to add a new Production to the grammar.
Parameters:
LHSString - takes the name of the LHS Symbol of the new Production (if not already done also a Nonterm Symbol is created)
RHSStrings - takes a String Array that contains the names of the RHS Symbols - an empty Array causes Epsilon as RHS (creating Nonterm Symbols for not previously defined Symbols is the default)
PrecString - takes null or the name of the precedence token (yacc specific extension)

toString

public String toString()
Returns a String Representation of this grammar.
Overrides:
toString in class Object
Returns:
returns a String Representation of this grammar