Examples of DFA


Examples of org.antlr.analysis.DFA

        Grammar g = new Grammar(
                "lexer grammar t;\n"+
                "A : 'a' 'b' | 'a' 'c' | 'd' 'e' ;");
    g.buildNFA();
        g.createLookaheadDFAs(false);
        DFA dfa = g.getLookaheadDFA(1);
        checkPrediction(dfa,"ab",1);
        checkPrediction(dfa,"ac",2);
        checkPrediction(dfa,"de",3);
        checkPrediction(dfa,"q", NFA.INVALID_ALT_NUMBER);
    }
View Full Code Here

Examples of org.antlr.analysis.DFA

                "lexer grammar t;\n"+
                "A : (DIGIT)+ '.' DIGIT | (DIGIT)+ ;\n" +
                "fragment DIGIT : '0'..'9' ;\n");
    g.buildNFA();
        g.createLookaheadDFAs(false);
        DFA dfa = g.getLookaheadDFA(3);
        checkPrediction(dfa,"32",2);
        checkPrediction(dfa,"999.2",1);
        checkPrediction(dfa,".2", NFA.INVALID_ALT_NUMBER);
    }
View Full Code Here

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

  }

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

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

    }

    _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

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

    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

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

    /** 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

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

  /** For debugging and other purposes. */
  public void dumpDFA() {
    synchronized (_interp.decisionToDFA) {
      boolean seenOne = false;
      for (int d = 0; d < _interp.decisionToDFA.length; d++) {
        DFA dfa = _interp.decisionToDFA[d];
        if ( !dfa.states.isEmpty() ) {
          if ( seenOne ) System.out.println();
          System.out.println("Decision " + dfa.decision + ":");
          System.out.print(dfa.toString(getVocabulary()));
          seenOne = true;
        }
      }
    }
    }
View Full Code Here

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

    this.modeNames = modeNames.toArray(new String[modeNames.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);
    }
    this._interp = new LexerATNSimulator(this,atn,_decisionToDFA,_sharedContextCache);
  }
View Full Code Here

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

  /**
   * Gets the total number of DFA states stored in the DFA cache for a
   * particular decision.
   */
  public int getDFASize(int decision) {
    DFA decisionToDFA = atnSimulator.decisionToDFA[decision];
    return decisionToDFA.states.size();
  }
View Full Code Here

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

    this.mode = mode;
    int mark = input.mark();
    try {
      this.startIndex = input.index();
      this.prevAccept.reset();
      DFA dfa = decisionToDFA[mode];
      if ( dfa.s0==null ) {
        return matchATN(input);
      }
      else {
        return execATN(input, dfa.s0);
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.