Search in sources :

Example 21 with PredictionContext

use of org.antlr.v4.runtime.atn.PredictionContext in project antlr4 by antlr.

the class TestGraphNodes method test_aex_bfx.

@Ignore("Known inefficiency but deferring resolving the issue for now")
@Test
public void test_aex_bfx() {
    // TJP: this is inefficient as it leaves the top x nodes unmerged.
    PredictionContext x1 = x();
    PredictionContext x2 = x();
    PredictionContext e = createSingleton(x1, 5);
    PredictionContext f = createSingleton(x2, 6);
    PredictionContext a = createSingleton(e, 1);
    PredictionContext b = createSingleton(f, 2);
    PredictionContext r = PredictionContext.merge(a, b, rootIsWildcard(), null);
    //		System.out.println(toDOTString(r, rootIsWildcard()));
    String expecting = "digraph G {\n" + "rankdir=LR;\n" + "  s0[shape=record, label=\"<p0>|<p1>\"];\n" + "  s2[label=\"2\"];\n" + "  s3[label=\"3\"];\n" + "  s4[label=\"*\"];\n" + "  s1[label=\"1\"];\n" + "  s0:p0->s1[label=\"1\"];\n" + "  s0:p1->s2[label=\"2\"];\n" + "  s2->s3[label=\"6\"];\n" + "  s3->s4[label=\"9\"];\n" + "  s1->s3[label=\"5\"];\n" + "}\n";
    assertEquals(expecting, toDOTString(r, rootIsWildcard()));
}
Also used : SingletonPredictionContext(org.antlr.v4.runtime.atn.SingletonPredictionContext) PredictionContext(org.antlr.v4.runtime.atn.PredictionContext) ArrayPredictionContext(org.antlr.v4.runtime.atn.ArrayPredictionContext) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 22 with PredictionContext

use of org.antlr.v4.runtime.atn.PredictionContext in project antlr4 by antlr.

the class TestGraphNodes method test_Aax_Aay.

@Test
public void test_Aax_Aay() {
    // ax + ay -> merged singleton a, array parent
    SingletonPredictionContext a1 = createSingleton(x(), 1);
    SingletonPredictionContext a2 = createSingleton(y(), 1);
    ArrayPredictionContext A1 = array(a1);
    ArrayPredictionContext A2 = array(a2);
    PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard(), null);
    //		System.out.println(toDOTString(r, rootIsWildcard()));
    String expecting = "digraph G {\n" + "rankdir=LR;\n" + "  s0[label=\"0\"];\n" + "  s1[shape=record, label=\"<p0>|<p1>\"];\n" + "  s2[label=\"*\"];\n" + "  s0->s1[label=\"1\"];\n" + "  s1:p0->s2[label=\"9\"];\n" + "  s1:p1->s2[label=\"10\"];\n" + "}\n";
    assertEquals(expecting, toDOTString(r, rootIsWildcard()));
}
Also used : ArrayPredictionContext(org.antlr.v4.runtime.atn.ArrayPredictionContext) SingletonPredictionContext(org.antlr.v4.runtime.atn.SingletonPredictionContext) SingletonPredictionContext(org.antlr.v4.runtime.atn.SingletonPredictionContext) PredictionContext(org.antlr.v4.runtime.atn.PredictionContext) ArrayPredictionContext(org.antlr.v4.runtime.atn.ArrayPredictionContext) Test(org.junit.Test)

Example 23 with PredictionContext

use of org.antlr.v4.runtime.atn.PredictionContext in project antlr4 by antlr.

the class TestGraphNodes method test_Aab_Ab.

