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


Java Barrier类代码示例

本文整理汇总了Java中org.antlr.misc.Barrier的典型用法代码示例。如果您正苦于以下问题:Java Barrier类的具体用法?Java Barrier怎么用?Java Barrier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: NFAConversionThread

import org.antlr.misc.Barrier; //导入依赖的package包/类
public NFAConversionThread(Grammar grammar,
						   Barrier barrier,
						   int i,
						   int j)
{
	this.grammar = grammar;
	this.barrier = barrier;
	this.i = i;
	this.j = j;
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:11,代码来源:NFAConversionThread.java

示例2: createLookaheadDFAs

import org.antlr.misc.Barrier; //导入依赖的package包/类
/** For each decision in this grammar, compute a single DFA using the
    *  NFA states associated with the decision.  The DFA construction
    *  determines whether or not the alternatives in the decision are
    *  separable using a regular lookahead language.
    *
    *  Store the lookahead DFAs in the AST created from the user's grammar
    *  so the code generator or whoever can easily access it.
    *
    *  This is a separate method because you might want to create a
    *  Grammar without doing the expensive analysis.
    */
   public void createLookaheadDFAs() {
	if ( nfa==null ) {
		createNFAs();
	}

	long start = System.currentTimeMillis();

	//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 ( !externalAnalysisAbort && decisionStartState.getNumberOfTransitions()>1 ) {
				createLookaheadDFA(decision);
			}
		}
	}
	else {
		ErrorManager.info("two-threaded DFA conversion");
		// create a barrier expecting n DFA and this main creation thread
		Barrier barrier = new Barrier(3);
		// assume 2 CPU for now
		int midpoint = numDecisions/2;
		NFAConversionThread t1 =
			new NFAConversionThread(this, barrier, 1, midpoint);
		new Thread(t1).start();
		if ( midpoint == (numDecisions/2) ) {
			midpoint++;
		}
		NFAConversionThread t2 =
			new NFAConversionThread(this, barrier, midpoint, numDecisions);
		new Thread(t2).start();
		// wait for these two threads to finish
		try {
			barrier.waitForRelease();
		}
		catch(InterruptedException e) {
			ErrorManager.internalError("what the hell? DFA interruptus", e);
		}
	}

	long stop = System.currentTimeMillis();
	DFACreationWallClockTimeInMS = stop - start;

	// indicate that we've finished building DFA (even if #decisions==0)
	allDecisionDFACreated = true;
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:59,代码来源:Grammar.java


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