public class GRForest
extends java.lang.Object
Each tree's root is stored in mmj.lang.Cnst.gRRoot(dot).
A tree contains every Notation Grammar Rule that begins with the gRRoot's Cnst. Each leaf node has a reference (pointer) to a sub-tree, and so on. This enables all Rules whose expressions begin with "(" to share a common root.
The purpose of GRForest and GRNode was to provide a searchable repository of
NotationRule information, and it is used for that purpose in
BottomUpParser
However, the Bottom Up algorithm is too inefficient
for Metamath's set.mm and has been "deprecated" (to put it politely), in
favor of EarleyParser
.
So, GRForest and GRNode are teetering on obsolescence and could be removed from without too much trouble. The only use for them still is checking for duplicate Rule expressions, and there is obviously a cheaper way to do that than with these things...(I'm guessing that since each GrammarRule carries its own expression that the hash code for each rule could be pre-computed and even stored, if desired, and then used as the key to a HashSet. Bada bing, bada boom.)
Therefore, I am not going to document these any further.
Constructor and Description |
---|
GRForest() |
Modifier and Type | Method and Description |
---|---|
static GRNode |
addNotationRule(Cnst[] ruleFormatExpr,
NotationRule notationRule)
get root, blow up if helpful to consistency;
find last element of input expr that has a node under the forest
root;
if last element of input expr is the final element of the array and
it already has a NotationRule return the found node -- but if the
NotationRule is null, update the rule with the input rule and return the
found node.
prepare a linked chain of all nodes that do not already exist and
splice them into the forest, returning the last node to the caller.
|
protected static GRNode |
addToTree(Cnst elementCnst,
GRNode oldRoot) |
static GRNode |
findCnstSubSeq(GRNode root,
Cnst[] ruleFormatExpr,
int seqNext,
int seqLast)
searches GrNode tree/subtree down through the "forest" of trees.
|
static NotationRule |
findLen1CnstNotationRule(GRNode root,
Cnst cnst)
searches GrNode tree for a length of 1 Notation Rule matching the input
Cnst.
|
static java.util.Collection<NotationRule> |
getRuleCollection(GRNode root) |
public static GRNode findCnstSubSeq(GRNode root, Cnst[] ruleFormatExpr, int seqNext, int seqLast)
root
- the root noderuleFormatExpr
- an array containing the sequence to search forseqNext
- the start index into ruleFormatExprseqLast
- the end index into ruleFormatExprnull
public static NotationRule findLen1CnstNotationRule(GRNode root, Cnst cnst)
root
- the root nodecnst
- the Cnst to search forpublic static GRNode addNotationRule(Cnst[] ruleFormatExpr, NotationRule notationRule)
ruleFormatExpr
- the expression to add.notationRule
- the NotationRule for the expressionprotected static GRNode addToTree(Cnst elementCnst, GRNode oldRoot) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public static java.util.Collection<NotationRule> getRuleCollection(GRNode root)