Java Code Examples for antlr.collections.AST#getNextSibling()

The following examples show how to use antlr.collections.AST#getNextSibling() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProEval.java    From proparse with Eclipse Public License 2.0 6 votes vote down vote up
public final Object  opsys_fun(AST _t) throws RecognitionException {
	Object ret;
	
	AST opsys_fun_AST_in = (_t == ASTNULL) ? null : (AST)_t;
	
	AST tmp130_AST_in = (AST)_t;
	match(_t,OPSYS);
	_t = _t.getNextSibling();
		String opsys = Environment.instance().opsys;
				if (opsys == null || opsys.length()==0)
					throw new ProEvalException("OPSYS has not been configured in Proparse.");
				ret = opsys;
			
	_retTree = _t;
	return ret;
}
 
Example 2
Source File: JTreeASTModel.java    From dacapobench with Apache License 2.0 6 votes vote down vote up
public Object getChild(Object parent, int index) {
    if (parent == null) {
        return null;
    }
    AST p = (AST)parent;
    AST c = p.getFirstChild();
    if (c == null) {
        throw new ArrayIndexOutOfBoundsException("node has no children");
    }
    int i = 0;
    while (c != null && i < index) {
        c = c.getNextSibling();
        i++;
    }
    return c;
}
 
Example 3
Source File: MethodNode.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void resolve(boolean inSelect) throws SemanticException {
	// Get the function name node.
	AST nameNode = getFirstChild();
	AST exprListNode = nameNode.getNextSibling();

	initializeMethodNode( nameNode, inSelect );

	// If the expression list has exactly one expression, and the type of the expression is a collection
	// then this might be a collection function, such as index(c) or size(c).
	if ( ASTUtil.hasExactlyOneChild( exprListNode ) ) {
		if ( "type".equals( methodName ) ) {
			typeDiscriminator( exprListNode.getFirstChild() );
			return;
		}
		if ( isCollectionPropertyMethod() ) {
			collectionProperty( exprListNode.getFirstChild(), nameNode );
			return;
		}
	}

	dialectFunction( exprListNode );
}
 
Example 4
Source File: ProEval.java    From proparse with Eclipse Public License 2.0 6 votes vote down vote up
public final Object  year_fun(AST _t) throws RecognitionException {
	Object ret;
	
	AST year_fun_AST_in = (_t == ASTNULL) ? null : (AST)_t;
	
		Object a;
	
	
	AST __t150 = _t;
	AST tmp185_AST_in = (AST)_t;
	match(_t,YEAR);
	_t = _t.getFirstChild();
	AST tmp186_AST_in = (AST)_t;
	match(_t,LEFTPAREN);
	_t = _t.getNextSibling();
	a=expr(_t);
	_t = _retTree;
	AST tmp187_AST_in = (AST)_t;
	match(_t,RIGHTPAREN);
	_t = _t.getNextSibling();
	_t = __t150;
	_t = _t.getNextSibling();
	if(true) throw new ProEvalException("YEAR function not yet supported.");
	_retTree = _t;
	return ret;
}
 
Example 5
Source File: ANTLRTreePrinter.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 6 votes vote down vote up
public final void rewrite(AST _t) throws RecognitionException {
	
	GrammarAST rewrite_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;
	
	try {      // for error handling
		{
		_loop105:
		do {
			if (_t==null) _t=ASTNULL;
			if ((_t.getType()==REWRITE)) {
				single_rewrite(_t);
				_t = _retTree;
			}
			else {
				break _loop105;
			}
			
		} while (true);
		}
	}
	catch (RecognitionException ex) {
		reportError(ex);
		if (_t!=null) {_t = _t.getNextSibling();}
	}
	_retTree = _t;
}
 
Example 6
Source File: CodeGenTreeWalker.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public final void exceptionHandler(AST _t,
	StringTemplate ruleST
) throws RecognitionException {
	
	GrammarAST exceptionHandler_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;
	
	try {      // for error handling
		AST __t55 = _t;
		GrammarAST tmp36_AST_in = (GrammarAST)_t;
		match(_t,LITERAL_catch);
		_t = _t.getFirstChild();
		GrammarAST tmp37_AST_in = (GrammarAST)_t;
		match(_t,ARG_ACTION);
		_t = _t.getNextSibling();
		GrammarAST tmp38_AST_in = (GrammarAST)_t;
		match(_t,ACTION);
		_t = _t.getNextSibling();
		_t = __t55;
		_t = _t.getNextSibling();
		
			List chunks = generator.translateAction(currentRuleName,tmp38_AST_in);
			ruleST.setAttribute("exceptions.{decl,action}",tmp37_AST_in.getText(),chunks);
			
	}
	catch (RecognitionException ex) {
		reportError(ex);
		if (_t!=null) {_t = _t.getNextSibling();}
	}
	_retTree = _t;
}
 
