Package org.antlr.analysis

Examples of org.antlr.analysis.Transition


        state = invokingTransition.followState;
        continue;
      }
      if ( state.getNumberOfTransitions()==1 ) {
        // no branching, just take this path
        Transition t0 = state.transition[0];
        if ( t0 instanceof RuleClosureTransition ) {
          ruleInvocationStack.push(state);
          if ( debug ) System.out.println("push state "+state);
          //System.out.println("call "+((RuleClosureTransition)t0).rule.name);
          //System.out.println("stack depth="+ruleInvocationStack.size());
        }
        else if ( t0.label.isSet() || t0.label.isAtom() ) {
          tokenTypes.add( getTokenType(t0.label) );
        }
        state = (NFAState)t0.target;
        continue;
      }

      int decisionNumber = state.getDecisionNumber();
      if ( decisionNumber==0 ) {
        System.out.println("weird: no decision number but a choice node");
        continue;
      }
      // decision point, pick ith alternative randomly
      int n = g.getNumberOfAltsForDecisionNFA(state);
      int randomAlt = random.nextInt(n) + 1;
      if ( debug ) System.out.println("randomAlt="+randomAlt);
      NFAState altStartState =
        g.getNFAStateForAltOfDecision(state, randomAlt);
      Transition t = altStartState.transition[0];
      state = (NFAState)t.target;
    }
  }
