use of org.antlr.v4.runtime.atn.DecisionInfo in project antlr4 by antlr.
the class TestParserProfiler method test2xOptional.
@Test
public void test2xOptional() throws Exception {
Grammar g = new Grammar("parser grammar T;\n" + "s : ID ('.' ID)? ';'\n" + " | ID INT \n" + " ;\n", lg);
DecisionInfo[] info = interpAndGetDecisionInfo(lg, g, "s", "a.b;", "a.b;");
assertEquals(2, info.length);
String expecting = "[{decision=0, contextSensitivities=0, errors=0, ambiguities=0, SLL_lookahead=2, " + "SLL_ATNTransitions=1, SLL_DFATransitions=1, LL_Fallback=0, LL_lookahead=0, LL_ATNTransitions=0}, " + "{decision=1, contextSensitivities=0, errors=0, ambiguities=0, SLL_lookahead=4, " + "SLL_ATNTransitions=2, SLL_DFATransitions=2, LL_Fallback=0, LL_lookahead=0, LL_ATNTransitions=0}]";
assertEquals(expecting, Arrays.toString(info));
}
use of org.antlr.v4.runtime.atn.DecisionInfo in project antlr4 by antlr.
the class TestParserProfiler method testSimpleLanguage.
@Ignore
@Test
public void testSimpleLanguage() throws Exception {
Grammar g = new Grammar(TestXPath.grammar);
String input = "def f(x,y) { x = 3+4*1*1/5*1*1+1*1+1; y; ; }\n" + "def g(x,a,b,c,d,e) { return 1+2*x; }\n" + "def h(x) { a=3; x=0+1; return a*x; }\n";
DecisionInfo[] info = interpAndGetDecisionInfo(g.getImplicitLexer(), g, "prog", input);
String expecting = "[{decision=0, contextSensitivities=1, errors=0, ambiguities=0, SLL_lookahead=3, " + "SLL_ATNTransitions=2, SLL_DFATransitions=0, LL_Fallback=1, LL_ATNTransitions=1}]";
assertEquals(expecting, Arrays.toString(info));
assertEquals(1, info.length);
}
use of org.antlr.v4.runtime.atn.DecisionInfo in project antlr4 by antlr.
the class TestParserProfiler method testDeepLookahead.
@Ignore
@Test
public void testDeepLookahead() throws Exception {
Grammar g = new Grammar("parser grammar T;\n" + "s : e ';'\n" + " | e '.' \n" + " ;\n" + // d=1 entry, d=2 bypass
"e : (ID|INT) ({true}? '+' e)*\n" + " ;\n", lg);
// pred forces to
// ambig and ('+' e)* tail recursion forces lookahead to fall out of e
// any non-precedence predicates are always evaluated as true by the interpreter
DecisionInfo[] info = interpAndGetDecisionInfo(lg, g, "s", "a+b+c;");
// at "+b" it uses k=1 and enters loop then calls e for b...
// e matches and d=2 uses "+c;" for k=3
assertEquals(2, info.length);
String expecting = "[{decision=0, contextSensitivities=0, errors=0, ambiguities=0, SLL_lookahead=6, " + "SLL_ATNTransitions=6, SLL_DFATransitions=0, LL_Fallback=0, LL_lookahead=0, LL_ATNTransitions=0}, " + "{decision=1, contextSensitivities=0, errors=0, ambiguities=0, SLL_lookahead=4, " + "SLL_ATNTransitions=2, SLL_DFATransitions=2, LL_Fallback=0, LL_lookahead=0, LL_ATNTransitions=0}]";
assertEquals(expecting, Arrays.toString(info));
}
use of org.antlr.v4.runtime.atn.DecisionInfo in project antlr4 by antlr.
the class TestParserProfiler method testLL2.
@Test
public void testLL2() throws Exception {
Grammar g = new Grammar("parser grammar T;\n" + "s : ID ';'{}\n" + " | ID '.'\n" + " ;\n", lg);
DecisionInfo[] info = interpAndGetDecisionInfo(lg, g, "s", "xyz;");
assertEquals(1, info.length);
String expecting = "{decision=0, contextSensitivities=0, errors=0, ambiguities=0, SLL_lookahead=2, " + "SLL_ATNTransitions=2, SLL_DFATransitions=0, LL_Fallback=0, LL_lookahead=0, LL_ATNTransitions=0}";
assertEquals(expecting, info[0].toString());
}
use of org.antlr.v4.runtime.atn.DecisionInfo in project antlr4 by antlr.
the class TestParserProfiler method testOptional.
@Test
public void testOptional() throws Exception {
Grammar g = new Grammar("parser grammar T;\n" + "s : ID ('.' ID)? ';'\n" + " | ID INT \n" + " ;\n", lg);
DecisionInfo[] info = interpAndGetDecisionInfo(lg, g, "s", "a.b;");
assertEquals(2, info.length);
String expecting = "[{decision=0, contextSensitivities=0, errors=0, ambiguities=0, SLL_lookahead=1, " + "SLL_ATNTransitions=1, SLL_DFATransitions=0, LL_Fallback=0, LL_lookahead=0, LL_ATNTransitions=0}, " + "{decision=1, contextSensitivities=0, errors=0, ambiguities=0, SLL_lookahead=2, " + "SLL_ATNTransitions=2, SLL_DFATransitions=0, LL_Fallback=0, LL_lookahead=0, LL_ATNTransitions=0}]";
assertEquals(expecting, Arrays.toString(info));
}
Aggregations