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


Java ATNState.addTransition方法代码示例

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


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

示例1: stringLiteral

import org.antlr.v4.runtime.atn.ATNState; //导入方法依赖的package包/类
/** For a lexer, a string is a sequence of char to match.  That is,
 *  "fog" is treated as 'f' 'o' 'g' not as a single transition in
 *  the DFA.  Machine== o-'f'->o-'o'->o-'g'->o and has n+1 states
 *  for n characters.
 */
@Override
public Handle stringLiteral(TerminalAST stringLiteralAST) {
	String chars = stringLiteralAST.getText();
	chars = CharSupport.getStringFromGrammarStringLiteral(chars);
	int n = chars.length();
	ATNState left = newState(stringLiteralAST);
	ATNState prev = left;
	ATNState right = null;
	for (int i=0; i<n; i++) {
		right = newState(stringLiteralAST);
		prev.addTransition(new AtomTransition(right, chars.charAt(i)));
		prev = right;
	}
	stringLiteralAST.atnState = left;
	return new Handle(left, right);
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:22,代码来源:LexerATNFactory.java

示例2: _ruleRef

import org.antlr.v4.runtime.atn.ATNState; //导入方法依赖的package包/类
public Handle _ruleRef(GrammarAST node) {
	Rule r = g.getRule(node.getText());
	if ( r==null ) {
		g.tool.errMgr.grammarError(ErrorType.INTERNAL_ERROR, g.fileName, node.getToken(), "Rule "+node.getText()+" undefined");
		return null;
	}
	RuleStartState start = atn.ruleToStartState[r.index];
	ATNState left = newState(node);
	ATNState right = newState(node);
	int precedence = 0;
	if (((GrammarASTWithOptions)node).getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME) != null) {
		precedence = Integer.parseInt(((GrammarASTWithOptions)node).getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME));
	}
	RuleTransition call = new RuleTransition(start, r.index, precedence, right);
	left.addTransition(call);

	node.atnState = left;
	return new Handle(left, right);
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:20,代码来源:ParserATNFactory.java

示例3: action

import org.antlr.v4.runtime.atn.ATNState; //导入方法依赖的package包/类
protected Handle action(GrammarAST node, LexerAction lexerAction) {
	ATNState left = newState(node);
	ATNState right = newState(node);
	boolean isCtxDependent = false;
	int lexerActionIndex = getLexerActionIndex(lexerAction);
	ActionTransition a =
		new ActionTransition(right, currentRule.index, lexerActionIndex, isCtxDependent);
	left.addTransition(a);
	node.atnState = left;
	Handle h = new Handle(left, right);
	return h;
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:13,代码来源:LexerATNFactory.java

示例4: range

import org.antlr.v4.runtime.atn.ATNState; //导入方法依赖的package包/类
@Override
public Handle range(GrammarAST a, GrammarAST b) {
	ATNState left = newState(a);
	ATNState right = newState(b);
	int t1 = CharSupport.getCharValueFromGrammarCharLiteral(a.getText());
	int t2 = CharSupport.getCharValueFromGrammarCharLiteral(b.getText());
	left.addTransition(new  RangeTransition(right, t1, t2));
	a.atnState = left;
	b.atnState = left;
	return new Handle(left, right);
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:12,代码来源:LexerATNFactory.java

示例5: charSetLiteral

import org.antlr.v4.runtime.atn.ATNState; //导入方法依赖的package包/类
/** [Aa\t \u1234a-z\]\-] char sets */
@Override
public Handle charSetLiteral(GrammarAST charSetAST) {
	ATNState left = newState(charSetAST);
	ATNState right = newState(charSetAST);
	IntervalSet set = getSetFromCharSetLiteral(charSetAST);
	left.addTransition(new SetTransition(right, set));
	charSetAST.atnState = left;
	return new Handle(left, right);
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:11,代码来源:LexerATNFactory.java

示例6: tokenRef

import org.antlr.v4.runtime.atn.ATNState; //导入方法依赖的package包/类
@Override
public Handle tokenRef(TerminalAST node) {
	// Ref to EOF in lexer yields char transition on -1
	if ( node.getText().equals("EOF") ) {
		ATNState left = newState(node);
		ATNState right = newState(node);
		left.addTransition(new AtomTransition(right, IntStream.EOF));
		return new Handle(left, right);
	}
	return _ruleRef(node);
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:12,代码来源:LexerATNFactory.java

示例7: tokenRef

import org.antlr.v4.runtime.atn.ATNState; //导入方法依赖的package包/类
/** From label {@code A} build graph {@code o-A->o}. */

	@Override
	public Handle tokenRef(TerminalAST node) {
		ATNState left = newState(node);
		ATNState right = newState(node);
		int ttype = g.getTokenType(node.getText());
		left.addTransition(new AtomTransition(right, ttype));
		node.atnState = left;
		return new Handle(left, right);
	}
 
开发者ID:antlr,项目名称:codebuff,代码行数:12,代码来源:ParserATNFactory.java

示例8: wildcard

import org.antlr.v4.runtime.atn.ATNState; //导入方法依赖的package包/类
/** Build an atom with all possible values in its label. */

	@Override
	public Handle wildcard(GrammarAST node) {
		ATNState left = newState(node);
		ATNState right = newState(node);
		left.addTransition(new WildcardTransition(right));
		node.atnState = left;
		return new Handle(left, right);
	}
 
开发者ID:antlr,项目名称:codebuff,代码行数:11,代码来源:ParserATNFactory.java

示例9: 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

示例10: 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.addTransition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。