Example 7
Source File: ProEval.java    From proparse with Eclipse Public License 2.0 5 votes vote down vote up
public final Object  truncate_fun(AST _t) throws RecognitionException {
	Object ret;
	
	AST truncate_fun_AST_in = (_t == ASTNULL) ? null : (AST)_t;
	
		Object a;
		Object b;
	
	
	AST __t146 = _t;
	AST tmp178_AST_in = (AST)_t;
	match(_t,TRUNCATE);
	_t = _t.getFirstChild();
	AST tmp179_AST_in = (AST)_t;
	match(_t,LEFTPAREN);
	_t = _t.getNextSibling();
	a=expr(_t);
	_t = _retTree;
	AST tmp180_AST_in = (AST)_t;
	match(_t,COMMA);
	_t = _t.getNextSibling();
	b=expr(_t);
	_t = _retTree;
	AST tmp181_AST_in = (AST)_t;
	match(_t,RIGHTPAREN);
	_t = _t.getNextSibling();
	_t = __t146;
	_t = _t.getNextSibling();
	if(true) throw new ProEvalException("TRUNCATE function not yet supported.");
	_retTree = _t;
	return ret;
}
 
Example 8
Source File: HqlParser.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Post process equality expressions, clean up the subtree.
 *
 * @param x The equality expression.
 * @return AST - The clean sub-tree.
 */
public AST processEqualityExpression(AST x) {
	if ( x == null ) {
		log.warn( "processEqualityExpression() : No expression to process!" );
		return null;
	}

	int type = x.getType();
	if ( type == EQ || type == NE ) {
		boolean negated = type == NE;
		if ( x.getNumberOfChildren() == 2 ) {
			AST a = x.getFirstChild();
			AST b = a.getNextSibling();
			// (EQ NULL b) => (IS_NULL b)
			if ( a.getType() == NULL && b.getType() != NULL ) {
				return createIsNullParent( b, negated );
			}
			// (EQ a NULL) => (IS_NULL a)
			else if ( b.getType() == NULL && a.getType() != NULL ) {
				return createIsNullParent( a, negated );
			}
			else if ( b.getType() == EMPTY ) {
				return processIsEmpty( a, negated );
			}
			else {
				return x;
			}
		}
		else {
			return x;
		}
	}
	else {
		return x;
	}
}
 
Example 9
Source File: ANTLRTreePrinter.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public final void optionsSpec(AST _t) throws RecognitionException {
	
	GrammarAST optionsSpec_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;
	
	try {      // for error handling
		AST __t26 = _t;
		GrammarAST tmp29_AST_in = (GrammarAST)_t;
		match(_t,OPTIONS);
		_t = _t.getFirstChild();
		out(" options {");
		{
		int _cnt28=0;
		_loop28:
		do {
			if (_t==null) _t=ASTNULL;
			if ((_t.getType()==ASSIGN)) {
				option(_t);
				_t = _retTree;
				out("; ");
			}
			else {
				if ( _cnt28>=1 ) { break _loop28; } else {throw new NoViableAltException(_t);}
			}
			
			_cnt28++;
		} while (true);
		}
		out("} ");
		_t = __t26;
		_t = _t.getNextSibling();
	}
	catch (RecognitionException ex) {
		reportError(ex);
		if (_t!=null) {_t = _t.getNextSibling();}
	}
	_retTree = _t;
}
 
Example 10
Source File: ProEval.java    From proparse with Eclipse Public License 2.0 5 votes vote down vote up
public final Object  propath_fun(AST _t) throws RecognitionException {
	Object ret;
	
	AST propath_fun_AST_in = (_t == ASTNULL) ? null : (AST)_t;
	
	AST tmp131_AST_in = (AST)_t;
	match(_t,PROPATH);
	_t = _t.getNextSibling();
		ret = propath();
			
	_retTree = _t;
	return ret;
}
 
