Package org.antlr.v4.runtime.atn

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


  /* start->ruleblock->end */
  @NotNull
  @Override
  public Handle rule(@NotNull GrammarAST ruleAST, @NotNull String name, @NotNull Handle blk) {
    Rule r = g.getRule(name);
    RuleStartState start = atn.ruleToStartState[r.index];
    epsilon(start, blk.left);
    RuleStopState stop = atn.ruleToStopState[r.index];
    epsilon(blk.right, stop);
    Handle h = new Handle(start, stop);
//    ATNPrinter ser = new ATNPrinter(g, h.left);
View Full Code Here

    Rule r = g.getRule(node.getText());
    if ( r==null ) {
      g.tool.errMgr.grammarError(ErrorType.INTERNAL_ERROR, g.fileName, node.getToken(), "Rule "+node.getText()+" undefined");
      return null;
    }
    RuleStartState start = atn.ruleToStartState[r.index];
    ATNState left = newState(node);
    ATNState right = newState(node);
    int precedence = 0;
    if (((GrammarASTWithOptions)node).getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME) != null) {
      precedence = Integer.parseInt(((GrammarASTWithOptions)node).getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME));
View Full Code Here

   */
  void createRuleStartAndStopATNStates() {
    atn.ruleToStartState = new RuleStartState[g.rules.size()];
    atn.ruleToStopState = new RuleStopState[g.rules.size()];
    for (Rule r : g.rules.values()) {
      RuleStartState start = newState(RuleStartState.class, r.ast);
      RuleStopState stop = newState(RuleStopState.class, r.ast);
      start.stopState = stop;
      start.isPrecedenceRule = r instanceof LeftRecursiveRule;
      start.setRuleIndex(r.index);
      stop.setRuleIndex(r.index);
      atn.ruleToStartState[r.index] = start;
      atn.ruleToStopState[r.index] = stop;
    }
  }
View Full Code Here

  @Override
  public Handle rule(@NotNull GrammarAST ruleAST, @NotNull String name, @NotNull Handle blk) {
    Rule r = g.getRule(name);
    RuleStartState start = atn.ruleToStartState[r.index];
    epsilon(start, blk.left);
    RuleStopState stop = atn.ruleToStopState[r.index];
    epsilon(blk.right, stop);
    Handle h = new Handle(start, stop);
//    ATNPrinter ser = new ATNPrinter(g, h.left);
//    System.out.println(ruleAST.toStringTree()+":\n"+ser.asString());
    ruleAST.atnState = start;
View Full Code Here

    return new Handle(left, right);
  }

  public void addFollowLink(int ruleIndex, ATNState right) {
    // add follow edge from end of invoked rule
    RuleStopState stop = atn.ruleToStopState[ruleIndex];
//        System.out.println("add follow link from "+ruleIndex+" to "+right);
    epsilon(stop, right);
  }
View Full Code Here

  void createRuleStartAndStopATNStates() {
    atn.ruleToStartState = new RuleStartState[g.rules.size()];
    atn.ruleToStopState = new RuleStopState[g.rules.size()];
    for (Rule r : g.rules.values()) {
      RuleStartState start = newState(RuleStartState.class, r.ast);
      RuleStopState stop = newState(RuleStopState.class, r.ast);
      start.stopState = stop;
      start.isPrecedenceRule = r instanceof LeftRecursiveRule;
      start.setRuleIndex(r.index);
      stop.setRuleIndex(r.index);
      atn.ruleToStartState[r.index] = start;
      atn.ruleToStopState[r.index] = stop;
    }
  }
View Full Code Here

    ATNState right = newState(node);
    int precedence = 0;
    if (((GrammarASTWithOptions)node).getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME) != null) {
      precedence = Integer.parseInt(((GrammarASTWithOptions)node).getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME));
    }
    RuleTransition call = new RuleTransition(start, r.index, precedence, right);
    left.addTransition(call);

    node.atnState = left;
    return new Handle(left, right);
  }
View Full Code Here

        for (ATNState p : atn.states) {
            if ( p!=null &&
                 p.getStateType() == ATNState.BASIC && p.getNumberOfTransitions()==1 &&
                 p.transition(0) instanceof RuleTransition )
            {
                RuleTransition rt = (RuleTransition) p.transition(0);
                addFollowLink(rt.ruleIndex, rt.followState);
            }
        }
    }
View Full Code Here

    }
    if ( invert ) {
      left.addTransition(new NotSetTransition(right, set));
    }
    else {
      left.addTransition(new SetTransition(right, set));
    }
    associatedAST.atnState = left;
    return new Handle(left, right);
  }
View Full Code Here

TOP

Related Classes of org.antlr.v4.runtime.atn.PredictionContext

Copyright © 2018 www.massapicom. 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.