Examples of Transition


Examples of org.antlr.analysis.Transition

    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

Examples of org.antlr.analysis.Transition

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

Examples of org.antlr.v4.runtime.atn.Transition

    int n = els.size();
    for (int i = 0; i < n - 1; i++) {  // hook up elements (visit all but last)
      Handle el = els.get(i);
      // if el is of form o-x->o for x in {rule, action, pred, token, ...}
      // and not last in alt
            Transition tr = null;
            if ( el.left.getNumberOfTransitions()==1 ) tr = el.left.transition(0);
            boolean isRuleTrans = tr instanceof RuleTransition;
            if ( el.left.getStateType() == ATNState.BASIC &&
        el.right.getStateType()== ATNState.BASIC &&
        tr!=null && (isRuleTrans && ((RuleTransition)tr).followState == el.right || tr.target == el.right) )
View Full Code Here

Examples of org.antlr.v4.runtime.atn.Transition

    ATNState eofTarget = newState(null); // one unique EOF target for all rules
    for (Rule r : g.rules.values()) {
      ATNState stop = atn.ruleToStopState[r.index];
      if ( stop.getNumberOfTransitions()>0 ) continue;
      n++;
      Transition t = new AtomTransition(eofTarget, Token.EOF);
      stop.addTransition(t);
    }
    return n;
  }
View Full Code Here

Examples of org.antlr.v4.runtime.atn.Transition

    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

Examples of org.antlr.v4.runtime.atn.Transition

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

Examples of org.antlr.v4.runtime.atn.Transition

    }
    else {
      edge = 1;
    }

    Transition transition = p.transition(edge - 1);
    switch (transition.getSerializationType()) {
    case Transition.EPSILON:
      if (pushRecursionContextStates.get(p.stateNumber) && !(transition.target instanceof LoopEndState)) {
        InterpreterRuleContext ctx = new InterpreterRuleContext(_parentContextStack.peek().a, _parentContextStack.peek().b, _ctx.getRuleIndex());
        pushNewRecursionContext(ctx, atn.ruleToStartState[p.ruleIndex].stateNumber, _ctx.getRuleIndex());
      }
      break;

    case Transition.ATOM:
      match(((AtomTransition)transition).label);
      break;

    case Transition.RANGE:
    case Transition.SET:
    case Transition.NOT_SET:
      if (!transition.matches(_input.LA(1), Token.MIN_USER_TOKEN_TYPE, 65535)) {
        _errHandler.recoverInline(this);
      }
      matchWildcard();
      break;
View Full Code Here

Examples of org.antlr.v4.runtime.atn.Transition

    }
    if ( invert ) {
      left.addTransition(new NotSetTransition(right, set));
    }
    else {
      Transition transition;
      if (set.getIntervals().size() == 1) {
        Interval interval = set.getIntervals().get(0);
        transition = new RangeTransition(right, interval.a, interval.b);
      } else {
        transition = new SetTransition(right, set);
View Full Code Here

Examples of org.antlr.v4.runtime.atn.Transition

      }
      if (q.getStateType() == ATNState.BASIC) {
        // we have p-x->q for x in {rule, action, pred, token, ...}
        // if edge out of q is single epsilon to block end
        // we can strip epsilon p-x->q-eps->r
        Transition trans = q.transition(0);
        if (q.getNumberOfTransitions() == 1 && trans instanceof EpsilonTransition) {
          ATNState r = trans.target;
          if (r instanceof BlockEndState || r instanceof PlusLoopbackState || r instanceof StarLoopbackState) {
            // skip over q
            if (p.transition(0) instanceof RuleTransition) {
View Full Code Here

Examples of org.antlr.v4.runtime.atn.Transition

      if ( marked.contains(s) ) continue;
      int n = s.getNumberOfTransitions();
//      System.out.println("visit "+s+"; edges="+n);
      marked.add(s);
      for (int i=0; i<n; i++) {
        Transition t = s.transition(i);
        if ( !(s instanceof RuleStopState) ) { // don't add follow states to work
          if ( t instanceof RuleTransition ) work.add(((RuleTransition)t).followState);
          else work.add( t.target );
        }
        buf.append(getStateString(s));
        if ( t instanceof EpsilonTransition ) {
          buf.append("->").append(getStateString(t.target)).append('\n');
        }
        else if ( t instanceof RuleTransition ) {
          buf.append("-").append(g.getRule(((RuleTransition)t).ruleIndex).name).append("->").append(getStateString(t.target)).append('\n');
        }
        else if ( t instanceof ActionTransition ) {
          ActionTransition a = (ActionTransition)t;
          buf.append("-").append(a.toString()).append("->").append(getStateString(t.target)).append('\n');
        }
        else if ( t instanceof SetTransition ) {
          SetTransition st = (SetTransition)t;
          boolean not = st instanceof NotSetTransition;
          if ( g.isLexer() ) {
            buf.append("-").append(not?"~":"").append(st.toString()).append("->").append(getStateString(t.target)).append('\n');
          }
          else {
            buf.append("-").append(not?"~":"").append(st.label().toString(g.getVocabulary())).append("->").append(getStateString(t.target)).append('\n');
          }
        }
        else if ( t instanceof AtomTransition ) {
          AtomTransition a = (AtomTransition)t;
          String label = g.getTokenDisplayName(a.label);
          buf.append("-").append(label).append("->").append(getStateString(t.target)).append('\n');
        }
        else {
          buf.append("-").append(t.toString()).append("->").append(getStateString(t.target)).append('\n');
        }
      }
    }
    return buf.toString();
  }
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.