Merge pull request #14 from sharwell/parrt-master

Fixed excessive consume in execDFA and corrected the unit test that should have detected it
This commit is contained in:
Terence Parr 2012-02-15 12:40:11 -08:00
commit f426e8781b
2 changed files with 9 additions and 3 deletions

View File

@ -364,6 +364,10 @@ public class ParserATNSimulator<Symbol> extends ATNSimulator {
// TODO: v3 dfa don't do this.
break;
}
// t is not updated if one of these states is reached
assert !s.isCtxSensitive && !s.isAcceptState;
// if no edge, pop over to ATN interpreter, update DFA and return
if ( s.edges == null || t >= s.edges.length || t < -1 || s.edges[t+1] == null ) {
if ( dfa_debug && t>=0 ) System.out.println("no edge for "+parser.getTokenNames()[t]);
@ -404,8 +408,10 @@ public class ParserATNSimulator<Symbol> extends ATNSimulator {
throw noViableAlt(input, outerContext, s.configset, startIndex);
}
s = target;
input.consume();
t = input.LA(1);
if (!s.isCtxSensitive && !s.isAcceptState) {
input.consume();
t = input.LA(1);
}
}
// if ( acceptState==null ) {
// if ( debug ) System.out.println("!!! no viable alt in dfa");

View File

@ -118,7 +118,7 @@ public class TestFullContextParsing extends BaseTest {
assertEquals(expecting, result);
assertEquals("line 1:5 reportAttemptingFullContext d=2: [(30,1,[20 10]), (22,2,[10])], input='34abc'\n" +
"line 1:2 reportContextSensitivity d=2: [(22,1,[10])],uniqueAlt=1, input='34'\n" +
"line 1:17 reportAttemptingFullContext d=2: [(30,1,[24 14]), (26,2,[14])], input='34abc'\n" +
"line 1:14 reportAttemptingFullContext d=2: [(30,1,[24 14]), (26,2,[14])], input='34abc'\n" +
"line 1:14 reportContextSensitivity d=2: [(8,2,[18]), (12,2,[18]), (1,2,[])],uniqueAlt=2, input='34abc'\n",
this.stderrDuringParse);
}