comments and a rename

This commit is contained in:
Terence Parr 2012-09-08 15:23:33 -07:00
parent 22e3f4f85f
commit 4bbbff4e8e
5 changed files with 14 additions and 14 deletions

View File

@ -432,7 +432,7 @@ public class ParserATNSimulator<Symbol extends Token> extends ATNSimulator {
loop: loop:
while ( true ) { while ( true ) {
if ( dfa_debug ) System.out.println("DFA state "+s.stateNumber+" LA(1)=="+getLookaheadName(input)); if ( dfa_debug ) System.out.println("DFA state "+s.stateNumber+" LA(1)=="+getLookaheadName(input));
if ( s.isCtxSensitive && !SLL ) { if ( s.requiresFullContext && !SLL ) {
if ( dfa_debug ) System.out.println("ctx sensitive state "+outerContext+" in "+s); if ( dfa_debug ) System.out.println("ctx sensitive state "+outerContext+" in "+s);
boolean loopsSimulateTailRecursion = true; boolean loopsSimulateTailRecursion = true;
boolean fullCtx = true; boolean fullCtx = true;
@ -464,7 +464,7 @@ public class ParserATNSimulator<Symbol extends Token> extends ATNSimulator {
} }
// t is not updated if one of these states is reached // t is not updated if one of these states is reached
assert !s.isCtxSensitive && !s.isAcceptState; assert !s.requiresFullContext && !s.isAcceptState;
// if no edge, pop over to ATN interpreter, update DFA and return // 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 ( s.edges == null || t >= s.edges.length || t < -1 || s.edges[t+1] == null ) {
@ -506,7 +506,7 @@ public class ParserATNSimulator<Symbol extends Token> extends ATNSimulator {
throw noViableAlt(input, outerContext, s.configs, startIndex); throw noViableAlt(input, outerContext, s.configs, startIndex);
} }
s = target; s = target;
if (!s.isCtxSensitive && !s.isAcceptState) { if (!s.requiresFullContext && !s.isAcceptState) {
input.consume(); input.consume();
t = input.LA(1); t = input.LA(1);
} }
@ -674,6 +674,9 @@ public class ParserATNSimulator<Symbol extends Token> extends ATNSimulator {
} }
else { else {
// SLL CONFLICT; RETRY WITH FULL LL CONTEXT // SLL CONFLICT; RETRY WITH FULL LL CONTEXT
// (it's possible SLL with preds could resolve to single alt
// which would mean we could avoid full LL, but not worth
// code complexity.)
if ( debug ) System.out.println("RETRY with outerContext="+outerContext); if ( debug ) System.out.println("RETRY with outerContext="+outerContext);
// don't look up context in cache now since we're just creating state D // don't look up context in cache now since we're just creating state D
loopsSimulateTailRecursion = true; loopsSimulateTailRecursion = true;
@ -689,7 +692,7 @@ public class ParserATNSimulator<Symbol extends Token> extends ATNSimulator {
D.configs.conflictingAlts.getMinElement(), D.configs.conflictingAlts.getMinElement(),
greedy); greedy);
// not accept state: isCtxSensitive // not accept state: isCtxSensitive
D.isCtxSensitive = true; // always force DFA to ATN simulate D.requiresFullContext = true; // always force DFA to ATN simulate
D.prediction = ATN.INVALID_ALT_NUMBER; D.prediction = ATN.INVALID_ALT_NUMBER;
addDFAEdge(dfa, previousD, t, D); addDFAEdge(dfa, previousD, t, D);
return predictedAlt; // all done with preds, etc... return predictedAlt; // all done with preds, etc...
@ -766,6 +769,7 @@ public class ParserATNSimulator<Symbol extends Token> extends ATNSimulator {
} }
} }
// all adds to dfa are done after we've created full D state
addDFAEdge(dfa, previousD, t, D); addDFAEdge(dfa, previousD, t, D);
if ( D.isAcceptState ) return predictedAlt; if ( D.isAcceptState ) return predictedAlt;

View File

@ -89,7 +89,7 @@ public class DFASerializer {
stateStr = ":s"+n+"=>"+s.prediction; stateStr = ":s"+n+"=>"+s.prediction;
} }
} }
else if ( s.isCtxSensitive ) { else if ( s.requiresFullContext) {
stateStr = "s"+n+"^"; stateStr = "s"+n+"^";
} }
return stateStr; return stateStr;

View File

@ -89,7 +89,7 @@ public class DFAState {
* Future execDFA() invocations immediately jumped doing full context * Future execDFA() invocations immediately jumped doing full context
* prediction if this field is true. * prediction if this field is true.
*/ */
public boolean isCtxSensitive; public boolean requiresFullContext;
/** During SLL parsing, this is a list of predicates associated with the /** During SLL parsing, this is a list of predicates associated with the
* ATN configurations of the DFA state. When we have predicates, * ATN configurations of the DFA state. When we have predicates,

View File

@ -139,7 +139,7 @@ public class DOTGenerator {
if ( s.isAcceptState ) { if ( s.isAcceptState ) {
buf.append("=>").append(s.prediction); buf.append("=>").append(s.prediction);
} }
if ( s.isCtxSensitive ) { if ( s.requiresFullContext) {
buf.append("^"); buf.append("^");
} }
if ( grammar!=null && grammar.tool.verbose_dfa ) { if ( grammar!=null && grammar.tool.verbose_dfa ) {

View File

@ -199,13 +199,9 @@ public class TestParserExec extends BaseTest {
*/ */
@Test @Test
public void testIfIfElse() throws Exception { public void testIfIfElse() throws Exception {
/* // Sam's works here but mine doesn't since I fail over to LL even
With the predicate, this looks to be context sensitive to the full // though SLL + preds evals to single alt; i could avoid but
LL prediction because that edge literally disappears. With SLL // code complexity wasn't worth it. see branch SLL-w-preds-avoids-LL
prediction, it sees a conflict. Even though there's a predicate,
it can't be sure that context would not resolve the conflict. Hence,
it retries with full context and sees no conflict.
*/
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
"s : stmt EOF ;\n" + "s : stmt EOF ;\n" +