Examples of PredictionContext


Examples of org.antlr.v4.runtime.atn.PredictionContext

  @Test public void test_Aax_Aby() { // ax + by but in arrays
    SingletonPredictionContext a = createSingleton(x(), 1);
    SingletonPredictionContext b = createSingleton(y(), 2);
    ArrayPredictionContext A1 = array(a);
    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" +
View Full Code Here

Examples of org.antlr.v4.runtime.atn.PredictionContext

  @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" +
View Full Code Here

Examples of org.antlr.v4.runtime.atn.PredictionContext

  @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" +
View Full Code Here

Examples of org.antlr.v4.runtime.atn.PredictionContext

    SingletonPredictionContext b = createSingleton(v(), 2);
    SingletonPredictionContext c = createSingleton(w(), 3);
    SingletonPredictionContext d = createSingleton(x(), 4);
    ArrayPredictionContext A1 = array(a, b);
    ArrayPredictionContext A2 = array(c, 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>|<p3>\"];\n" +
View Full Code Here

Examples of org.antlr.v4.runtime.atn.PredictionContext

    SingletonPredictionContext b1 = createSingleton(v(), 2);
    SingletonPredictionContext b2 = createSingleton(v(), 2);
    SingletonPredictionContext d = createSingleton(x(), 4);
    ArrayPredictionContext A1 = array(a, b1);
    ArrayPredictionContext A2 = array(b2, 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" +
View Full Code Here

Examples of org.antlr.v4.runtime.atn.PredictionContext

    SingletonPredictionContext b1 = createSingleton(v(), 2);
    SingletonPredictionContext b2 = createSingleton(w(), 2);
    SingletonPredictionContext d = createSingleton(x(), 4);
    ArrayPredictionContext A1 = array(a, b1);
    ArrayPredictionContext A2 = array(b2, 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" +
View Full Code Here

Examples of org.antlr.v4.runtime.atn.PredictionContext

    SingletonPredictionContext b1 = createSingleton(v(), 2);
    SingletonPredictionContext b2 = createSingleton(v(), 2);
    SingletonPredictionContext d = createSingleton(u(), 4);
    ArrayPredictionContext A1 = array(a, b1);
    ArrayPredictionContext A2 = array(b2, 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" +
View Full Code Here

Examples of org.antlr.v4.runtime.atn.PredictionContext

    SingletonPredictionContext b = createSingleton(u(), 2);
    SingletonPredictionContext c = createSingleton(u(), 3);
    SingletonPredictionContext d = createSingleton(u(), 4);
    ArrayPredictionContext A1 = array(a, b);
    ArrayPredictionContext A2 = array(c, 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>|<p3>\"];\n" +
View Full Code Here

Examples of org.antlr.v4.runtime.atn.PredictionContext

    Deque<PredictionContext> workList = new ArrayDeque<PredictionContext>();
    visited.put(context, context);
    contextIds.put(context, contextIds.size());
    workList.add(context);
    while (!workList.isEmpty()) {
      PredictionContext current = workList.pop();
      nodes.append("  s").append(contextIds.get(current)).append('[');

      if (current.size() > 1) {
        nodes.append("shape=record, ");
      }

      nodes.append("label=\"");

      if (current.isEmpty()) {
        nodes.append(rootIsWildcard ? '*' : '$');
      } else if (current.size() > 1) {
        for (int i = 0; i < current.size(); i++) {
          if (i > 0) {
            nodes.append('|');
          }

          nodes.append("<p").append(i).append('>');
          if (current.getReturnState(i) == PredictionContext.EMPTY_RETURN_STATE) {
            nodes.append(rootIsWildcard ? '*' : '$');
          }
        }
      } else {
        nodes.append(contextIds.get(current));
      }

      nodes.append("\"];\n");

      if (current.isEmpty()) {
        continue;
      }

      for (int i = 0; i < current.size(); i++) {
        if (current.getReturnState(i) == PredictionContext.EMPTY_RETURN_STATE) {
          continue;
        }

        if (visited.put(current.getParent(i), current.getParent(i)) == null) {
          contextIds.put(current.getParent(i), contextIds.size());
          workList.push(current.getParent(i));
        }

        edges.append("  s").append(contextIds.get(current));
        if (current.size() > 1) {
          edges.append(":p").append(i);
        }

        edges.append("->");
        edges.append('s').append(contextIds.get(current.getParent(i)));
        edges.append("[label=\"").append(current.getReturnState(i)).append("\"]");
        edges.append(";\n");
      }
    }

    StringBuilder builder = new StringBuilder();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.