changes to ATN simulator just before I try adding context back in.

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 8903]
This commit is contained in:
parrt 2011-07-24 13:20:49 -08:00
parent 66da1f723a
commit 1fcc12a7ad
2 changed files with 17 additions and 9 deletions

View File

@ -463,16 +463,23 @@ public class ParserATNSimulator extends ATNSimulator {
ATNConfig c = null; ATNConfig c = null;
if ( t instanceof RuleTransition ) { if ( t instanceof RuleTransition ) {
ATNState p = config.state; ATNState p = config.state;
RuleContext newContext = RuleContext newContext;
new RuleContext(config.context, p.stateNumber, t.target.stateNumber); if ( parser != null ) {
// RuleContext xx = parser.args(config.context, t.target.stateNumber, t.target.ruleIndex, -999); System.out.println("rule trans to rule "+parser.getRuleNames()[t.target.ruleIndex]);
// xx.invokingState = p.stateNumber; newContext = parser.args(config.context, t.target.stateNumber, t.target.ruleIndex, -999);
newContext.invokingState = p.stateNumber;
System.out.println("new ctx type is "+newContext.getClass().getSimpleName());
}
else {
newContext = new RuleContext(config.context, p.stateNumber, t.target.stateNumber);
}
c = new ATNConfig(config, t.target, newContext); c = new ATNConfig(config, t.target, newContext);
// c = new ATNConfig(config, t.target, xx);
} }
else if ( t instanceof PredicateTransition ) { else if ( t instanceof PredicateTransition ) {
PredicateTransition pt = (PredicateTransition)t; PredicateTransition pt = (PredicateTransition)t;
if ( debug ) System.out.println("PRED (eval="+evalPreds+") "+pt.ruleIndex+":"+pt.predIndex); if ( debug ) System.out.println("PRED (eval="+evalPreds+") "+pt.ruleIndex+":"+pt.predIndex);
if ( parser != null ) System.out.println("rule surrounding pred is "+
parser.getRuleNames()[pt.ruleIndex]);
// preds are epsilon if we're not doing preds. // preds are epsilon if we're not doing preds.
// if we are doing preds, pred must eval to true // if we are doing preds, pred must eval to true
if ( !evalPreds || if ( !evalPreds ||

View File

@ -114,7 +114,7 @@ case <index> : return new <r.actions.(index).ctxType>(_localctx, s, <actions.(in
>> >>
RuleActionFunction(r, actions) ::= << RuleActionFunction(r, actions) ::= <<
public void <r.name>_action(<r.ctxType> _localctx, int s, int actionIndex) { public void <r.name>_action(<r.ctxType> _localctx, int actionIndex) {
switch ( actionIndex ) { switch ( actionIndex ) {
<actions:{index| <actions:{index|
case <index> : <actions.(index)> break;}; separator="\n"> case <index> : <actions.(index)> break;}; separator="\n">
@ -141,7 +141,7 @@ public QStack\<<currentRule.ctxType>\> <currentRule.name>_stk = new QStack\<<cur
_ctx = _localctx; _ctx = _localctx;
<currentRule.name>_stk.push(_localctx); <currentRule.name>_stk.push(_localctx);
_localctx.start = input.LT(1); _localctx.start = input.LT(1);
//System.out.println("enter "+ruleNames[<currentRule.index>]); System.out.println("enter "+ruleNames[<currentRule.index>]);
<namedActions.init> <namedActions.init>
<locals; separator="\n"> <locals; separator="\n">
try { try {
@ -158,7 +158,7 @@ public QStack\<<currentRule.ctxType>\> <currentRule.name>_stk = new QStack\<<cur
<currentRule.name>_stk.pop(); <currentRule.name>_stk.pop();
_ctx = (ParserRuleContext)_ctx.parent; _ctx = (ParserRuleContext)_ctx.parent;
<finallyAction> <finallyAction>
//System.out.println("exit "+ruleNames[<currentRule.index>]); System.out.println("exit "+ruleNames[<currentRule.index>]);
} }
return _localctx; return _localctx;
} }
@ -611,7 +611,8 @@ public static final ATN _ATN =
ATNSimulator.deserialize(_serializedATN.toCharArray()); ATNSimulator.deserialize(_serializedATN.toCharArray());
static { static {
org.antlr.v4.tool.DOTGenerator dot = new org.antlr.v4.tool.DOTGenerator(null); org.antlr.v4.tool.DOTGenerator dot = new org.antlr.v4.tool.DOTGenerator(null);
//System.out.println(dot.getDOT(_ATN.decisionToState.get(0), rulesNames)); //System.out.println(dot.getDOT(_ATN.decisionToState.get(0), ruleNames));
//System.out.println(dot.getDOT(_ATN.ruleToStartState[2], ruleNames));
} }
>> >>