Package org.antlr.v4.automata

Examples of org.antlr.v4.automata.ATNOptimizer


    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

    int n = s.getNumberOfTransitions();
    boolean stateReachesStopState = false;
    for (int i=0; i<n; i++) {
      Transition t = s.transition(i);
      if ( t instanceof RuleTransition ) {
        RuleTransition rt = (RuleTransition) t;
        Rule r = g.getRule(rt.ruleIndex);
        if ( rulesVisitedPerRuleCheck.contains((RuleStartState)t.target) ) {
          addRulesToCycle(enclosingRule, r);
        }
        else {
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

   * {@code (A|B)*} is not the same thing as {@code (A|B|)+}.
   */
  @NotNull
  @Override
  public Handle star(@NotNull GrammarAST starAST, @NotNull Handle elem) {
    StarBlockStartState blkStart = (StarBlockStartState)elem.left;
    BlockEndState blkEnd = (BlockEndState)elem.right;
    preventEpsilonClosureBlocks.add(new Triple<Rule, ATNState, ATNState>(currentRule, blkStart, blkEnd));

    StarLoopEntryState entry = newState(StarLoopEntryState.class, starAST);
    entry.nonGreedy = !((QuantifierAST)starAST).isGreedy();
View Full Code Here

  public Handle star(@NotNull GrammarAST starAST, @NotNull Handle elem) {
    StarBlockStartState blkStart = (StarBlockStartState)elem.left;
    BlockEndState blkEnd = (BlockEndState)elem.right;
    preventEpsilonClosureBlocks.add(new Triple<Rule, ATNState, ATNState>(currentRule, blkStart, blkEnd));

    StarLoopEntryState entry = newState(StarLoopEntryState.class, starAST);
    entry.nonGreedy = !((QuantifierAST)starAST).isGreedy();
    atn.defineDecisionState(entry);
    LoopEndState end = newState(LoopEndState.class, starAST);
    StarLoopbackState loop = newState(StarLoopbackState.class, starAST);
    entry.loopBackState = loop;
View Full Code Here

    StarLoopEntryState entry = newState(StarLoopEntryState.class, starAST);
    entry.nonGreedy = !((QuantifierAST)starAST).isGreedy();
    atn.defineDecisionState(entry);
    LoopEndState end = newState(LoopEndState.class, starAST);
    StarLoopbackState loop = newState(StarLoopbackState.class, starAST);
    entry.loopBackState = loop;
    end.loopBackState = loop;

    BlockAST blkAST = (BlockAST)starAST.getChild(0);
    if ( ((QuantifierAST)starAST).isGreedy() ) {
View Full Code Here

    int n = els.size();
    for (int i = 0; i < n - 1; i++) {  // hook up elements (visit all but last)
      Handle el = els.get(i);
      // if el is of form o-x->o for x in {rule, action, pred, token, ...}
      // and not last in alt
            Transition tr = null;
            if ( el.left.getNumberOfTransitions()==1 ) tr = el.left.transition(0);
            boolean isRuleTrans = tr instanceof RuleTransition;
            if ( el.left.getStateType() == ATNState.BASIC &&
        el.right.getStateType()== ATNState.BASIC &&
        tr!=null && (isRuleTrans && ((RuleTransition)tr).followState == el.right || tr.target == el.right) )
View Full Code Here

TOP

Related Classes of org.antlr.v4.automata.ATNOptimizer

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.