|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object marf.nlp.Parsing.GrammarCompiler.Grammar
public class Grammar
Represents the language Grammar data structure. Encapsulates collections of terminals, non-terminals, and rules of the current grammar that can be serialized and reloaded on demand.
$Id: Grammar.java,v 1.22 2007/12/18 21:37:56 mokhov Exp $
Field Summary | |
---|---|
static java.lang.String |
DEFAULT_FIRST_SETS_FILE
Default filename to output first sets. |
static java.lang.String |
DEFAULT_FOLLOW_SETS_FILE
Default filename to output follow sets. |
static java.lang.String |
DEFAULT_RULES_FILE
Default filename to output rule productions. |
protected Terminal |
oEOFTerminal
A local EOF terminal reference. |
protected Terminal |
oEpsilonTerminal
The epsilon token. |
protected java.util.Vector |
oNonTerminalList
List of non-terminals. |
protected java.util.Vector |
oRules
A vector of rules. |
protected NonTerminal |
oStartNonTerminal
A reference to the starting state. |
protected java.util.Vector |
oTerminalList
List of terminals. |
private static long |
serialVersionUID
For serialization versioning. |
Constructor Summary | |
---|---|
Grammar()
Default constructor. |
Method Summary | |
---|---|
void |
addNonTeminal(NonTerminal poNonTerminal)
Adds non-terminal to the set of non-terminals. |
void |
addRule(Rule poRule)
Adds a grammar rule to the collection of rules. |
void |
addTeminal(Terminal poTerminal)
Adds a terminal to the set of terminals. |
void |
computeFirstSets()
Computes first sets for all non-terminals from the non-terminals list. |
void |
computeFollowSets()
Computes follow sets for all non-terminals from the non-terminals list. |
int |
contains(GrammarElement poGrammarElement)
Similarly to contains(String) looks up
the index of the specified grammar element. |
int |
contains(java.lang.String pstrName)
Checks whether a grammar element with a given name (lexeme) exists in the corresponding list or not. |
int |
containsNonTerminal(java.lang.String pstrName)
Checks whether the named non-terminal is contained in this grammar and gets its index. |
int |
containsTerminal(java.lang.String pstrName)
Checks whether the named terminal is contained in this grammar and gets its index. |
Terminal |
getEOFTerminal()
Allows querying for the current EOF terminal. |
Terminal |
getEpsilonTerminal()
Allows querying for the current epsilon terminal. |
static java.lang.String |
getMARFSourceCodeRevision()
Retrieves class' revision. |
java.util.Vector |
getNonTerminalList()
Allows querying for the collection of non-terminals of this grammar. |
Rule |
getRule(int piA,
int piB,
int piC)
Retrieves a grammar rule given the indices of the LHS non-terminal and two grammar elements on the RHS. |
Rule |
getRule(java.lang.String pstrTerminal,
int piNonTerminalIndex)
Allows querying for a grammar rule given the name of the terminal and the index of the non-terminal grammar elements. |
java.util.Vector |
getRules()
Allows querying for the collection of rules of this grammar. |
NonTerminal |
getStartNonTerminal()
Allows querying for the current starting non-terminal. |
java.util.Vector |
getTerminalList()
Allows querying for the collection of terminals of this grammar. |
boolean |
serialize(int piOperation)
Performs serialization of this grammar data structure. |
void |
setEOFTerminal(Terminal poTerminal)
Allows setting a new EOF terminal. |
void |
setEpsilonTerminal(Terminal poEpsilonTerminal)
Allows setting a new epsilon terminal. |
void |
setStartNonTerminal(NonTerminal poStartNonTerminal)
Allows setting a new starting non-terminal. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String DEFAULT_FIRST_SETS_FILE
public static final java.lang.String DEFAULT_FOLLOW_SETS_FILE
public static final java.lang.String DEFAULT_RULES_FILE
protected java.util.Vector oTerminalList
protected java.util.Vector oNonTerminalList
protected java.util.Vector oRules
protected Terminal oEOFTerminal
protected Terminal oEpsilonTerminal
protected NonTerminal oStartNonTerminal
private static final long serialVersionUID
serialver
tool that comes with JDK.
Constructor Detail |
---|
public Grammar()
Method Detail |
---|
public void computeFirstSets()
public void computeFollowSets() throws SyntaxError
SyntaxError
- if there is no starting non-terminalpublic int containsNonTerminal(java.lang.String pstrName)
pstrName
- the name of the non-terminal to look for
public int containsTerminal(java.lang.String pstrName)
pstrName
- the name of the terminal to look for
public int contains(java.lang.String pstrName)
pstrName
- the name of the grammar element to look for
public int contains(GrammarElement poGrammarElement)
contains(String)
looks up
the index of the specified grammar element.
poGrammarElement
- a grammar element to look up.
contains(String)
public final Rule getRule(java.lang.String pstrTerminal, int piNonTerminalIndex)
pstrTerminal
- the name of the terminalpiNonTerminalIndex
- the index of the non-terminal in the table
public final Rule getRule(int piA, int piB, int piC)
piA
- piB
- piC
-
java.lang.RuntimeException
- if the rule found is not in CNFpublic boolean serialize(int piOperation)
piOperation
- UNUSED; (usually 0 means load, 1 means save)
true
if successfulpublic void addTeminal(Terminal poTerminal)
poTerminal
- the terminal to add; must not be nullpublic void addNonTeminal(NonTerminal poNonTerminal)
poNonTerminal
- the non-terminal to add; must not be nullpublic void addRule(Rule poRule)
poRule
- the rule to add; must not be nullpublic Terminal getEOFTerminal()
public void setEOFTerminal(Terminal poTerminal)
poTerminal
- the terminal to become EOFpublic Terminal getEpsilonTerminal()
public void setEpsilonTerminal(Terminal poEpsilonTerminal)
poEpsilonTerminal
- the terminal to become epsilonpublic NonTerminal getStartNonTerminal()
public void setStartNonTerminal(NonTerminal poStartNonTerminal)
poStartNonTerminal
- the non-terminal to become the starting pointpublic final java.util.Vector getTerminalList()
public final java.util.Vector getNonTerminalList()
public final java.util.Vector getRules()
public static java.lang.String getMARFSourceCodeRevision()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |