Search in sources :

Example 6 with DecisionInfo

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));
}
Also used : DecisionInfo(org.antlr.v4.runtime.atn.DecisionInfo) Grammar(org.antlr.v4.tool.Grammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Example 7 with DecisionInfo

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);
}
Also used : DecisionInfo(org.antlr.v4.runtime.atn.DecisionInfo) Grammar(org.antlr.v4.tool.Grammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with DecisionInfo

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));
}
Also used : DecisionInfo(org.antlr.v4.runtime.atn.DecisionInfo) Grammar(org.antlr.v4.tool.Grammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with DecisionInfo

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());
}
Also used : DecisionInfo(org.antlr.v4.runtime.atn.DecisionInfo) Grammar(org.antlr.v4.tool.Grammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Example 10 with DecisionInfo

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));
}
Also used : DecisionInfo(org.antlr.v4.runtime.atn.DecisionInfo) Grammar(org.antlr.v4.tool.Grammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Aggregations

DecisionInfo (org.antlr.v4.runtime.atn.DecisionInfo)11 Grammar (org.antlr.v4.tool.Grammar)9 LexerGrammar (org.antlr.v4.tool.LexerGrammar)9 Test (org.junit.Test)9 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)3 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)3 LexerInterpreter (org.antlr.v4.runtime.LexerInterpreter)3 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)3 GrammarParserInterpreter (org.antlr.v4.tool.GrammarParserInterpreter)2 Ignore (org.junit.Ignore)2 ParserInterpreter (org.antlr.v4.runtime.ParserInterpreter)1 AmbiguityInfo (org.antlr.v4.runtime.atn.AmbiguityInfo)1 LookaheadEventInfo (org.antlr.v4.runtime.atn.LookaheadEventInfo)1 ParseTree (org.antlr.v4.runtime.tree.ParseTree)1 Rule (org.antlr.v4.tool.Rule)1