ParserATNSimulator

This commit is contained in:
Peter Boyer 2015-12-18 18:46:09 -05:00
parent aa6cedaade
commit cd2466a9d9
7 changed files with 345 additions and 508 deletions

View File

@ -64,11 +64,11 @@ func NewATNConfig1(c *ATNConfig, state *ATNState, context *PredictionContext) *A
func NewATNConfig(c *ATNConfig, state *ATNState, context *PredictionContext, semanticContext *SemanticContext) *ATNConfig {
a := new(ATNConfig)
a.InitATNConfig2(c, state, context, semanticContext)
a.InitATNConfig(c, state, context, semanticContext)
return a
}
func (a *ATNConfig) InitATNConfig2(c *ATNConfig, state *ATNState, context *PredictionContext, semanticContext *SemanticContext) {
func (a *ATNConfig) InitATNConfig(c *ATNConfig, state *ATNState, context *PredictionContext, semanticContext *SemanticContext) {
a.state = state;
a.alt = c.alt;
@ -198,6 +198,7 @@ func (this *ATNConfig) toString() string {
type LexerATNConfig struct {
ATNConfig
lexerActionExecutor *LexerActionExecutor
passedThroughNonGreedyDecision bool
}
@ -227,18 +228,29 @@ func (this *LexerATNConfig) hashString() {
}
func (this *LexerATNConfig) equals(other *ATNConfig) bool {
othert, ok := other.(*LexerATNConfig)
if (this == other) {
return true
} else if _, ok := other.(*LexerATNConfig); !ok {
} else if !ok {
return false
} else if (this.passedThroughNonGreedyDecision != other.passedThroughNonGreedyDecision) {
} else if (this.passedThroughNonGreedyDecision != othert.passedThroughNonGreedyDecision) {
return false
} else if (this.lexerActionExecutor ?
!this.lexerActionExecutor.equals(other.lexerActionExecutor)
: !other.lexerActionExecutor) {
}
var b bool
if (this.lexerActionExecutor != nil){
b = !this.lexerActionExecutor.equals(othert.lexerActionExecutor)
} else {
b = !othert.lexerActionExecutor
}
if (b) {
return false
} else {
return ATNConfig.prototype.equals.call(this, other)
panic("Not implemented")
// return ATNConfig.prototype.equals.call(this, other)
}
}

View File

@ -132,7 +132,7 @@ type NoViableAltException struct {
// of the offending input and also knows where the parser was
// in the various paths when the error. Reported by reportNoViableAlternative()
//
func NoViableAltException(recognizer *Parser, input *InputStream, startToken *Token,
func NewNoViableAltException(recognizer *Parser, input *InputStream, startToken *Token,
offendingToken *Token, deadEndConfigs *ATNConfigSet, ctx *ParserRuleContext) *NoViableAltException {
if (ctx == nil){

File diff suppressed because it is too large Load Diff

View File

@ -92,7 +92,7 @@ func (this *RuleContext) getPayload() *RuleContext {
// added to the parse trees, they will not appear in the output of this
// method.
//
func (this *RuleContext) getText() {
func (this *RuleContext) getText() string {
if (this.getChildCount() == 0) {
return ""
} else {
@ -128,8 +128,7 @@ func (this *RuleContext) toStringTree(ruleNames []string, recog *Recognizer) str
}
func (this *RuleContext) toString(ruleNames []string, stop *RuleContext) string {
ruleNames = ruleNames || nil
stop = stop || nil
var p *RuleContext = this
var s = "["
for (p != nil && p != stop) {

View File

@ -17,7 +17,7 @@ type SemanticContext interface {
toString() string
}
func SemanticContextandContext(a, b *SemanticContext) {
func SemanticContextandContext(a, b *SemanticContext) *SemanticContext {
if (a == nil || a == SemanticContextNONE) {
return b
}
@ -32,7 +32,7 @@ func SemanticContextandContext(a, b *SemanticContext) {
}
}
func SemanticContextorContext(a, b *SemanticContext) {
func SemanticContextorContext(a, b *SemanticContext) *SemanticContext {
if (a == nil) {
return b
}

View File

@ -18,6 +18,7 @@ type Transition struct {
target *ATNState
isEpsilon bool
label *IntervalSet
serializationType int
}
func Transition (target *ATNState) *Transition {
@ -39,6 +40,10 @@ func (t *Transition) InitTransition(target *ATNState) {
t.label = nil
}
func (t *Transition) matches( symbol, minVocabSymbol, maxVocabSymbol int ) bool {
panic("Not implemented")
}
const(
TransitionEPSILON = 1
TransitionRANGE = 2
@ -97,7 +102,6 @@ type AtomTransition struct {
Transition
label_ int
label *IntervalSet
serializationType int
}
func NewAtomTransition ( target *ATNState, label int ) *AtomTransition {
@ -128,7 +132,7 @@ func (t *AtomTransition) toString() string {
type RuleTransition struct {
Transition
ruleIndex, precedence, followState, serializationType int
ruleIndex, precedence, followState int
}
func NewRuleTransition ( ruleStart *ATNState, ruleIndex, precedence, followState int ) *RuleTransition {
@ -155,7 +159,7 @@ type EpsilonTransition struct {
Transition
isEpsilon bool
outermostPrecedenceReturn, serializationType int
outermostPrecedenceReturn int
}
func NewEpsilonTransition ( target *ATNState, outermostPrecedenceReturn int ) *EpsilonTransition {
@ -181,7 +185,7 @@ func (t *EpsilonTransition) toString() string {
type RangeTransition struct {
Transition
serializationType, start, stop int
start, stop int
}
func NewRangeTransition ( target *ATNState, start, stop int ) *RangeTransition {
@ -228,7 +232,7 @@ type PredicateTransition struct {
Transition
isCtxDependent bool
ruleIndex, predIndex, serializationType int
ruleIndex, predIndex int
}
func PredicateTransition ( target *ATNState, ruleIndex, predIndex int, isCtxDependent bool ) *PredicateTransition {
@ -261,7 +265,7 @@ type ActionTransition struct {
Transition
isCtxDependent bool
ruleIndex, actionIndex, predIndex, serializationType int
ruleIndex, actionIndex, predIndex int
}
func NewActionTransition ( target *ATNState, ruleIndex, actionIndex int, isCtxDependent bool ) *ActionTransition {
@ -290,8 +294,6 @@ func (t *ActionTransition) toString() string {
type SetTransition struct {
Transition
serializationType int
}
func NewSetTransition ( target *ATNState, set *IntervalSet ) *SetTransition {
@ -352,8 +354,6 @@ func (t *NotSetTransition) toString() string {
type WildcardTransition struct {
Transition
serializationType int
}
func NewWildcardTransition ( target *ATNState ) *WildcardTransition {
@ -377,7 +377,6 @@ type PrecedencePredicateTransition struct {
Transition
precedence int
serializationType int
}
func PrecedencePredicateTransition ( target *ATNState, precedence int ) *PrecedencePredicateTransition {

View File

@ -1536,7 +1536,7 @@ ParserATNSimulator.prototype.getLookaheadName = function(input) {
//
ParserATNSimulator.prototype.dumpDeadEndConfigs = function(nvae) {
console.log("dead end configs: ");
var decs = nvae.getDeadEndConfigs();
var decs = nvae.deadEndConfigs;
for(var i=0; i<decs.length; i++) {
var c = decs[i];
var trans = "no edges";