com.inxar.syntacs.grammar.context_free
Class CFGrammar

java.lang.Object
  |
  +--com.inxar.syntacs.grammar.context_free.CFGrammar
All Implemented Interfaces:
ContextFreeGrammar, ContextFreeSet

public class CFGrammar
extends Object
implements ContextFreeGrammar, ContextFreeSet

Standard ContextFreeGrammar implementation.


Constructor Summary
CFGrammar()
          Constructs the CFGrammar.
 
Method Summary
 ContextFreeSet compile()
          When the construction and setup of the context free language elements is complete, compile() returns a ContextFreeSet object which can then be used to construct a DPA.
 ContextFreeGrammar getContextFreeGrammar()
          Returns the parent ContextFreeGrammar.
 Epsilon getEpsilon()
          Returns the Epsilon object if needed.
 GrammarSymbol getGrammarSymbol(int ID)
          Returns the GrammarSymbol with the given id.
 Item getItem(int ID)
          Returns the Item with the given id.
 NonTerminal getNonTerminal(int ID)
          Returns the NonTerminal with the given id.
 NonTerminal getNonTerminal(String name)
           
 Enumeration getNonTerminals()
           
 Production getProduction(int ID)
          Returns the Production with the given id.
 Enumeration getProductions()
           
 Production getStart()
          Returns the Production designated as the start.
 Terminal getTerminal(int ID)
          Returns the Terminal with the given id.
 Terminal getTerminal(String name)
           
 Enumeration getTerminals()
           
 int items()
          Returns the number of Items in the grammar.
 NonTerminal newNonTerminal(String name)
          Allocates and returns a new NonTerminal with the given name.
 Production newProduction(NonTerminal nonTerminal)
          Allocates and returns a new Production on the given LHS NonTerminal and predefined length.
 Terminal newTerminal(Token type)
          Allocates and returns a new Terminal based on the given Token.
 int nonTerminals()
          Returns the number of NonTerminals in the grammar.
 int productions()
          Returns the number of Productions in the grammar.
 void setStartProduction(Production startProduction)
          Sets the start production to the given production.
 int terminals()
          Returns the number of Terminals in the grammar.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CFGrammar

public CFGrammar()
Constructs the CFGrammar.
Method Detail

getContextFreeGrammar

public ContextFreeGrammar getContextFreeGrammar()
Description copied from interface: ContextFreeSet
Returns the parent ContextFreeGrammar.
Specified by:
getContextFreeGrammar in interface ContextFreeSet

newTerminal

public Terminal newTerminal(Token type)
Description copied from interface: ContextFreeGrammar
Allocates and returns a new Terminal based on the given Token. This method is pragmatically particularly important for the following reason: One generally defines a Lexer using a RegularGrammar and a Parser with a ContextFreeGrammar. By defining our Terminals based on tokens, the link from the Lexer to the Parser is made. In other words, the output of a Lexer (token based in the regular grammar) forms the input for the Parser (as terminals). Thus, this method is the compile-time link between the Lexer and Parser.
Specified by:
newTerminal in interface ContextFreeGrammar

newNonTerminal

public NonTerminal newNonTerminal(String name)
Description copied from interface: ContextFreeGrammar
Allocates and returns a new NonTerminal with the given name.
Specified by:
newNonTerminal in interface ContextFreeGrammar

newProduction

public Production newProduction(NonTerminal nonTerminal)
Description copied from interface: ContextFreeGrammar
Allocates and returns a new Production on the given LHS NonTerminal and predefined length.
Specified by:
newProduction in interface ContextFreeGrammar

terminals

public int terminals()
Description copied from interface: ContextFreeSet
Returns the number of Terminals in the grammar.
Specified by:
terminals in interface ContextFreeSet

nonTerminals

public int nonTerminals()
Description copied from interface: ContextFreeSet
Returns the number of NonTerminals in the grammar.
Specified by:
nonTerminals in interface ContextFreeSet

productions

public int productions()
Description copied from interface: ContextFreeSet
Returns the number of Productions in the grammar.
Specified by:
productions in interface ContextFreeSet

items

public int items()
Description copied from interface: ContextFreeSet
Returns the number of Items in the grammar.
Specified by:
items in interface ContextFreeSet

getEpsilon

public Epsilon getEpsilon()
Description copied from interface: ContextFreeGrammar
Returns the Epsilon object if needed.
Specified by:
getEpsilon in interface ContextFreeGrammar

getTerminal

public Terminal getTerminal(int ID)
Description copied from interface: ContextFreeSet
Returns the Terminal with the given id. If the id is not known, implementations may either return null or throw a RuntimeException.
Specified by:
getTerminal in interface ContextFreeSet

getNonTerminal

public NonTerminal getNonTerminal(int ID)
Description copied from interface: ContextFreeSet
Returns the NonTerminal with the given id. If the id is not known, implementations may either return null or throw a RuntimeException.
Specified by:
getNonTerminal in interface ContextFreeSet

getGrammarSymbol

public GrammarSymbol getGrammarSymbol(int ID)
Description copied from interface: ContextFreeSet
Returns the GrammarSymbol with the given id. If the id is not known, implementations may either return null or throw a RuntimeException.
Specified by:
getGrammarSymbol in interface ContextFreeSet

getProduction

public Production getProduction(int ID)
Description copied from interface: ContextFreeSet
Returns the Production with the given id. If the id is not known, implementations may either return null or throw a RuntimeException.
Specified by:
getProduction in interface ContextFreeSet

getItem

public Item getItem(int ID)
Description copied from interface: ContextFreeSet
Returns the Item with the given id. If the id is not known, implementations may either return null or throw a RuntimeException.
Specified by:
getItem in interface ContextFreeSet

getNonTerminal

public NonTerminal getNonTerminal(String name)

getTerminal

public Terminal getTerminal(String name)

getNonTerminals

public Enumeration getNonTerminals()

getTerminals

public Enumeration getTerminals()

getProductions

public Enumeration getProductions()

getStart

public Production getStart()
Description copied from interface: ContextFreeSet
Returns the Production designated as the start. Note that this production is generally not the same as the one given in ContextFreeLanguage.toGrammar(Production), as the start Production is typically 'augmented'.
Specified by:
getStart in interface ContextFreeSet

setStartProduction

public void setStartProduction(Production startProduction)
Description copied from interface: ContextFreeGrammar
Sets the start production to the given production.
Specified by:
setStartProduction in interface ContextFreeGrammar

compile

public ContextFreeSet compile()
Description copied from interface: ContextFreeGrammar
When the construction and setup of the context free language elements is complete, compile() returns a ContextFreeSet object which can then be used to construct a DPA.
Specified by:
compile in interface ContextFreeGrammar

toString

public String toString()
Overrides:
toString in class Object