diff --git a/runtime/Go/src/antlr4/DFASerializer.go b/runtime/Go/src/antlr4/DFASerializer.go index a0a6b1f5e..c54f90e7a 100644 --- a/runtime/Go/src/antlr4/DFASerializer.go +++ b/runtime/Go/src/antlr4/DFASerializer.go @@ -7,11 +7,6 @@ import ( // A DFA walker that knows how to dump them to serialized strings. -type IDFASerializer interface { - -} - - type DFASerializer struct { dfa *DFA literalNames, symbolicNames []string @@ -44,8 +39,7 @@ func (this *DFASerializer) String() string { var buf = "" var states = this.dfa.sortedStates() - for i := 0; i < len(states); i++ { - var s = states[i] + for _,s := range states { if s.edges != nil { var n = len(s.edges) for j := 0; j < n; j++ { diff --git a/runtime/Go/src/antlr4/DFAState.go b/runtime/Go/src/antlr4/DFAState.go index 1ec489765..0f000f5ba 100644 --- a/runtime/Go/src/antlr4/DFAState.go +++ b/runtime/Go/src/antlr4/DFAState.go @@ -121,6 +121,10 @@ func (this *DFAState) GetAltSet() *Set { } } +func (this *DFAState) setPrediction(v int) { + this.prediction = v +} + // Two {@link DFAState} instances are equal if their ATN configuration sets // are the same. This method is used to see if a state already exists. // @@ -151,8 +155,8 @@ func (this *DFAState) String() string { func (this *DFAState) Hash() string { var s string - if (this.isAcceptState) { - if (this.predicates != nil) { + if this.isAcceptState { + if this.predicates != nil { s = "=>" + fmt.Sprint(this.predicates) } else { s = "=>" + fmt.Sprint(this.prediction) diff --git a/runtime/Go/src/antlr4/LL1Analyzer.go b/runtime/Go/src/antlr4/LL1Analyzer.go index 588ef88e4..422cce1e4 100644 --- a/runtime/Go/src/antlr4/LL1Analyzer.go +++ b/runtime/Go/src/antlr4/LL1Analyzer.go @@ -175,7 +175,7 @@ func (la *LL1Analyzer) _LOOK(s, stopState IATNState, ctx IPredictionContext, loo for i := 0; i < ctx.length(); i++ { returnState := la.atn.states[ctx.getReturnState(i)] - la.__LOOK(returnState, stopState, ctx.GetParent(i), look, lookBusy, calledRuleStack, seeThruPreds, addEOF, i) + la.__LOOK(returnState, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF, i) } return diff --git a/runtime/Go/src/antlr4/LexerATNSimulator.go b/runtime/Go/src/antlr4/LexerATNSimulator.go index 93fa44d6a..d846931b6 100644 --- a/runtime/Go/src/antlr4/LexerATNSimulator.go +++ b/runtime/Go/src/antlr4/LexerATNSimulator.go @@ -623,7 +623,7 @@ func (this *LexerATNSimulator) addDFAState(configs *ATNConfigSet) *DFAState { if firstConfigWithRuleStopState != nil { proposed.isAcceptState = true proposed.lexerActionExecutor = firstConfigWithRuleStopState.(*LexerATNConfig).lexerActionExecutor - proposed.prediction = this.atn.ruleToTokenType[firstConfigWithRuleStopState.GetState().GetRuleIndex()] + proposed.setPrediction(this.atn.ruleToTokenType[firstConfigWithRuleStopState.GetState().GetRuleIndex()]) } var hash = proposed.Hash() var dfa = this.decisionToDFA[this.mode] diff --git a/runtime/Go/src/antlr4/ParserATNSimulator.go b/runtime/Go/src/antlr4/ParserATNSimulator.go index 46b82dc04..c2cfa1756 100644 --- a/runtime/Go/src/antlr4/ParserATNSimulator.go +++ b/runtime/Go/src/antlr4/ParserATNSimulator.go @@ -327,19 +327,19 @@ func (this *ParserATNSimulator) computeTargetState(dfa *DFA, previousD *DFAState // NO CONFLICT, UNIQUELY PREDICTED ALT D.isAcceptState = true D.configs.uniqueAlt = predictedAlt - D.prediction = predictedAlt + D.setPrediction( predictedAlt ) } else if PredictionModehasSLLConflictTerminatingPrediction(this.predictionMode, reach) { // MORE THAN ONE VIABLE ALTERNATIVE D.configs.conflictingAlts = this.getConflictingAlts(reach) D.requiresFullContext = true // in SLL-only mode, we will stop at this state and return the minimum alt D.isAcceptState = true - D.prediction = D.configs.conflictingAlts.minValue() + D.setPrediction( D.configs.conflictingAlts.minValue() ) } if D.isAcceptState && D.configs.hasSemanticContext { this.predicateDFAState(D, this.atn.getDecisionState(dfa.decision)) if D.predicates != nil { - D.prediction = ATNINVALID_ALT_NUMBER + D.setPrediction( ATNINVALID_ALT_NUMBER ) } } // all adds to dfa are done after we've created full D state @@ -357,12 +357,12 @@ func (this *ParserATNSimulator) predicateDFAState(dfaState *DFAState, decisionSt var altToPred = this.getPredsForAmbigAlts(altsToCollectPredsFrom, dfaState.configs, nalts) if altToPred != nil { dfaState.predicates = this.getPredicatePredictions(altsToCollectPredsFrom, altToPred) - dfaState.prediction = ATNINVALID_ALT_NUMBER // make sure we use preds + dfaState.setPrediction( ATNINVALID_ALT_NUMBER ) // make sure we use preds } else { // There are preds in configs but they might go away // when OR'd together like {p}? || NONE == NONE. If neither // alt has preds, resolve to min alt - dfaState.prediction = altsToCollectPredsFrom.minValue() + dfaState.setPrediction( altsToCollectPredsFrom.minValue() ) } } @@ -1072,7 +1072,6 @@ func (this *ParserATNSimulator) closure_(config IATNConfig, configs *ATNConfigSe fmt.Println(closureBusy) } - if this._dfa != nil && this._dfa.precedenceDfa { fmt.Println("DEBUG 4") if t.(*EpsilonTransition).outermostPrecedenceReturn == this._dfa.atnStartState.GetRuleIndex() { diff --git a/runtime/Go/src/antlr4/Utils.go b/runtime/Go/src/antlr4/Utils.go index c7bf9197d..686ede2b7 100644 --- a/runtime/Go/src/antlr4/Utils.go +++ b/runtime/Go/src/antlr4/Utils.go @@ -219,7 +219,7 @@ func (this *BitSet) values() []int { } func (this *BitSet) minValue() int { - min := 0 + min := 2147483647 for k, _ := range this.data { if k < min { diff --git a/runtime/JavaScript/src/ArithmeticParser.js b/runtime/JavaScript/src/ArithmeticParser.js index c6a67e047..5af1068e7 100644 --- a/runtime/JavaScript/src/ArithmeticParser.js +++ b/runtime/JavaScript/src/ArithmeticParser.js @@ -726,9 +726,11 @@ ArithmeticParser.prototype.relop = function() { this.state = 56; _la = this._input.LA(1); if(!((((_la) & ~0x1f) == 0 && ((1 << _la) & ((1 << ArithmeticParser.GT) | (1 << ArithmeticParser.LT) | (1 << ArithmeticParser.EQ))) !== 0))) { + console.log("DEBUG1") this._errHandler.recoverInline(this); } else { + console.log("DEBUG2") this.consume(); } } catch (re) { diff --git a/runtime/JavaScript/src/antlr4/BufferedTokenStream.js b/runtime/JavaScript/src/antlr4/BufferedTokenStream.js index ca299c73d..e1fb948d6 100644 --- a/runtime/JavaScript/src/antlr4/BufferedTokenStream.js +++ b/runtime/JavaScript/src/antlr4/BufferedTokenStream.js @@ -97,7 +97,6 @@ BufferedTokenStream.prototype.mark = function() { }; BufferedTokenStream.prototype.release = function(marker) { -console.log("Nothing to release") // no resources to release }; diff --git a/runtime/JavaScript/src/antlr4/Parser.js b/runtime/JavaScript/src/antlr4/Parser.js index d6f08e674..ad8127194 100644 --- a/runtime/JavaScript/src/antlr4/Parser.js +++ b/runtime/JavaScript/src/antlr4/Parser.js @@ -141,7 +141,6 @@ Parser.prototype.match = function(ttype) { if (t.type === ttype) { this._errHandler.reportMatch(this); this.consume(); - console.log("consume done") } else { t = this._errHandler.recoverInline(this); if (this.buildParseTrees && t.tokenIndex === -1) { diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg index 16b513ff5..33c6c9e3e 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg @@ -454,7 +454,7 @@ TestSetInline(s) ::= << // Javascript language spec - shift operators are 32 bits long max testShiftInRange(shiftAmount) ::= << -(() & 0x1f) == 0 +(() & -(0x1f+1)) == 0 >> // produces smaller bytecode only when bits.ttypes contains more than two items