当前位置: 首页>>代码示例>>Java>>正文


Java ATNState.getNumberOfTransitions方法代码示例

本文整理汇总了Java中org.antlr.v4.runtime.atn.ATNState.getNumberOfTransitions方法的典型用法代码示例。如果您正苦于以下问题:Java ATNState.getNumberOfTransitions方法的具体用法?Java ATNState.getNumberOfTransitions怎么用?Java ATNState.getNumberOfTransitions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.antlr.v4.runtime.atn.ATNState的用法示例。


在下文中一共展示了ATNState.getNumberOfTransitions方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visitState

import org.antlr.v4.runtime.atn.ATNState; //导入方法依赖的package包/类
@Override
protected void visitState(ATNState p) {
    super.visitState(p);

    if (p.getNumberOfTransitions() > 1) {
        return;
    }

    Transition transition = p.transition(0);
    if (transition instanceof RuleTransition) {
        // rule transition created a new context
        associatedTransitions.put(_ctx, transition);
    }
    else if (!p.onlyHasEpsilonTransitions()) {
        // match transition created a new terminal or error node
        associatedTransitions.put(_ctx.getChild(_ctx.getChildCount() - 1), transition);
    }
}
 
开发者ID:tunnelvisionlabs,项目名称:goworks,代码行数:19,代码来源:ParserDebuggerReferenceAnchorsParserTask.java

示例2: visitState

import org.antlr.v4.runtime.atn.ATNState; //导入方法依赖的package包/类
@Override
public void visitState(ATNState p) {
	if (p.getStateType() == ATNState.BASIC && p.getNumberOfTransitions() == 1) {
		ATNState q = p.transition(0).target;
		if (p.transition(0) instanceof RuleTransition) {
			q = ((RuleTransition) p.transition(0)).followState;
		}
		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) {
						((RuleTransition) p.transition(0)).followState = r;
					} else {
						p.transition(0).target = r;
					}
					_atn.removeState(q);
				}
			}
		}
	}
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:28,代码来源:TailEpsilonRemover.java

示例3: visit_

import org.antlr.v4.runtime.atn.ATNState; //导入方法依赖的package包/类
public void visit_(ATNState s, Set<Integer> visited) {
	if ( !visited.add(s.stateNumber) ) return;
	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);
	}
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:12,代码来源:ATNVisitor.java

示例4: addRuleFollowLinks

import org.antlr.v4.runtime.atn.ATNState; //导入方法依赖的package包/类
public void addRuleFollowLinks() {
    for (ATNState p : atn.states) {
        if ( p!=null &&
             p.getStateType() == ATNState.BASIC && p.getNumberOfTransitions()==1 &&
             p.transition(0) instanceof RuleTransition )
        {
            RuleTransition rt = (RuleTransition) p.transition(0);
            addFollowLink(rt.ruleIndex, rt.followState);
        }
    }
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:12,代码来源:ParserATNFactory.java

示例5: addEOFTransitionToStartRules

import org.antlr.v4.runtime.atn.ATNState; //导入方法依赖的package包/类
/** Add an EOF transition to any rule end ATNState that points to nothing
    *  (i.e., for all those rules not invoked by another rule).  These
    *  are start symbols then.
 *
 *  Return the number of grammar entry points; i.e., how many rules are
 *  not invoked by another rule (they can only be invoked from outside).
 *  These are the start rules.
    */
public int addEOFTransitionToStartRules() {
	int n = 0;
	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;
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:21,代码来源:ParserATNFactory.java

示例6: check

import org.antlr.v4.runtime.atn.ATNState; //导入方法依赖的package包/类
/** From state s, look for any transition to a rule that is currently
 *  being traced.  When tracing r, visitedPerRuleCheck has r
 *  initially.  If you reach a rule stop state, return but notify the
 *  invoking rule that the called rule is nullable. This implies that
 *  invoking rule must look at follow transition for that invoking state.
 *
 *  The visitedStates tracks visited states within a single rule so
 *  we can avoid epsilon-loop-induced infinite recursion here.  Keep
 *  filling the cycles in listOfRecursiveCycles and also, as a
 *  side-effect, set leftRecursiveRules.
 */
public boolean check(Rule enclosingRule, ATNState s, Set<ATNState> visitedStates) {
	if ( s instanceof RuleStopState) return true;
	if ( visitedStates.contains(s) ) return false;
	visitedStates.add(s);

	//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;
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:47,代码来源:LeftRecursionDetector.java

示例7: epsilon

import org.antlr.v4.runtime.atn.ATNState; //导入方法依赖的package包/类
protected void epsilon(ATNState a, ATNState b, boolean prepend) {
	if ( a!=null ) {
		int index = prepend ? 0 : a.getNumberOfTransitions();
		a.addTransition(index, new EpsilonTransition(b));
	}
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:7,代码来源:ParserATNFactory.java


注:本文中的org.antlr.v4.runtime.atn.ATNState.getNumberOfTransitions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。