public class ParseNodeHolder
extends java.lang.Object
The idea is that an Expression to be parsed can be rewritten as an array of ParseNodeHolders, with the original Sym's stored in ParseNodeHolder.mObj. Then The Var's can be replaced with their VarHyp's, with mObj set to the VarHyp and also stored in parseNode. Subsequently the array of ParseNodeHolders can be rewritten, and rewritten until, at last, every mObj containing a Cnst has been parsed -- and there is only one item in the array whose parseNode is the root of a parse tree.
Anyway, ParseNodeHolder is very popular in mmj.verify. Grammar. Many uses! Haha.
In EarleyParser the need arose to maintain a linked list of ParseNodeHolders instead of an array, so, what the heck, twinFwd and twinBwd were added (I was so happy, why not!) The problem was that in an ambiguous grammar, many valid parse trees can exist, and you don't know where you will first notice them; they might be found at a bottom sub-tree and then propagate upward. So, infinite parse trees are feasible, thanks to adding linked lists of' ParseNodeHolder. <:-)
Modifier and Type | Field and Description |
---|---|
ParseNodeHolder |
bwd
Backward reference in chain of ParseNodeHolders.
|
ParseNodeHolder |
fwd
Forward reference in chain of ParseNodeHolders.
|
MObj |
mObj
mObj contains either a Cnst, a Var or a Stmt.
|
ParseNode |
parseNode
ParseNode associated with mObj, may be null.
|
Constructor and Description |
---|
ParseNodeHolder()
Default constructor.
|
ParseNodeHolder(Cnst cnst)
Constructor -- input is Cnst, so no ParseNode available, just load the
MObj for use in ParseTree generation...
|
ParseNodeHolder(ParseNode parseNode)
Constructor -- input is a ParseNode, so derive MObj from the input
ParseNode.stmt.
|
ParseNodeHolder(VarHyp varHyp)
Constructor -- input is VarHyp so create default VarHyp ParseNode.
|
Modifier and Type | Method and Description |
---|---|
void |
addToTwinChain(ParseNodeHolder x)
Add a node to a ParseNodeHolder's twin chain.
|
static Cnst[] |
buildRuleFormatExpr(ParseNodeHolder[] parseNodeHolderExpr)
A tedious conversion.
|
java.lang.String |
dumpTwinChainToString()
Copy "twin chain" to string for diagnostic use.
|
java.lang.String |
getCnstIdOrLabel()
return Cnst or Label of ParseNode.stmt.
|
Cnst |
getCnstOrTyp()
return Cnst or Type Code of ParseNode.stmt.
|
void |
initTwinChain()
Init twin chain, first node points to itself.
|
java.lang.String |
toString() |
public MObj mObj
public ParseNode parseNode
public ParseNodeHolder fwd
public ParseNodeHolder bwd
public ParseNodeHolder()
public ParseNodeHolder(ParseNode parseNode)
parseNode
- the input ParseNodepublic ParseNodeHolder(Cnst cnst)
cnst
- the input Cnstpublic ParseNodeHolder(VarHyp varHyp)
varHyp
- the input VarHyppublic static Cnst[] buildRuleFormatExpr(ParseNodeHolder[] parseNodeHolderExpr)
Converts to "ruleFormatExpr" -- each item in the Cnst array is a grammaticl Type Code or a Cnst.
parseNodeHolderExpr
- array of ParseNodeHolder.public Cnst getCnstOrTyp()
If mObj is a Cnst, return it, otherwise return the Type Code of parseNode.
public java.lang.String getCnstIdOrLabel()
public java.lang.String dumpTwinChainToString()
public void initTwinChain()
public void addToTwinChain(ParseNodeHolder x)
Inserts at the front of the list.
x
- the node to addpublic java.lang.String toString()
toString
in class java.lang.Object