View Full Code Here


      // within same rule, we've hit same state; quit looping
      return false;
    }
    visitedStates.add(s);
    boolean stateReachesAcceptState = false;
    Transition t0 = s.transition[0];
    if ( t0 instanceof RuleClosureTransition ) {
      RuleClosureTransition refTrans = (RuleClosureTransition)t0;
      Rule refRuleDef = refTrans.rule;
      //String targetRuleName = ((NFAState)t0.target).getEnclosingRule();
      if ( visitedDuringRecursionCheck.contains(refRuleDef) ) {
        // record left-recursive rule, but don't go back in
        grammar.leftRecursiveRules.add(refRuleDef);
        /*
        System.out.println("already visited "+refRuleDef+", calling from "+
                   s.enclosingRule);
                   */
        addRulesToCycle(refRuleDef,
                s.enclosingRule,
                listOfRecursiveCycles);
      }
      else {
        // must visit if not already visited; send new visitedStates set
        visitedDuringRecursionCheck.add(refRuleDef);
        boolean callReachedAcceptState =
          traceStatesLookingForLeftRecursion((NFAState)t0.target,
                             new HashSet(),
                             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);
        }
      }
    }
    else if ( t0.label.isEpsilon() || t0.label.isSemanticPredicate() ) {
      stateReachesAcceptState |=
        traceStatesLookingForLeftRecursion((NFAState)t0.target, visitedStates, listOfRecursiveCycles);
    }
    // else it has a labeled edge

    // now do the other transition if it exists
    Transition t1 = s.transition[1];
    if ( t1!=null ) {
      stateReachesAcceptState |=
        traceStatesLookingForLeftRecursion((NFAState)t1.target,
                           visitedStates,
                           listOfRecursiveCycles);
View Full Code Here

      // within same rule, we've hit same state; quit looping
      return false;
    }
    visitedStates.add(s);
    boolean stateReachesAcceptState = false;
    Transition t0 = s.transition(0);
    if ( t0 instanceof RuleClosureTransition ) {
      String targetRuleName = ((NFAState)t0.target).getEnclosingRule();
      if ( grammar.visitedDuringRecursionCheck.contains(targetRuleName) ) {
        // record left-recursive rule, but don't go back in
        grammar.leftRecursiveRules.add(targetRuleName);
        /*
        System.out.println("already visited "+targetRuleName+", calling from "+
                   s.getEnclosingRule());
        */
        addRulesToCycle(targetRuleName,
                s.getEnclosingRule(),
                listOfRecursiveCycles);
      }
      else {
        // must visit if not already visited; send new visitedStates set
        grammar.visitedDuringRecursionCheck.add(targetRuleName);
        boolean callReachedAcceptState =
          traceStatesLookingForLeftRecursion((NFAState)t0.target,
                             new HashSet(),
                             listOfRecursiveCycles);
        // we're back from visiting that rule
        grammar.visitedDuringRecursionCheck.remove(targetRuleName);
        // must keep going in this rule then
        if ( callReachedAcceptState ) {
          NFAState followingState =
            ((RuleClosureTransition)t0).getFollowState();
          stateReachesAcceptState |=
            traceStatesLookingForLeftRecursion(followingState,
                               visitedStates,
                               listOfRecursiveCycles);
        }
      }
    }
    else if ( t0.label.isEpsilon() ) {
      stateReachesAcceptState |=
        traceStatesLookingForLeftRecursion((NFAState)t0.target, visitedStates, listOfRecursiveCycles);
    }
    // else it has a labeled edge

    // now do the other transition if it exists
    Transition t1 = s.transition(1);
    if ( t1!=null ) {
      stateReachesAcceptState |=
        traceStatesLookingForLeftRecursion((NFAState)t1.target,
                           visitedStates,
                           listOfRecursiveCycles);
View Full Code Here

        state = invokingTransition.getFollowState();
        continue;
      }
      if ( state.getNumberOfTransitions()==1 ) {
        // no branching, just take this path
        Transition t0 = state.transition(0);
        if ( t0 instanceof RuleClosureTransition ) {
          ruleInvocationStack.push(state);
          // System.out.println("push state "+state);
          int ruleIndex = ((RuleClosureTransition)t0).getRuleIndex();
          //System.out.println("invoke "+g.getRuleName(ruleIndex));
        }
        else if ( !t0.label.isEpsilon() ) {
          tokenTypes.add( getTokenType(t0.label) );
          //System.out.println(t0.label.toString(g));
        }
        state = (NFAState)t0.target;
        continue;
      }

      int decisionNumber = state.getDecisionNumber();
      if ( decisionNumber==0 ) {
        System.out.println("weird: no decision number but a choice node");
        continue;
      }
      // decision point, pick ith alternative randomly
      int n = g.getNumberOfAltsForDecisionNFA(state);
      int randomAlt = random.nextInt(n) + 1;
      //System.out.println("randomAlt="+randomAlt);
      NFAState altStartState =
        g.getNFAStateForAltOfDecision(state, randomAlt);
      Transition t = altStartState.transition(0);
      /*
      start of a decision could never be a labeled transition
      if ( !t.label.isEpsilon() ) {
        tokenTypes.add( getTokenType(t.label) );
      }
View Full Code Here

      // within same rule, we've hit same state; quit looping
      return false;
    }
    visitedStates.add(s);
    boolean stateReachesAcceptState = false;
    Transition t0 = s.transition[0];
    if ( t0 instanceof RuleClosureTransition ) {
      RuleClosureTransition refTrans = (RuleClosureTransition)t0;
      Rule refRuleDef = refTrans.rule;
      //String targetRuleName = ((NFAState)t0.target).getEnclosingRule();
      if ( visitedDuringRecursionCheck.contains(refRuleDef) ) {
        // record left-recursive rule, but don't go back in
        grammar.leftRecursiveRules.add(refRuleDef);
        /*
        System.out.println("already visited "+refRuleDef+", calling from "+
                   s.enclosingRule);
                   */
        addRulesToCycle(refRuleDef,
                s.enclosingRule,
                listOfRecursiveCycles);
      }
      else {
        // must visit if not already visited; send new visitedStates set
        visitedDuringRecursionCheck.add(refRuleDef);
        boolean callReachedAcceptState =
          traceStatesLookingForLeftRecursion((NFAState)t0.target,
                             new HashSet<NFAState>(),
                             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);
        }
      }
    }
    else if ( t0.label.isEpsilon() || t0.label.isSemanticPredicate() ) {
      stateReachesAcceptState |=
        traceStatesLookingForLeftRecursion((NFAState)t0.target, visitedStates, listOfRecursiveCycles);
    }
    // else it has a labeled edge

    // now do the other transition if it exists
    Transition t1 = s.transition[1];
    if ( t1!=null ) {
      stateReachesAcceptState |=
        traceStatesLookingForLeftRecursion((NFAState)t1.target,
                           visitedStates,
                           listOfRecursiveCycles);
View Full Code Here

      // within same rule, we've hit same state; quit looping
      return false;
    }
    visitedStates.add(s);
    boolean stateReachesAcceptState = false;
    Transition t0 = s.transition[0];
    if ( t0 instanceof RuleClosureTransition ) {
      RuleClosureTransition refTrans = (RuleClosureTransition)t0;
      Rule refRuleDef = refTrans.rule;
      //String targetRuleName = ((NFAState)t0.target).getEnclosingRule();
      if ( visitedDuringRecursionCheck.contains(refRuleDef) ) {
        // record left-recursive rule, but don't go back in
        grammar.leftRecursiveRules.add(refRuleDef);
        /*
        System.out.println("already visited "+refRuleDef+", calling from "+
                   s.enclosingRule);
                   */
        addRulesToCycle(refRuleDef,
                s.enclosingRule,
                listOfRecursiveCycles);
      }
      else {
        // must visit if not already visited; send new visitedStates set
        visitedDuringRecursionCheck.add(refRuleDef);
        boolean callReachedAcceptState =
          traceStatesLookingForLeftRecursion((NFAState)t0.target,
                             new HashSet(),
                             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);
        }
      }
    }
    else if ( t0.label.isEpsilon() || t0.label.isSemanticPredicate() ) {
      stateReachesAcceptState |=
        traceStatesLookingForLeftRecursion((NFAState)t0.target, visitedStates, listOfRecursiveCycles);
    }
    // else it has a labeled edge

    // now do the other transition if it exists
    Transition t1 = s.transition[1];
    if ( t1!=null ) {
      stateReachesAcceptState |=
        traceStatesLookingForLeftRecursion((NFAState)t1.target,
                           visitedStates,
                           listOfRecursiveCycles);
View Full Code Here

TOP

Related Classes of org.antlr.analysis.Transition

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.