|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.inxar.syntacs.grammar.context_free.CFGrammar
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 Item s 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 NonTerminal s in the grammar. |
int |
productions()
Returns the number of Production s in the grammar. |
void |
setStartProduction(Production startProduction)
Sets the start production to the given production. |
int |
terminals()
Returns the number of Terminal s in the grammar. |
String |
toString()
|
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public CFGrammar()
CFGrammar
.Method Detail |
public ContextFreeGrammar getContextFreeGrammar()
ContextFreeSet
ContextFreeGrammar
.getContextFreeGrammar
in interface ContextFreeSet
public Terminal newTerminal(Token type)
ContextFreeGrammar
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
Terminal
s based on token
s, 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 terminal
s). Thus, this
method is the compile-time link between the Lexer
and Parser
.newTerminal
in interface ContextFreeGrammar
public NonTerminal newNonTerminal(String name)
ContextFreeGrammar
NonTerminal
with the
given name.newNonTerminal
in interface ContextFreeGrammar
public Production newProduction(NonTerminal nonTerminal)
ContextFreeGrammar
Production
on the
given LHS NonTerminal
and predefined length.newProduction
in interface ContextFreeGrammar
public int terminals()
ContextFreeSet
Terminal
s in the grammar.terminals
in interface ContextFreeSet
public int nonTerminals()
ContextFreeSet
NonTerminal
s in the grammar.nonTerminals
in interface ContextFreeSet
public int productions()
ContextFreeSet
Production
s in the grammar.productions
in interface ContextFreeSet
public int items()
ContextFreeSet
Item
s in the grammar.items
in interface ContextFreeSet
public Epsilon getEpsilon()
ContextFreeGrammar
Epsilon
object if needed.getEpsilon
in interface ContextFreeGrammar
public Terminal getTerminal(int ID)
ContextFreeSet
Terminal
with the given id. If the id
is not known, implementations may either return
null
or throw a RuntimeException
.getTerminal
in interface ContextFreeSet
public NonTerminal getNonTerminal(int ID)
ContextFreeSet
NonTerminal
with the given id. If the
id is not known, implementations may either return
null
or throw a RuntimeException
.getNonTerminal
in interface ContextFreeSet
public GrammarSymbol getGrammarSymbol(int ID)
ContextFreeSet
GrammarSymbol
with the given id. If
the id is not known, implementations may either return
null
or throw a RuntimeException
.getGrammarSymbol
in interface ContextFreeSet
public Production getProduction(int ID)
ContextFreeSet
Production
with the given id. If the
id is not known, implementations may either return
null
or throw a RuntimeException
.getProduction
in interface ContextFreeSet
public Item getItem(int ID)
ContextFreeSet
Item
with the given id. If the id is
not known, implementations may either return null
or throw a RuntimeException
.getItem
in interface ContextFreeSet
public NonTerminal getNonTerminal(String name)
public Terminal getTerminal(String name)
public Enumeration getNonTerminals()
public Enumeration getTerminals()
public Enumeration getProductions()
public Production getStart()
ContextFreeSet
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'.getStart
in interface ContextFreeSet
public void setStartProduction(Production startProduction)
ContextFreeGrammar
setStartProduction
in interface ContextFreeGrammar
public ContextFreeSet compile()
ContextFreeGrammar
compile()
returns a
ContextFreeSet
object which can then be used to
construct a DPA
.compile
in interface ContextFreeGrammar
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |