Package org.antlr.v4.runtime.dfa

Examples of org.antlr.v4.runtime.dfa.DFA


  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

    ATNState eofTarget = newState(null); // one unique EOF target for all rules
    for (Rule r : g.rules.values()) {
      ATNState stop = atn.ruleToStopState[r.index];
      if ( stop.getNumberOfTransitions()>0 ) continue;
      n++;
      Transition t = new AtomTransition(eofTarget, Token.EOF);
      stop.addTransition(t);
    }
    return n;
  }
View Full Code Here

    visited.add(s.stateNumber);

    visitState(s);
    int n = s.getNumberOfTransitions();
    for (int i=0; i<n; i++) {
      Transition t = s.transition(i);
      visit_(t.target, visited);
    }
  }
View Full Code Here

  @NotNull
  @Override
  public Handle wildcard(@NotNull GrammarAST node) {
    ATNState left = newState(node);
    ATNState right = newState(node);
    left.addTransition(new WildcardTransition(right));
    node.atnState = left;
    return new Handle(left, right);
  }
View Full Code Here

  }

  @Override
  public void clearDFA() {
    for (int d = 0; d < decisionToDFA.length; d++) {
      decisionToDFA[d] = new DFA(atn.getDecisionState(d), d);
    }
  }
View Full Code Here

    }

    _input = input;
    _startIndex = input.index();
    _outerContext = outerContext;
    DFA dfa = decisionToDFA[decision];
    _dfa = dfa;

    int m = input.mark();
    int index = _startIndex;

    // Now we are certain to have a specific decision's DFA
    // But, do we still need an initial state?
    try {
      DFAState s0;
      if (dfa.isPrecedenceDfa()) {
        // the start state for a precedence DFA depends on the current
        // parser precedence, and is provided by a DFA method.
        s0 = dfa.getPrecedenceStartState(parser.getPrecedence());
      }
      else {
        // the start state for a "regular" DFA is just s0
        s0 = dfa.s0;
      }

      if (s0 == null) {
        if ( outerContext ==null ) outerContext = ParserRuleContext.EMPTY;
        if ( debug || debug_list_atn_decisions )  {
          System.out.println("predictATN decision "+ dfa.decision+
                     " exec LA(1)=="+ getLookaheadName(input) +
                     ", outerContext="+ outerContext.toString(parser));
        }

        /* If this is not a precedence DFA, we check the ATN start state
         * to determine if this ATN start state is the decision for the
         * closure block that determines whether a precedence rule
         * should continue or complete.
         */
        if (!dfa.isPrecedenceDfa() && dfa.atnStartState instanceof StarLoopEntryState) {
          if (((StarLoopEntryState)dfa.atnStartState).precedenceRuleDecision) {
            dfa.setPrecedenceDfa(true);
          }
        }

        boolean fullCtx = false;
        ATNConfigSet s0_closure =
          computeStartState(dfa.atnStartState,
                    ParserRuleContext.EMPTY,
                    fullCtx);

        if (dfa.isPrecedenceDfa()) {
          /* If this is a precedence DFA, we use applyPrecedenceFilter
           * to convert the computed start state to a precedence start
           * state. We then use DFA.setPrecedenceStartState to set the
           * appropriate start state for the precedence level rather
           * than simply setting DFA.s0.
           */
          s0_closure = applyPrecedenceFilter(s0_closure);
          s0 = addDFAState(dfa, new DFAState(s0_closure));
          dfa.setPrecedenceStartState(parser.getPrecedence(), s0);
        }
        else {
          s0 = addDFAState(dfa, new DFAState(s0_closure));
          dfa.s0 = s0;
        }
      }

      int alt = execATN(dfa, s0, input, index, outerContext);
      if ( debug ) System.out.println("DFA after predictATN: "+ dfa.toString(parser.getVocabulary()));
      return alt;
    }
    finally {
      mergeCache = null; // wack cache after each prediction
      _dfa = null;
View Full Code Here

    this.ruleNames = ruleNames.toArray(new String[ruleNames.size()]);
    this.vocabulary = vocabulary;
    this.decisionToDFA = new DFA[atn.getNumberOfDecisions()];
    for (int i = 0; i < decisionToDFA.length; i++) {
      decisionToDFA[i] = new DFA(atn.getDecisionState(i), i);
    }

    // identify the ATN states where pushNewRecursionContext must be called
    this.pushRecursionContextStates = new BitSet(atn.states.size());
    for (ATNState state : atn.states) {
View Full Code Here

    /** For debugging and other purposes. */
  public List<String> getDFAStrings() {
    synchronized (_interp.decisionToDFA) {
      List<String> s = new ArrayList<String>();
      for (int d = 0; d < _interp.decisionToDFA.length; d++) {
        DFA dfa = _interp.decisionToDFA[d];
        s.add( dfa.toString(getVocabulary()) );
      }
      return s;
    }
    }
View Full Code Here

TOP

Related Classes of org.antlr.v4.runtime.dfa.DFA

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.