Package org.antlr.v4.runtime.dfa

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


    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


    //System.out.println("visit "+s);
    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 {
          // must visit if not already visited; mark target, pop when done
          rulesVisitedPerRuleCheck.add((RuleStartState)t.target);
          // send new visitedStates set per rule invocation
          boolean nullable = check(r, t.target, new HashSet<ATNState>());
          // we're back from visiting that rule
          rulesVisitedPerRuleCheck.remove((RuleStartState)t.target);
          if ( nullable ) {
            stateReachesStopState |= check(enclosingRule, rt.followState, visitedStates);
          }
        }
      }
      else if ( t.isEpsilon() ) {
        stateReachesStopState |= check(enclosingRule, t.target, visitedStates);
      }
      // else ignore non-epsilon transitions
    }
    return stateReachesStopState;
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

    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

      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

      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

    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

  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

    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

    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

TOP

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

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.