Package org.antlr.analysis

Examples of org.antlr.analysis.NFAState


    //System.out.println("### create DFAs");
    int numDecisions = getNumberOfDecisions();
    if ( NFAToDFAConverter.SINGLE_THREADED_NFA_CONVERSION ) {
      for (int decision=1; decision<=numDecisions; decision++) {
        NFAState decisionStartState = getDecisionNFAStartState(decision);
        if ( leftRecursiveRules.contains(decisionStartState.enclosingRule) ) {
          // don't bother to process decisions within left recursive rules.
          if ( composite.watchNFAConversion ) {
            System.out.println("ignoring decision "+decision+
                       " within left-recursive rule "+decisionStartState.enclosingRule.name);
          }
          continue;
        }
        if ( !externalAnalysisAbort && decisionStartState.getNumberOfTransitions()>1 ) {
          Rule r = decisionStartState.enclosingRule;
          if ( r.isSynPred && !synPredNamesUsedInDFA.contains(r.name) ) {
            continue;
          }
          DFA dfa = null;
View Full Code Here


  public DFA createLL_1_LookaheadDFA(int decision) {
    Decision d = getDecision(decision);
    String enclosingRule = d.startState.enclosingRule.name;
    Rule r = d.startState.enclosingRule;
    NFAState decisionStartState = getDecisionNFAStartState(decision);

    if ( composite.watchNFAConversion ) {
      System.out.println("--------------------\nattempting LL(1) DFA (d="
                 +decisionStartState.getDecisionNumber()+") for "+
                 decisionStartState.getDescription());
    }

    if ( r.isSynPred && !synPredNamesUsedInDFA.contains(enclosingRule) ) {
      return null;
    }

    // compute lookahead for each alt
    int numAlts = getNumberOfAltsForDecisionNFA(decisionStartState);
    LookaheadSet[] altLook = new LookaheadSet[numAlts+1];
    for (int alt = 1; alt <= numAlts; alt++) {
      int walkAlt =
        decisionStartState.translateDisplayAltToWalkAlt(alt);
      NFAState altLeftEdge = getNFAStateForAltOfDecision(decisionStartState, walkAlt);
      NFAState altStartState = (NFAState)altLeftEdge.transition[0].target;
      //System.out.println("alt "+alt+" start state = "+altStartState.stateNumber);
      altLook[alt] = ll1Analyzer.LOOK(altStartState);
      //System.out.println("alt "+alt+": "+altLook[alt].toString(this));
    }
View Full Code Here

    Decision d = getDecision(decision);
    String enclosingRule = d.startState.enclosingRule.name;
    Rule r = d.startState.enclosingRule;

    //System.out.println("createLookaheadDFA(): "+enclosingRule+" dec "+decision+"; synprednames prev used "+synPredNamesUsedInDFA);
    NFAState decisionStartState = getDecisionNFAStartState(decision);
    long startDFA=0,stopDFA;
    if ( composite.watchNFAConversion ) {
      System.out.println("--------------------\nbuilding lookahead DFA (d="
                 +decisionStartState.getDecisionNumber()+") for "+
                 decisionStartState.getDescription());
      startDFA = System.currentTimeMillis();
    }

    DFA lookaheadDFA = new DFA(decision, decisionStartState);
    // Retry to create a simpler DFA if analysis failed (non-LL(*),
 
View Full Code Here

    }
    return user_k;
  }

  public boolean getAutoBacktrackMode(int decision) {
    NFAState decisionNFAStartState = getDecisionNFAStartState(decision);
    String autoBacktrack =
      (String)getBlockOption(decisionNFAStartState.associatedASTNode, "backtrack");

    if ( autoBacktrack==null ) {
      autoBacktrack = (String)nfa.grammar.getOption("backtrack");
View Full Code Here

  public int getNumberOfAltsForDecisionNFA(NFAState decisionState) {
    if ( decisionState==null ) {
      return 0;
    }
    int n = 1;
    NFAState p = decisionState;
    while ( p.transition[1] !=null ) {
      n++;
      p = (NFAState)p.transition[1].target;
    }
    return n;
View Full Code Here

  public NFAState getNFAStateForAltOfDecision(NFAState decisionState, int alt) {
    if ( decisionState==null || alt<=0 ) {
      return null;
    }
    int n = 1;
    NFAState p = decisionState;
    while ( p!=null ) {
      if ( n==alt ) {
        return p;
      }
      n++;
View Full Code Here

                             listOfRecursiveCycles);
        // we're back from visiting that rule
        visitedDuringRecursionCheck.remove(refRuleDef);
        // must keep going in this rule then
        if ( callReachedAcceptState ) {
          NFAState followingState =
            ((RuleClosureTransition) t0).followState;
          stateReachesAcceptState |=
            traceStatesLookingForLeftRecursion(followingState,
                               visitedStates,
                               listOfRecursiveCycles);
View Full Code Here

      for (int i = 0; i < alts.size(); i++) {
        Integer altI = alts.get(i);
        String tokenName =
          probe.getTokenNameForTokensRuleAlt(altI);
        // reset the line/col to the token definition
        NFAState ruleStart =
          probe.dfa.nfa.grammar.getRuleStartState(tokenName);
        line = ruleStart.associatedASTNode.getLine();
        column = ruleStart.associatedASTNode.getCharPositionInLine();
        st.add("tokens", tokenName);
      }
View Full Code Here

                             listOfRecursiveCycles);
        // we're back from visiting that rule
        visitedDuringRecursionCheck.remove(refRuleDef);
        // must keep going in this rule then
        if ( callReachedAcceptState ) {
          NFAState followingState =
            ((RuleClosureTransition) t0).followState;
          stateReachesAcceptState |=
            traceStatesLookingForLeftRecursion(followingState,
                               visitedStates,
                               listOfRecursiveCycles);
View Full Code Here

      for (int i = 0; i < alts.size(); i++) {
        Integer altI = (Integer) alts.get(i);
        String tokenName =
          probe.getTokenNameForTokensRuleAlt(altI.intValue());
        // reset the line/col to the token definition
        NFAState ruleStart =
          probe.dfa.nfa.grammar.getRuleStartState(tokenName);
        line = ruleStart.associatedASTNode.getLine();
        column = ruleStart.associatedASTNode.getCharPositionInLine();
        st.add("tokens", tokenName);
      }
View Full Code Here

TOP

Related Classes of org.antlr.analysis.NFAState

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.