@Test
public void test_Aab_Ab() {
    // a,b + b
    ArrayPredictionContext A1 = array(a(), b());
    ArrayPredictionContext A2 = array(b());
    PredictionContext r = PredictionContext.merge(A1, A2, rootIsWildcard(), null);
    //		System.out.println(toDOTString(r, rootIsWildcard()));
    String expecting = "digraph G {\n" + "rankdir=LR;\n" + "  s0[shape=record, label=\"<p0>|<p1>\"];\n" + "  s1[label=\"*\"];\n" + "  s0:p0->s1[label=\"1\"];\n" + "  s0:p1->s1[label=\"2\"];\n" + "}\n";
    assertEquals(expecting, toDOTString(r, rootIsWildcard()));
}
Also used : ArrayPredictionContext(org.antlr.v4.runtime.atn.ArrayPredictionContext) SingletonPredictionContext(org.antlr.v4.runtime.atn.SingletonPredictionContext) PredictionContext(org.antlr.v4.runtime.atn.PredictionContext) ArrayPredictionContext(org.antlr.v4.runtime.atn.ArrayPredictionContext) Test(org.junit.Test)

Example 24 with PredictionContext

use of org.antlr.v4.runtime.atn.PredictionContext in project antlr4 by antlr.

the class TestGraphNodes method test_a$_ax_fullctx.

@Test
public void test_a$_ax_fullctx() {
    PredictionContext a1 = a();
    PredictionContext x = x();
    PredictionContext a2 = createSingleton(x, 1);
    PredictionContext r = PredictionContext.merge(a1, a2, fullCtx(), null);
    //		System.out.println(toDOTString(r, fullCtx()));
    String expecting = "digraph G {\n" + "rankdir=LR;\n" + "  s0[label=\"0\"];\n" + "  s1[shape=record, label=\"<p0>|<p1>$\"];\n" + "  s2[label=\"$\"];\n" + "  s0->s1[label=\"1\"];\n" + "  s1:p0->s2[label=\"9\"];\n" + "}\n";
    assertEquals(expecting, toDOTString(r, fullCtx()));
}
Also used : SingletonPredictionContext(org.antlr.v4.runtime.atn.SingletonPredictionContext) PredictionContext(org.antlr.v4.runtime.atn.PredictionContext) ArrayPredictionContext(org.antlr.v4.runtime.atn.ArrayPredictionContext) Test(org.junit.Test)

Example 25 with PredictionContext

use of org.antlr.v4.runtime.atn.PredictionContext in project antlr4 by antlr.

the class TestGraphNodes method test_ax_ax.

@Test
public void test_ax_ax() {
    PredictionContext x1 = x();
    PredictionContext x2 = x();
    PredictionContext a1 = createSingleton(x1, 1);
    PredictionContext a2 = createSingleton(x2, 1);
    PredictionContext r = PredictionContext.merge(a1, a2, rootIsWildcard(), null);
    //		System.out.println(toDOTString(r, rootIsWildcard()));
    String expecting = "digraph G {\n" + "rankdir=LR;\n" + "  s0[label=\"0\"];\n" + "  s1[label=\"1\"];\n" + "  s2[label=\"*\"];\n" + "  s0->s1[label=\"1\"];\n" + "  s1->s2[label=\"9\"];\n" + "}\n";
    assertEquals(expecting, toDOTString(r, rootIsWildcard()));
}
Also used : SingletonPredictionContext(org.antlr.v4.runtime.atn.SingletonPredictionContext) PredictionContext(org.antlr.v4.runtime.atn.PredictionContext) ArrayPredictionContext(org.antlr.v4.runtime.atn.ArrayPredictionContext) Test(org.junit.Test)

Aggregations

ArrayPredictionContext (org.antlr.v4.runtime.atn.ArrayPredictionContext)39 PredictionContext (org.antlr.v4.runtime.atn.PredictionContext)39 SingletonPredictionContext (org.antlr.v4.runtime.atn.SingletonPredictionContext)39 Test (org.junit.Test)38 ArrayDeque (java.util.ArrayDeque)1 BitSet (java.util.BitSet)1 IdentityHashMap (java.util.IdentityHashMap)1 IntervalSet (org.antlr.v4.runtime.misc.IntervalSet)1 Ignore (org.junit.Ignore)1