Example 11
Source File: DefineGrammarItemsWalker.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 4 votes vote down vote up
public final void rewrite_block(AST _t) throws RecognitionException {
	
	GrammarAST rewrite_block_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;
	
	GrammarAST enclosingBlock = currentRewriteBlock;
	if ( inputState.guessing==0 ) {  // don't do if guessing
	currentRewriteBlock=rewrite_block_AST_in; // pts to BLOCK node
	currentRewriteBlock.rewriteRefsShallow = new HashSet<GrammarAST>();
	currentRewriteBlock.rewriteRefsDeep = new HashSet<GrammarAST>();
	}
	
	
	try {      // for error handling
		AST __t133 = _t;
		GrammarAST tmp77_AST_in = (GrammarAST)_t;
		match(_t,BLOCK);
		_t = _t.getFirstChild();
		rewrite_alternative(_t);
		_t = _retTree;
		GrammarAST tmp78_AST_in = (GrammarAST)_t;
		match(_t,EOB);
		_t = _t.getNextSibling();
		_t = __t133;
		_t = _t.getNextSibling();
		if ( inputState.guessing==0 ) {
			
			// copy the element refs in this block to the surrounding block
			if ( enclosingBlock!=null ) {
			enclosingBlock.rewriteRefsDeep
			.addAll(currentRewriteBlock.rewriteRefsShallow);
			}
			currentRewriteBlock = enclosingBlock; // restore old BLOCK ptr
			
		}
	}
	catch (RecognitionException ex) {
		if (inputState.guessing==0) {
			reportError(ex);
			if (_t!=null) {_t = _t.getNextSibling();}
		} else {
		  throw ex;
		}
	}
	_retTree = _t;
}
 
Example 12
Source File: CodeGenTreeWalker.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 4 votes vote down vote up
public final StringTemplate  element_action(AST _t) throws RecognitionException {
	StringTemplate code=null;
	
	GrammarAST element_action_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;
	GrammarAST act = null;
	GrammarAST act2 = null;
	
	try {      // for error handling
		if (_t==null) _t=ASTNULL;
		switch ( _t.getType()) {
		case ACTION:
		{
			act = (GrammarAST)_t;
			match(_t,ACTION);
			_t = _t.getNextSibling();
			
			code = templates.getInstanceOf("execAction");
			code.setAttribute("action", generator.translateAction(currentRuleName,act));
			
			break;
		}
		case FORCED_ACTION:
		{
			act2 = (GrammarAST)_t;
			match(_t,FORCED_ACTION);
			_t = _t.getNextSibling();
			
			code = templates.getInstanceOf("execForcedAction");
			code.setAttribute("action", generator.translateAction(currentRuleName,act2));
			
			break;
		}
		default:
		{
			throw new NoViableAltException(_t);
		}
		}
	}
	catch (RecognitionException ex) {
		reportError(ex);
		if (_t!=null) {_t = _t.getNextSibling();}
	}
	_retTree = _t;
	return code;
}
 
Example 13
Source File: ASTUtil.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static void appendSibling(AST n, AST s) {
	while ( n.getNextSibling() != null ) {
		n = n.getNextSibling();
	}
	n.setNextSibling( s );
}
 
Example 14
Source File: ProEval.java    From proparse with Eclipse Public License 2.0 4 votes vote down vote up
public final Object  index_fun(AST _t) throws RecognitionException {
	Object ret;
	
	AST index_fun_AST_in = (_t == ASTNULL) ? null : (AST)_t;
	
		Object a;
		Object b;
		Object c = null;
	
	
	AST __t73 = _t;
	AST tmp75_AST_in = (AST)_t;
	match(_t,INDEX);
	_t = _t.getFirstChild();
	AST tmp76_AST_in = (AST)_t;
	match(_t,LEFTPAREN);
	_t = _t.getNextSibling();
	a=expr(_t);
	_t = _retTree;
	AST tmp77_AST_in = (AST)_t;
	match(_t,COMMA);
	_t = _t.getNextSibling();
	b=expr(_t);
	_t = _retTree;
	{
	if (_t==null) _t=ASTNULL;
	switch ( _t.getType()) {
	case COMMA:
	{
		AST tmp78_AST_in = (AST)_t;
		match(_t,COMMA);
		_t = _t.getNextSibling();
		c=expr(_t);
		_t = _retTree;
		break;
	}
	case RIGHTPAREN:
	{
		break;
	}
	default:
	{
		throw new NoViableAltException(_t);
	}
	}
	}
	AST tmp79_AST_in = (AST)_t;
	match(_t,RIGHTPAREN);
	_t = _t.getNextSibling();
	_t = __t73;
	_t = _t.getNextSibling();
		ret = index(a, b, c);
			
	_retTree = _t;
	return ret;
}
 
