org.inxar.syntacs.grammar.context_free
Interface ContextFreeGrammar

All Known Implementing Classes:
CFGrammar

public interface ContextFreeGrammar

The ContextFreeGrammar interface is a factory for assembling context free grammars, analogous to the RegularGrammar interface. Each newXXX method allocates and returns a construct used in defining context free grammars. When complete, the ContextFreeSet object is obtained via the compile() method, which compiles the state of the grammar into a form more amenable to set operations (which are generally implemented using bit vectors).


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.
 Epsilon getEpsilon()
          Returns the Epsilon object if needed.
 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.
 void setStartProduction(Production start)
          Sets the start production to the given production.
 

Method Detail

newTerminal

public Terminal newTerminal(Token type)
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.

newNonTerminal

public NonTerminal newNonTerminal(String name)
Allocates and returns a new NonTerminal with the given name.

newProduction

public Production newProduction(NonTerminal nonTerminal)
Allocates and returns a new Production on the given LHS NonTerminal and predefined length.

getEpsilon

public Epsilon getEpsilon()
Returns the Epsilon object if needed.

setStartProduction

public void setStartProduction(Production start)
Sets the start production to the given production.

compile

public 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.