diff --git a/lib/jison.js b/lib/jison.js index 789307f6e..066b096f9 100755 --- a/lib/jison.js +++ b/lib/jison.js @@ -722,27 +722,32 @@ lrGeneratorMixin.gotoOperation = function gotoOperation (itemSet, symbol) { } }); - return gotoSet.isEmpty() ? gotoSet : this.closureOperation(gotoSet); + return gotoSet; }; /* Create unique set of item sets * */ lrGeneratorMixin.canonicalCollection = function canonicalCollection () { var item1 = new this.Item(this.productions[0], 0, [this.EOF]); - var firstState = this.closureOperation(new this.ItemSet(item1)), + var firstStateNoClosure = new this.ItemSet(item1), + firstState = this.closureOperation(firstStateNoClosure), states = new Set(firstState), marked = 0, self = this, - itemSet; + itemSet, + markedSymbols; states.has = {}; - states.has[firstState] = 0; + states.has[firstStateNoClosure.valueOf()] = 0; while (marked !== states.size()) { itemSet = states.item(marked); marked++; + markedSymbols = {}; itemSet.forEach(function CC_itemSet_forEach (item) { - if (item.markedSymbol && item.markedSymbol !== self.EOF) + if (item.markedSymbol && !markedSymbols[item.markedSymbol] && item.markedSymbol !== self.EOF){ + markedSymbols[item.markedSymbol] = true; self.canonicalCollectionInsert(item.markedSymbol, itemSet, states, marked-1); + } }); } @@ -751,21 +756,22 @@ lrGeneratorMixin.canonicalCollection = function canonicalCollection () { // Pushes a unique state into the que. Some parsing algorithms may perform additional operations lrGeneratorMixin.canonicalCollectionInsert = function canonicalCollectionInsert (symbol, itemSet, states, stateNum) { - var g = this.gotoOperation(itemSet, symbol); - if (!g.predecessors) - g.predecessors = {}; - // add g to que if not empty or duplicate - if (!g.isEmpty()) { - var gv = g.valueOf(), - i = states.has[gv]; - if (i === -1 || typeof i === 'undefined') { - states.has[gv] = states.size(); + var g = this.gotoOperation(itemSet, symbol), + state = states.has[g.valueOf()]; + + if(state !== undefined){ + itemSet.edges[symbol] = state; // store goto transition for table + states.item(state).predecessors[symbol].push(stateNum); + }else{ + // add g to que if not empty or duplicate + if (!g.isEmpty()) { + states.has[g.valueOf()] = states.size(); + g = this.closureOperation(g); + if (!g.predecessors) + g.predecessors = {}; itemSet.edges[symbol] = states.size(); // store goto transition for table states.push(g); g.predecessors[symbol] = [stateNum]; - } else { - itemSet.edges[symbol] = i; // store goto transition for table - states.item(i).predecessors[symbol].push(stateNum); } } }; diff --git a/package.json b/package.json index e04ad7504..6cf63db02 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Zach Carter (http://zaa.ch)", "name": "jison", "description": "A parser generator with Bison's API", - "version": "0.4.15", + "version": "0.4.16", "keywords": [ "jison", "bison",