Example 15
Source File: ANTLRTreePrinter.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 4 votes vote down vote up
public final void grammar(AST _t) throws RecognitionException {
	
	GrammarAST grammar_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;
	
	try {      // for error handling
		{
		if (_t==null) _t=ASTNULL;
		switch ( _t.getType()) {
		case LEXER_GRAMMAR:
		{
			AST __t5 = _t;
			GrammarAST tmp2_AST_in = (GrammarAST)_t;
			match(_t,LEXER_GRAMMAR);
			_t = _t.getFirstChild();
			grammarSpec(_t,"lexer " );
			_t = _retTree;
			_t = __t5;
			_t = _t.getNextSibling();
			break;
		}
		case PARSER_GRAMMAR:
		{
			AST __t6 = _t;
			GrammarAST tmp3_AST_in = (GrammarAST)_t;
			match(_t,PARSER_GRAMMAR);
			_t = _t.getFirstChild();
			grammarSpec(_t,"parser ");
			_t = _retTree;
			_t = __t6;
			_t = _t.getNextSibling();
			break;
		}
		case TREE_GRAMMAR:
		{
			AST __t7 = _t;
			GrammarAST tmp4_AST_in = (GrammarAST)_t;
			match(_t,TREE_GRAMMAR);
			_t = _t.getFirstChild();
			grammarSpec(_t,"tree ");
			_t = _retTree;
			_t = __t7;
			_t = _t.getNextSibling();
			break;
		}
		case COMBINED_GRAMMAR:
		{
			AST __t8 = _t;
			GrammarAST tmp5_AST_in = (GrammarAST)_t;
			match(_t,COMBINED_GRAMMAR);
			_t = _t.getFirstChild();
			grammarSpec(_t,"");
			_t = _retTree;
			_t = __t8;
			_t = _t.getNextSibling();
			break;
		}
		default:
		{
			throw new NoViableAltException(_t);
		}
		}
		}
	}
	catch (RecognitionException ex) {
		reportError(ex);
		if (_t!=null) {_t = _t.getNextSibling();}
	}
	_retTree = _t;
}
 
Example 16
Source File: TreeToNFAConverter.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 4 votes vote down vote up
public final StateCluster  tree(AST _t) throws RecognitionException {
	StateCluster g=null;
	
	GrammarAST tree_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;
	
	StateCluster e=null;
	GrammarAST el=null;
	StateCluster down=null, up=null;
	
	
	try {      // for error handling
		AST __t78 = _t;
		GrammarAST tmp66_AST_in = (GrammarAST)_t;
		match(_t,TREE_BEGIN);
		_t = _t.getFirstChild();
		el=(GrammarAST)_t;
		g=element(_t);
		_t = _retTree;
		
		down = factory.build_Atom(Label.DOWN, el);
		// TODO set following states for imaginary nodes?
		//el.followingNFAState = down.right;
				   g = factory.build_AB(g,down);
				
		{
		_loop80:
		do {
			if (_t==null) _t=ASTNULL;
			if ((_tokenSet_0.member(_t.getType()))) {
				el=(GrammarAST)_t;
				e=element(_t);
				_t = _retTree;
				g = factory.build_AB(g,e);
			}
			else {
				break _loop80;
			}
			
		} while (true);
		}
		
		up = factory.build_Atom(Label.UP, el);
		//el.followingNFAState = up.right;
				   g = factory.build_AB(g,up);
				   // tree roots point at right edge of DOWN for LOOK computation later
				   tree_AST_in.NFATreeDownState = down.left;
				
		_t = __t78;
		_t = _t.getNextSibling();
	}
	catch (RecognitionException ex) {
		reportError(ex);
		if (_t!=null) {_t = _t.getNextSibling();}
	}
	_retTree = _t;
	return g;
}
 
Example 17
Source File: DefineGrammarItemsWalker.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 4 votes vote down vote up
public final void delegateGrammars(AST _t) throws RecognitionException {
	
	GrammarAST delegateGrammars_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;
	
	try {      // for error handling
		AST __t25 = _t;
		GrammarAST tmp7_AST_in = (GrammarAST)_t;
		match(_t,IMPORT);
		_t = _t.getFirstChild();
		{
		int _cnt28=0;
		_loop28:
		do {
			if (_t==null) _t=ASTNULL;
			switch ( _t.getType()) {
			case ASSIGN:
			{
				AST __t27 = _t;
				GrammarAST tmp8_AST_in = (GrammarAST)_t;
				match(_t,ASSIGN);
				_t = _t.getFirstChild();
				GrammarAST tmp9_AST_in = (GrammarAST)_t;
				match(_t,ID);
				_t = _t.getNextSibling();
				GrammarAST tmp10_AST_in = (GrammarAST)_t;
				match(_t,ID);
				_t = _t.getNextSibling();
				_t = __t27;
				_t = _t.getNextSibling();
				break;
			}
			case ID:
			{
				GrammarAST tmp11_AST_in = (GrammarAST)_t;
				match(_t,ID);
				_t = _t.getNextSibling();
				break;
			}
			default:
			{
				if ( _cnt28>=1 ) { break _loop28; } else {throw new NoViableAltException(_t);}
			}
			}
			_cnt28++;
		} while (true);
		}
		_t = __t25;
		_t = _t.getNextSibling();
	}
	catch (RecognitionException ex) {
		if (inputState.guessing==0) {
			reportError(ex);
			if (_t!=null) {_t = _t.getNextSibling();}
		} else {
		  throw ex;
		}
	}
	_retTree = _t;
}
 
