Package org.antlr.analysis

Examples of org.antlr.analysis.Transition


        if(processedStates.contains(state))
            return;
        processedStates.add(state);

        for(int t=0; t<state.getNumberOfTransitions(); t++) {
            Transition transition = state.transition(t);
            addIncomingTransitionToState((NFAState)transition.target);
            recursiveAnalysis((NFAState)transition.target);
        }
    }
View Full Code Here


        }

        for(int t=0; t<state.getNumberOfTransitions(); t++) {
            FAState parentState = js;

            Transition transition = state.transition(t);
            NFAState target = (NFAState)transition.target;
            if(targetStateIsInAnotherRule(transition)) {
                target = targetStateOfTransition(transition);
                parentState = createRuleReferenceState(parentState, transition, null);
            }

            if(transition.isEpsilon()) {
                buildRecursiveSkipState(parentState, target, new HashSet<NFAState>(currentPath), new ArrayList<Integer>());
            } else {
                FAState targetState = buildRecursiveState(target, new HashSet<NFAState>(currentPath));
                if(targetState.loop) {
                    // Handle "loop" transition by creating a "normal" transition and assigning a flag
View Full Code Here

            Integer skippedState = state.stateNumber;
            skippedStates.add(skippedState);
            skippedStatesMap.put(skippedState, parentState);

            for(int t=0; t<state.getNumberOfTransitions(); t++) {
                Transition transition = state.transition(t);
                if(targetStateIsInAnotherRule(transition)) {
                    NFAState target = targetStateOfTransition(transition);
                    FAState ruleRefState = createRuleReferenceState(parentState, transition, skippedStates);
                    buildRecursiveSkipState(ruleRefState, target, currentPath, new ArrayList<Integer>(skippedStates));
                } else
View Full Code Here

        return state.getNumberOfTransitions() == 1 && state.transition(0).isEpsilon();
    }

    public boolean hasOneOrMoreEpsilonTransitionOnly(NFAState state) {
        for(int t=0; t<state.getNumberOfTransitions(); t++) {
            Transition transition = state.transition(t);
            if(!transition.isEpsilon())
                return false;
        }
        return state.getNumberOfTransitions()>0;
    }
View Full Code Here

        return state.getNumberOfTransitions()>0;
    }

    public boolean hasMoreThanOneEpsilonTransitionOnly(NFAState state) {
        for(int t=0; t<state.getNumberOfTransitions(); t++) {
            Transition transition = state.transition(t);
            if(!transition.isEpsilon())
                return false;
        }
        return state.getNumberOfTransitions()>1;
    }
View Full Code Here

    public boolean isAlternativeTransitionEndingAtSameState(NFAState state) {
        NFAState endState = endStateOfAlternative((NFAState)state.transition(0).target);

        for(int t=1; t<state.getNumberOfTransitions(); t++) {
            Transition transition = state.transition(t);
            NFAState newEndState = endStateOfAlternative((NFAState)transition.target);
            if(!endState.equals(newEndState))
                return false;
        }
        return true;
View Full Code Here

        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

    while ( p!=null ) {
      if ( n==alt ) {
        return p;
      }
      n++;
      Transition next = p.transition[1];
      p = null;
      if ( next!=null ) {
        p = (NFAState)next.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<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.