Search in sources :

Example 1 with PredictionContext

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

the class LL1Analyzer method LOOK.

/**
	 * Compute set of tokens that can follow {@code s} in the ATN in the
	 * specified {@code ctx}.
	 *
	 * <p>If {@code ctx} is {@code null} and the end of the rule containing
	 * {@code s} is reached, {@link Token#EPSILON} is added to the result set.
	 * If {@code ctx} is not {@code null} and the end of the outermost rule is
	 * reached, {@link Token#EOF} is added to the result set.</p>
	 *
	 * @param s the ATN state
	 * @param stopState the ATN state to stop at. This can be a
	 * {@link BlockEndState} to detect epsilon paths through a closure.
	 * @param ctx the complete parser context, or {@code null} if the context
	 * should be ignored
	 *
	 * @return The set of tokens that can follow {@code s} in the ATN in the
	 * specified {@code ctx}.
	 */
public IntervalSet LOOK(ATNState s, ATNState stopState, RuleContext ctx) {
    IntervalSet r = new IntervalSet();
    // ignore preds; get all lookahead
    boolean seeThruPreds = true;
    PredictionContext lookContext = ctx != null ? PredictionContext.fromRuleContext(s.atn, ctx) : null;
    _LOOK(s, stopState, lookContext, r, new HashSet<ATNConfig>(), new BitSet(), seeThruPreds, true);
    return r;
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) BitSet(java.util.BitSet)

Example 2 with PredictionContext

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

the class TestGraphNodes method test_ax_by.

@Test
public void test_ax_by() {
    PredictionContext a = createSingleton(x(), 1);
    PredictionContext b = createSingleton(y(), 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=\"*\"];\n" + "  s1[label=\"1\"];\n" + "  s0:p0->s1[label=\"1\"];\n" + "  s0:p1->s2[label=\"2\"];\n" + "  s2->s3[label=\"10\"];\n" + "  s1->s3[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)

Example 3 with PredictionContext

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

the class TestGraphNodes method test_$_x_fullctx.

@Test
public void test_$_x_fullctx() {
    PredictionContext r = PredictionContext.merge(PredictionContext.EMPTY, x(), fullCtx(), null);
    //		System.out.println(toDOTString(r, fullCtx()));
    String expecting = "digraph G {\n" + "rankdir=LR;\n" + "  s0[shape=record, label=\"<p0>|<p1>$\"];\n" + "  s1[label=\"$\"];\n" + "  s0:p0->s1[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 4 with PredictionContext

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

the class TestGraphNodes method test_Aaxc_Aayd.

@Test
public void test_Aaxc_Aayd() {
    // ax,c + ay,d -> merged a, array parent
    SingletonPredictionContext a1 = createSingleton(x(), 1);
    SingletonPredictionContext a2 = createSingleton(y(), 1);
    ArrayPredictionContext A1 = array(a1, c());
    ArrayPredictionContext A2 = array(a2, d());
    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>|<p2>\"];\n" + "  s2[label=\"*\"];\n" + "  s1[shape=record, label=\"<p0>|<p1>\"];\n" + "  s0:p0->s1[label=\"1\"];\n" + "  s0:p1->s2[label=\"3\"];\n" + "  s0:p2->s2[label=\"4\"];\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 5 with PredictionContext

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

the class TestGraphNodes method test_x_$.

@Test
public void test_x_$() {
    PredictionContext r = PredictionContext.merge(x(), PredictionContext.EMPTY, rootIsWildcard(), null);
    //		System.out.println(toDOTString(r, rootIsWildcard()));
    String expecting = "digraph G {\n" + "rankdir=LR;\n" + "  s0[label=\"*\"];\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