Example 18
Source File: ProEval.java    From proparse with Eclipse Public License 2.0 4 votes vote down vote up
public final Object  trim_fun(AST _t) throws RecognitionException {
	Object ret;
	
	AST trim_fun_AST_in = (_t == ASTNULL) ? null : (AST)_t;
	
		Object a;
		Object b = null;
	
	
	AST __t143 = _t;
	AST tmp174_AST_in = (AST)_t;
	match(_t,TRIM);
	_t = _t.getFirstChild();
	AST tmp175_AST_in = (AST)_t;
	match(_t,LEFTPAREN);
	_t = _t.getNextSibling();
	a=expr(_t);
	_t = _retTree;
	{
	if (_t==null) _t=ASTNULL;
	switch ( _t.getType()) {
	case COMMA:
	{
		AST tmp176_AST_in = (AST)_t;
		match(_t,COMMA);
		_t = _t.getNextSibling();
		b=expr(_t);
		_t = _retTree;
		break;
	}
	case RIGHTPAREN:
	{
		break;
	}
	default:
	{
		throw new NoViableAltException(_t);
	}
	}
	}
	AST tmp177_AST_in = (AST)_t;
	match(_t,RIGHTPAREN);
	_t = _t.getNextSibling();
	_t = __t143;
	_t = _t.getNextSibling();
		String s = getString(a);
				if (b != null)
					ret = StringFuncs.trim(s, getString(b));
				else
					ret = s.trim();
			
	_retTree = _t;
	return ret;
}
 
Example 19
Source File: TreeToNFAConverter.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 4 votes vote down vote up
public final void grammar(AST _t) throws RecognitionException {
	
	GrammarAST grammar_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;
	
	try {      // for error handling
		{
		if (_t==null) _t=ASTNULL;
		switch ( _t.getType()) {
		case LEXER_GRAMMAR:
		{
			AST __t3 = _t;
			GrammarAST tmp1_AST_in = (GrammarAST)_t;
			match(_t,LEXER_GRAMMAR);
			_t = _t.getFirstChild();
			grammarSpec(_t);
			_t = _retTree;
			_t = __t3;
			_t = _t.getNextSibling();
			break;
		}
		case PARSER_GRAMMAR:
		{
			AST __t4 = _t;
			GrammarAST tmp2_AST_in = (GrammarAST)_t;
			match(_t,PARSER_GRAMMAR);
			_t = _t.getFirstChild();
			grammarSpec(_t);
			_t = _retTree;
			_t = __t4;
			_t = _t.getNextSibling();
			break;
		}
		case TREE_GRAMMAR:
		{
			AST __t5 = _t;
			GrammarAST tmp3_AST_in = (GrammarAST)_t;
			match(_t,TREE_GRAMMAR);
			_t = _t.getFirstChild();
			grammarSpec(_t);
			_t = _retTree;
			_t = __t5;
			_t = _t.getNextSibling();
			break;
		}
		case COMBINED_GRAMMAR:
		{
			AST __t6 = _t;
			GrammarAST tmp4_AST_in = (GrammarAST)_t;
			match(_t,COMBINED_GRAMMAR);
			_t = _t.getFirstChild();
			grammarSpec(_t);
			_t = _retTree;
			_t = __t6;
			_t = _t.getNextSibling();
			break;
		}
		default:
		{
			throw new NoViableAltException(_t);
		}
		}
		}
		finish();
	}
	catch (RecognitionException ex) {
		reportError(ex);
		if (_t!=null) {_t = _t.getNextSibling();}
	}
	_retTree = _t;
}
 
Example 20
Source File: ASTUtil.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Finds the first node of the specified type in the chain of children.
 *
 * @param parent The parent
 * @param type The type to find.
 *
 * @return The first node of the specified type, or null if not found.
 */
public static AST findTypeInChildren(AST parent, int type) {
	AST n = parent.getFirstChild();
	while ( n != null && n.getType() != type ) {
		n = n.getNextSibling();
	}
	return n;
}