Examples of DFAState


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

    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);
View Full Code Here

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

      System.out.println("execATN decision "+dfa.decision+
                 " exec LA(1)=="+ getLookaheadName(input)+
                 " line "+input.LT(1).getLine()+":"+input.LT(1).getCharPositionInLine());
    }

    DFAState previousD = s0;

    if ( debug ) System.out.println("s0 = "+s0);

    int t = input.LA(1);

    while (true) { // while more work
      DFAState D = getExistingTargetState(previousD, t);
      if (D == null) {
        D = computeTargetState(dfa, previousD, t);
      }

      if (D == ERROR) {
View Full Code Here

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

      addDFAEdge(dfa, previousD, t, ERROR);
      return ERROR;
    }

    // create new target state; we'll add to DFA after it's complete
    DFAState D = new DFAState(reach);

    int predictedAlt = getUniqueAlt(reach);

    if ( debug ) {
      Collection<BitSet> altSubSets = PredictionMode.getConflictingAltSubsets(reach);
View Full Code Here

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

    if (D == ERROR) {
      return D;
    }

    synchronized (dfa.states) {
      DFAState existing = dfa.states.get(D);
      if ( existing!=null ) return existing;

      D.stateNumber = dfa.states.size();
      if (!D.configs.isReadonly()) {
        D.configs.optimizeConfigs(this);
View Full Code Here

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

  protected DFAState getExistingTargetState(DFAState previousD, int t) {
    // this method is called after each time the input position advances
    // during SLL prediction
    _sllStopIndex = _input.index();

    DFAState existingTargetState = super.getExistingTargetState(previousD, t);
    if ( existingTargetState!=null ) {
      decisions[currentDecision].SLL_DFATransitions++; // count only if we transition over a DFA state
      if ( existingTargetState==ERROR ) {
        decisions[currentDecision].errors.add(
            new ErrorInfo(currentDecision, previousD.configs, _input, _startIndex, _sllStopIndex, false)
View Full Code Here

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

    return existingTargetState;
  }

  @Override
  protected DFAState computeTargetState(DFA dfa, DFAState previousD, int t) {
    DFAState state = super.computeTargetState(dfa, previousD, t);
    currentState = state;
    return state;
  }
View Full Code Here

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

    ATNConfigSet s0_closure = computeStartState(input, startState);
    boolean suppressEdge = s0_closure.hasSemanticContext;
    s0_closure.hasSemanticContext = false;

    DFAState next = addDFAState(s0_closure);
    if (!suppressEdge) {
      decisionToDFA[mode].s0 = next;
    }

    int predict = execATN(input, next);
View Full Code Here

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

      // allow zero-length tokens
      captureSimState(prevAccept, input, ds0);
    }

    int t = input.LA(1);
    @NotNull
    DFAState s = ds0; // s is current/from DFA state

    while ( true ) { // while more work
      if ( debug ) {
        System.out.format(Locale.getDefault(), "execATN loop starting closure: %s\n", s.configs);
      }

      // As we move src->trg, src->trg, we keep track of the previous trg to
      // avoid looking up the DFA state again, which is expensive.
      // If the previous target was already part of the DFA, we might
      // be able to avoid doing a reach operation upon t. If s!=null,
      // it means that semantic predicates didn't prevent us from
      // creating a DFA state. Once we know s!=null, we check to see if
      // the DFA state has an edge already for t. If so, we can just reuse
      // it's configuration set; there's no point in re-computing it.
      // This is kind of like doing DFA simulation within the ATN
      // simulation because DFA simulation is really just a way to avoid
      // computing reach/closure sets. Technically, once we know that
      // we have a previously added DFA state, we could jump over to
      // the DFA simulator. But, that would mean popping back and forth
      // a lot and making things more complicated algorithmically.
      // This optimization makes a lot of sense for loops within DFA.
      // A character will take us back to an existing DFA state
      // that already has lots of edges out of it. e.g., .* in comments.
      DFAState target = getExistingTargetState(s, t);
      if (target == null) {
        target = computeTargetState(input, s, t);
      }

      if (target == ERROR) {
View Full Code Here

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

  protected DFAState getExistingTargetState(@NotNull DFAState s, int t) {
    if (s.edges == null || t < MIN_DFA_EDGE || t > MAX_DFA_EDGE) {
      return null;
    }

    DFAState target = s.edges[t - MIN_DFA_EDGE];
    if (debug && target != null) {
      System.out.println("reuse state "+s.stateNumber+
                 " edge to "+target.stateNumber);
    }
View Full Code Here

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

     * state, we can continue in pure DFA mode from there.
     */
    boolean suppressEdge = q.hasSemanticContext;
    q.hasSemanticContext = false;

    @NotNull
    DFAState to = addDFAState(q);

    if (suppressEdge) {
      return to;
    }
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.