All Packages Class Hierarchy This Package Previous Next Index
Class javaParse.GrammarInfo
java.lang.Object
|
+----javaParse.GrammarInfo
- public class GrammarInfo
- extends Object
- implements Cloneable
allows users to add Productions as Strings and iterate over
them, get the Variables, and get the Terminals.
-
GrammarInfo()
- Allocates a new instance of class GrammarInfo.
-
addProduction(String)
-
-
clone()
- Creates a clone of the grammar.
-
currentLeftProd()
- Returns the current left side of the production.
-
currentProd()
- Returns the current production.
-
currentRightProd()
- Returns the current right side of the production.
-
currentVar()
-
-
firstProd()
- Set the class production index to the first production in the grammar.
-
firstVar()
- Set the class variable index to the start symbol
-
getNumProds()
-
-
getNumVars()
-
-
getRightProds()
-
-
getStartSymbol()
-
-
getTerminals()
-
-
getVariables()
-
-
hasStartProduction()
-
-
isGoodGrammarInfo()
-
-
isTerminal(char)
-
-
isUnrestricted()
-
-
isVariable(char)
-
-
leftProdAt(int)
-
-
nextProd()
- Increment the production to the next production.
-
nextVar()
- Increment the variable to the next one, interates
in alphabetical order, after starting with the Start Symbol
-
prodsAllAdded()
- lets the GrammarInfo organize itself, and sort everything since
no more prods can be added once Done is called
addProd does not check to see if this was called
thus, another call to addProd will mess up sorted order
that was previously guaranteed
-
prodsDone()
- Indicates if the production index is at the last production.
-
rightProdAt(int)
-
-
varsDone()
-
GrammarInfo
public GrammarInfo()
- Allocates a new instance of class GrammarInfo.
clone
public Object clone()
- Creates a clone of the grammar.
- Overrides:
- clone in class Object
prodsAllAdded
public void prodsAllAdded()
- lets the GrammarInfo organize itself, and sort everything since
no more prods can be added once Done is called
addProd does not check to see if this was called
thus, another call to addProd will mess up sorted order
that was previously guaranteed
isGoodGrammarInfo
public boolean isGoodGrammarInfo()
- Returns:
- s true if all productions produce a good GrammarInfo such that
every variable begins its own production and every variable
is also on the right hand side of the production
Only the start symbol is allowed to appear on one side of Prod
addProduction
public boolean addProduction(String prod)
- Parameters:
- p - production to be added for exp, "S->aSb"
- Returns:
- true if it adds valid production to the grammar.
firstProd
public void firstProd()
- Set the class production index to the first production in the grammar.
firstVar
public void firstVar()
- Set the class variable index to the start symbol
nextProd
public void nextProd()
- Increment the production to the next production.
nextVar
public void nextVar()
- Increment the variable to the next one, interates
in alphabetical order, after starting with the Start Symbol
currentLeftProd
public String currentLeftProd()
- Returns the current left side of the production.
currentRightProd
public String currentRightProd()
- Returns the current right side of the production.
currentProd
public String currentProd()
- Returns the current production.
currentVar
public String currentVar()
- Returns:
- the current variable
prodsDone
public boolean prodsDone()
- Indicates if the production index is at the last production.
varsDone
public boolean varsDone()
- Returns:
- true if the last variable has already been touched
leftProdAt
public String leftProdAt(int pos)
- Parameters:
- pos - the index in the String 1 < pos <= TotalNumberOfProductions
- Returns:
- the left side Production in the Grammar
Note: used for LR
rightProdAt
public String rightProdAt(int pos)
- Parameters:
- pos - the index in the String 1 < pos <=hTotalNumberOfProductions
- Returns:
- the right side of the production at a certain pos
Used for LR
getStartSymbol
public String getStartSymbol()
- Returns:
- the start symbol for the grammar
getNumProds
public int getNumProds()
- Returns:
- the number of productions in the grammar
getNumVars
public int getNumVars()
- Returns:
- the number of different variables in the grammar
getVariables
public String[] getVariables()
- Returns:
- String[] of Variables such that the first
element is the starting variable and the rest
are all alphabetized: "A" - "Z" is a variable
getRightProds
public String[] getRightProds()
- Returns:
- a String[] containing the Rhs
of the grammar in the original order
getTerminals
public Vector getTerminals()
- Returns:
- a sorted Vector of terminals
where a terminal is "a"- "z" and other misc terminal chars
hasStartProduction
public boolean hasStartProduction()
- Returns:
- true if S-> has been added somewhere to the GrammarInfo
isUnrestricted
public boolean isUnrestricted()
- Returns:
- true if the grammar is unrestricted
isTerminal
public boolean isTerminal(char c)
- Returns:
- true if c is a Terminal (even if it is not a Terminal
in this GrammarInfo)
isVariable
public static boolean isVariable(char c)
- Returns:
- true if c is a Variable (even of it is not a Variable
in this GrammarInfo
All Packages Class Hierarchy This Package Previous Next Index