public bool Equals(MultiState <SYMBOL_ENUM, TREE_NODE> comp) { if (Object.ReferenceEquals(comp, null)) { return(false); } if (Object.ReferenceEquals(this, comp)) { return(true); } return(items.SetEquals(comp.items)); }
internal bool Merge(MultiState <SYMBOL_ENUM, TREE_NODE> incomingState, Dictionary <Production <SYMBOL_ENUM, TREE_NODE>, Dictionary <int, SymbolChunkSet <SYMBOL_ENUM> > > precomputedRhsFirsts, int lookaheadWidth) { bool changed = false; itemsLookaheadsStamp = Math.Max(itemsLookaheadsStamp, incomingState.itemsLookaheadsStamp); // merge shifts foreach (SingleState <SYMBOL_ENUM, TREE_NODE> existing_state in this.items) { if (existing_state.Merge(incomingState.items.GetValue(existing_state), timeStamp)) { changed = true; } } addClosuresLookaheads(precomputedRhsFirsts, lookaheadWidth); return(changed); }
internal bool CanBeMerged(MultiState <SYMBOL_ENUM, TREE_NODE> newState) { // todo: comparer can be improved -- unseen terminals here can be considered as equal // however this means the merge can increase the number of stored items // and this means that after merge new shift moves should be created for added items // ERROR WARNING // this migh be not 100% correct, consider such mergers // expr -> PLUS . expr { func1 }; // expr -> MINUS . expr { func1 }; // same function // against // expr -> MUL . expr { func2 }; // normaly we would like to set precedence between MINUS, PLUS and MUL // but because MINUS and PLUS are merged, we have only MINUS-MUL precedence conflict // we rely on the fact func1 is the same, BUT it is a fragile assumption // pay attention when facing strange behaviour if such merger (which is my own idea) still makes sense // the cores are different if (!items.SetEquals(newState.items)) // [@STATE_EQ] { return(false); } // check by lookahead (the input which triggers the action) if there are no conflicts on actions foreach (SymbolChunk <SYMBOL_ENUM> lookahead in this.reduceLookaheads().Concat(newState.reduceLookaheads()).Distinct()) { // [@STATE_EQ] var this_reduces = this.reduceStatesByLookahead(lookahead).ToHashSet(stateComparer); var comp_reduces = newState.reduceStatesByLookahead(lookahead).ToHashSet(stateComparer); if (this_reduces.Count + comp_reduces.Count > 1 && !this_reduces.SetEquals(comp_reduces)) { return(false); } } return(true); }
public Node(MultiState <SYMBOL_ENUM, TREE_NODE> state) { State = state; EdgesTo = new Dictionary <SYMBOL_ENUM, Node <SYMBOL_ENUM, TREE_NODE> >(); sources = new HashSet <Tuple <SYMBOL_ENUM, Node <SYMBOL_ENUM, TREE_NODE> > >(); }
internal Node <SYMBOL_ENUM, TREE_NODE> Find(MultiState <SYMBOL_ENUM, TREE_NODE> state) { return(nodes.SingleOrDefault(it => it.State.Equals(state))); }