Java Code Examples for antlr.collections.AST#getFirstChild()
The following examples show how to use
antlr.collections.AST#getFirstChild() .
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: JTreeASTModel.java From dacapobench with Apache License 2.0 | 6 votes |
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 2
Source File: ProEval.java From proparse with Eclipse Public License 2.0 | 6 votes |
public final Object member_fun(AST _t) throws RecognitionException { Object ret; AST member_fun_AST_in = (_t == ASTNULL) ? null : (AST)_t; Object a; AST __t102 = _t; AST tmp116_AST_in = (AST)_t; match(_t,MEMBER); _t = _t.getFirstChild(); AST tmp117_AST_in = (AST)_t; match(_t,LEFTPAREN); _t = _t.getNextSibling(); a=expr(_t); _t = _retTree; AST tmp118_AST_in = (AST)_t; match(_t,RIGHTPAREN); _t = _t.getNextSibling(); _t = __t102; _t = _t.getNextSibling(); if(true) throw new ProEvalException("MEMBER function not yet supported."); _retTree = _t; return ret; }
Example 3
Source File: JsonQueryWalker.java From jasperreports with GNU Lesser General Public License v3.0 | 6 votes |
public final FilterExpression filterExprMain(AST _t) throws RecognitionException { FilterExpression filterExpression = null; AST filterExprMain_AST_in = (_t == ASTNULL) ? null : (AST)_t; try { // for error handling AST __t109 = _t; AST tmp13_AST_in = (AST)_t; match(_t,FILTER); _t = _t.getFirstChild(); filterExpression=filterExpr(_t); _t = _retTree; _t = __t109; _t = _t.getNextSibling(); } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; return filterExpression; }
Example 4
Source File: ProEval.java From proparse with Eclipse Public License 2.0 | 6 votes |
public final Object day_fun(AST _t) throws RecognitionException { Object ret; AST day_fun_AST_in = (_t == ASTNULL) ? null : (AST)_t; Object a; AST __t57 = _t; AST tmp50_AST_in = (AST)_t; match(_t,DAY); _t = _t.getFirstChild(); AST tmp51_AST_in = (AST)_t; match(_t,LEFTPAREN); _t = _t.getNextSibling(); a=expr(_t); _t = _retTree; AST tmp52_AST_in = (AST)_t; match(_t,RIGHTPAREN); _t = _t.getNextSibling(); _t = __t57; _t = _t.getNextSibling(); if(true) throw new ProEvalException("DAY function not yet supported."); _retTree = _t; return ret; }
Example 5
Source File: TreeToNFAConverter.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 6 votes |
public final void attrScope(AST _t) throws RecognitionException { GrammarAST attrScope_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; try { // for error handling AST __t8 = _t; GrammarAST tmp13_AST_in = (GrammarAST)_t; match(_t,SCOPE); _t = _t.getFirstChild(); GrammarAST tmp14_AST_in = (GrammarAST)_t; match(_t,ID); _t = _t.getNextSibling(); GrammarAST tmp15_AST_in = (GrammarAST)_t; match(_t,ACTION); _t = _t.getNextSibling(); _t = __t8; _t = _t.getNextSibling(); } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; }
Example 6
Source File: DefineGrammarItemsWalker.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 5 votes |
public final void ruleAction(AST _t, Rule r ) throws RecognitionException { GrammarAST ruleAction_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; GrammarAST amp = null; GrammarAST id = null; GrammarAST a = null; try { // for error handling AST __t66 = _t; amp = _t==ASTNULL ? null :(GrammarAST)_t; match(_t,AMPERSAND); _t = _t.getFirstChild(); id = (GrammarAST)_t; match(_t,ID); _t = _t.getNextSibling(); a = (GrammarAST)_t; match(_t,ACTION); _t = _t.getNextSibling(); _t = __t66; _t = _t.getNextSibling(); if ( inputState.guessing==0 ) { if (r!=null) r.defineNamedAction(amp,id,a); } } catch (RecognitionException ex) { if (inputState.guessing==0) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } else { throw ex; } } _retTree = _t; }
Example 7
Source File: AssignTokenTypesWalker.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 5 votes |
public final void option(AST _t, Map opts ) throws RecognitionException { GrammarAST option_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; GrammarAST id = null; String key=null; Object value=null; try { // for error handling AST __t23 = _t; GrammarAST tmp16_AST_in = (GrammarAST)_t; match(_t,ASSIGN); _t = _t.getFirstChild(); id = (GrammarAST)_t; match(_t,ID); _t = _t.getNextSibling(); key=id.getText(); value=optionValue(_t); _t = _retTree; _t = __t23; _t = _t.getNextSibling(); opts.put(key,value); // check for grammar-level option to import vocabulary if ( currentRuleName==null && key.equals("tokenVocab") ) { grammar.importTokenVocabulary(id,(String)value); } } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; }
Example 8
Source File: ASTUtil.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Determine if a given node (test) is contained anywhere in the subtree * of another given node (fixture). * * @param fixture The node against which to testto be checked for children. * @param test The node to be tested as being a subtree child of the parent. * * @return True if child is contained in the parent's collection of children. */ public static boolean isSubtreeChild(AST fixture, AST test) { AST n = fixture.getFirstChild(); while ( n != null ) { if ( n == test ) { return true; } if ( n.getFirstChild() != null && isSubtreeChild( n, test ) ) { return true; } n = n.getNextSibling(); } return false; }
Example 9
Source File: CompilationUnitBuilder.java From testability-explorer with Apache License 2.0 | 5 votes |
private boolean contains(AST modifiers, String text) { AST modifier = modifiers.getFirstChild(); while (modifier != null) { if (modifier.getText().equals(text)) return true; modifier = modifier.getNextSibling(); } return false; }
Example 10
Source File: ProEval.java From proparse with Eclipse Public License 2.0 | 4 votes |
public final Object maximum_fun(AST _t) throws RecognitionException { Object ret; AST maximum_fun_AST_in = (_t == ASTNULL) ? null : (AST)_t; Object a; Object b; AST __t98 = _t; AST tmp112_AST_in = (AST)_t; match(_t,MAXIMUM); _t = _t.getFirstChild(); AST tmp113_AST_in = (AST)_t; match(_t,LEFTPAREN); _t = _t.getNextSibling(); a=expr(_t); _t = _retTree; ret = a; { int _cnt100=0; _loop100: do { if (_t==null) _t=ASTNULL; if ((_t.getType()==COMMA)) { AST tmp114_AST_in = (AST)_t; match(_t,COMMA); _t = _t.getNextSibling(); b=expr(_t); _t = _retTree; if (ret==null || b==null) ret=null; else { if (compare(b, ret, Compare.GT)) ret = b; } } else { if ( _cnt100>=1 ) { break _loop100; } else {throw new NoViableAltException(_t);} } _cnt100++; } while (true); } AST tmp115_AST_in = (AST)_t; match(_t,RIGHTPAREN); _t = _t.getNextSibling(); _t = __t98; _t = _t.getNextSibling(); _retTree = _t; return ret; }
Example 11
Source File: TreeToNFAConverter.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 4 votes |
public final void rewrite(AST _t) throws RecognitionException { GrammarAST rewrite_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; try { // for error handling { _loop64: do { if (_t==null) _t=ASTNULL; if ((_t.getType()==REWRITE)) { if ( grammar.getOption("output")==null ) { ErrorManager.grammarError(ErrorManager.MSG_REWRITE_OR_OP_WITH_NO_OUTPUT_OPTION, grammar, rewrite_AST_in.token, currentRuleName); } AST __t61 = _t; GrammarAST tmp39_AST_in = (GrammarAST)_t; match(_t,REWRITE); _t = _t.getFirstChild(); { if (_t==null) _t=ASTNULL; switch ( _t.getType()) { case SEMPRED: { GrammarAST tmp40_AST_in = (GrammarAST)_t; match(_t,SEMPRED); _t = _t.getNextSibling(); break; } case ALT: case TEMPLATE: case ACTION: case ETC: { break; } default: { throw new NoViableAltException(_t); } } } { if (_t==null) _t=ASTNULL; switch ( _t.getType()) { case ALT: { GrammarAST tmp41_AST_in = (GrammarAST)_t; match(_t,ALT); _t = _t.getNextSibling(); break; } case TEMPLATE: { GrammarAST tmp42_AST_in = (GrammarAST)_t; match(_t,TEMPLATE); _t = _t.getNextSibling(); break; } case ACTION: { GrammarAST tmp43_AST_in = (GrammarAST)_t; match(_t,ACTION); _t = _t.getNextSibling(); break; } case ETC: { GrammarAST tmp44_AST_in = (GrammarAST)_t; match(_t,ETC); _t = _t.getNextSibling(); break; } default: { throw new NoViableAltException(_t); } } } _t = __t61; _t = _t.getNextSibling(); } else { break _loop64; } } while (true); } } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; }
Example 12
Source File: CodeGenTreeWalker.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 4 votes |
public final void setElement(AST _t) throws RecognitionException { GrammarAST setElement_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; GrammarAST c = null; GrammarAST t = null; GrammarAST s = null; GrammarAST c1 = null; GrammarAST c2 = null; try { // for error handling if (_t==null) _t=ASTNULL; switch ( _t.getType()) { case CHAR_LITERAL: { c = (GrammarAST)_t; match(_t,CHAR_LITERAL); _t = _t.getNextSibling(); break; } case TOKEN_REF: { t = (GrammarAST)_t; match(_t,TOKEN_REF); _t = _t.getNextSibling(); break; } case STRING_LITERAL: { s = (GrammarAST)_t; match(_t,STRING_LITERAL); _t = _t.getNextSibling(); break; } case CHAR_RANGE: { AST __t93 = _t; GrammarAST tmp57_AST_in = (GrammarAST)_t; match(_t,CHAR_RANGE); _t = _t.getFirstChild(); c1 = (GrammarAST)_t; match(_t,CHAR_LITERAL); _t = _t.getNextSibling(); c2 = (GrammarAST)_t; match(_t,CHAR_LITERAL); _t = _t.getNextSibling(); _t = __t93; _t = _t.getNextSibling(); break; } default: { throw new NoViableAltException(_t); } } } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; }
Example 13
Source File: ProEval.java From proparse with Eclipse Public License 2.0 | 4 votes |
public final Object numentries_fun(AST _t) throws RecognitionException { Object ret; AST numentries_fun_AST_in = (_t == ASTNULL) ? null : (AST)_t; Object a; Object b = null; AST __t110 = _t; AST tmp126_AST_in = (AST)_t; match(_t,NUMENTRIES); _t = _t.getFirstChild(); AST tmp127_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 tmp128_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 tmp129_AST_in = (AST)_t; match(_t,RIGHTPAREN); _t = _t.getNextSibling(); _t = __t110; _t = _t.getNextSibling(); ret = numentries(a, b); _retTree = _t; return ret; }
Example 14
Source File: StringVisitor.java From cxf with Apache License 2.0 | 4 votes |
public static boolean isBounded(AST node) { return node.getFirstChild() != null; }
Example 15
Source File: TreeToNFAConverter.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 4 votes |
public final StateCluster alternative(AST _t) throws RecognitionException { StateCluster g=null; GrammarAST alternative_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; StateCluster e = null; try { // for error handling AST __t48 = _t; GrammarAST tmp38_AST_in = (GrammarAST)_t; match(_t,ALT); _t = _t.getFirstChild(); { int _cnt50=0; _loop50: do { if (_t==null) _t=ASTNULL; if ((_tokenSet_0.member(_t.getType()))) { e=element(_t); _t = _retTree; g = factory.build_AB(g,e); } else { if ( _cnt50>=1 ) { break _loop50; } else {throw new NoViableAltException(_t);} } _cnt50++; } while (true); } _t = __t48; _t = _t.getNextSibling(); if (g==null) { // if alt was a list of actions or whatever g = factory.build_Epsilon(); } else { factory.optimizeAlternative(g); } } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; return g; }
Example 16
Source File: DefineGrammarItemsWalker.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 4 votes |
public final void rewrite(AST _t) throws RecognitionException { GrammarAST rewrite_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; GrammarAST pred = null; currentRewriteRule = rewrite_AST_in; // has to execute during guessing if ( grammar.buildAST() ) { rewrite_AST_in.rewriteRefsDeep = new HashSet<GrammarAST>(); } try { // for error handling { _loop131: do { if (_t==null) _t=ASTNULL; if ((_t.getType()==REWRITE)) { AST __t129 = _t; GrammarAST tmp39_AST_in = (GrammarAST)_t; match(_t,REWRITE); _t = _t.getFirstChild(); { if (_t==null) _t=ASTNULL; switch ( _t.getType()) { case SEMPRED: { pred = (GrammarAST)_t; match(_t,SEMPRED); _t = _t.getNextSibling(); break; } case ALT: case TEMPLATE: case ACTION: case ETC: { break; } default: { throw new NoViableAltException(_t); } } } rewrite_alternative(_t); _t = _retTree; _t = __t129; _t = _t.getNextSibling(); if ( inputState.guessing==0 ) { if ( pred!=null ) { pred.outerAltNum = this.outerAltNum; trackInlineAction(pred); } } } else { break _loop131; } } while (true); } } catch (RecognitionException ex) { if (inputState.guessing==0) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } else { throw ex; } } _retTree = _t; }
Example 17
Source File: ProEval.java From proparse with Eclipse Public License 2.0 | 4 votes |
public final Object asc_fun(AST _t) throws RecognitionException { Object ret; AST asc_fun_AST_in = (_t == ASTNULL) ? null : (AST)_t; Object a; Object b = null; Object c = null; AST __t50 = _t; AST tmp40_AST_in = (AST)_t; match(_t,ASC); _t = _t.getFirstChild(); AST tmp41_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 tmp42_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 tmp43_AST_in = (AST)_t; match(_t,COMMA); _t = _t.getNextSibling(); c=expr(_t); _t = _retTree; break; } case RIGHTPAREN: { break; } default: { throw new NoViableAltException(_t); } } } break; } case RIGHTPAREN: { break; } default: { throw new NoViableAltException(_t); } } } AST tmp44_AST_in = (AST)_t; match(_t,RIGHTPAREN); _t = _t.getNextSibling(); _t = __t50; _t = _t.getNextSibling(); if(true) throw new ProEvalException("ASC function not yet supported."); _retTree = _t; return ret; }
Example 18
Source File: CodeGenTreeWalker.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 4 votes |
public final StringTemplate alternative(AST _t) throws RecognitionException { StringTemplate code=templates.getInstanceOf("alt"); GrammarAST alternative_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; GrammarAST a = null; /* // TODO: can we use Rule.altsWithRewrites??? if ( blockNestingLevel==RULE_BLOCK_NESTING_LEVEL ) { GrammarAST aRewriteNode = #alternative.findFirstType(REWRITE); if ( grammar.buildAST() && (aRewriteNode!=null|| (#alternative.getNextSibling()!=null && #alternative.getNextSibling().getType()==REWRITE)) ) { currentAltHasASTRewrite = true; } else { currentAltHasASTRewrite = false; } } */ if ( blockNestingLevel==RULE_BLOCK_NESTING_LEVEL && grammar.buildAST() ) { Rule r = grammar.getRule(currentRuleName); currentAltHasASTRewrite = r.hasRewrite(outerAltNum); } String description = grammar.grammarTreeToString(alternative_AST_in, false); description = generator.target.getTargetStringLiteralFromString(description); code.setAttribute("description", description); code.setAttribute("treeLevel", rewriteTreeNestingLevel); if ( !currentAltHasASTRewrite && grammar.buildAST() ) { code.setAttribute("autoAST", Boolean.valueOf(true)); } StringTemplate e; try { // for error handling AST __t59 = _t; a = _t==ASTNULL ? null :(GrammarAST)_t; match(_t,ALT); _t = _t.getFirstChild(); { int _cnt61=0; _loop61: do { if (_t==null) _t=ASTNULL; if ((_t.getType()==BLOCK||_t.getType()==OPTIONAL||_t.getType()==CLOSURE||_t.getType()==POSITIVE_CLOSURE||_t.getType()==CHAR_RANGE||_t.getType()==EPSILON||_t.getType()==FORCED_ACTION||_t.getType()==GATED_SEMPRED||_t.getType()==SYN_SEMPRED||_t.getType()==BACKTRACK_SEMPRED||_t.getType()==DOT||_t.getType()==ACTION||_t.getType()==ASSIGN||_t.getType()==STRING_LITERAL||_t.getType()==CHAR_LITERAL||_t.getType()==TOKEN_REF||_t.getType()==BANG||_t.getType()==PLUS_ASSIGN||_t.getType()==SEMPRED||_t.getType()==ROOT||_t.getType()==WILDCARD||_t.getType()==RULE_REF||_t.getType()==NOT||_t.getType()==TREE_BEGIN)) { GrammarAST elAST=(GrammarAST)_t; e=element(_t,null,null); _t = _retTree; if ( e!=null ) { code.setAttribute("elements.{el,line,pos}", e, Utils.integer(elAST.getLine()), Utils.integer(elAST.getColumn()) ); } } else { if ( _cnt61>=1 ) { break _loop61; } else {throw new NoViableAltException(_t);} } _cnt61++; } while (true); } GrammarAST tmp35_AST_in = (GrammarAST)_t; match(_t,EOA); _t = _t.getNextSibling(); _t = __t59; _t = _t.getNextSibling(); } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; return code; }
Example 19
Source File: DumpASTVisitor.java From dacapobench with Apache License 2.0 | 4 votes |
public void visit(AST node) { // Flatten this level of the tree if it has no children boolean flatten = /*true*/ false; AST node2; for (node2 = node; node2 != null; node2 = node2.getNextSibling()) { if (node2.getFirstChild() != null) { flatten = false; break; } } for (node2 = node; node2 != null; node2 = node2.getNextSibling()) { if (!flatten || node2 == node) { tabs(); } if (node2.getText() == null) { System.out.print("nil"); } else { System.out.print(node2.getText()); } System.out.print(" [" + node2.getType() + "] "); if (flatten) { System.out.print(" "); } else { System.out.println(""); } if (node2.getFirstChild() != null) { level++; visit(node2.getFirstChild()); level--; } } if (flatten) { System.out.println(""); } }
Example 20
Source File: ProEval.java From proparse with Eclipse Public License 2.0 | 4 votes |
public final Object etime_fun(AST _t) throws RecognitionException { Object ret; AST etime_fun_AST_in = (_t == ASTNULL) ? null : (AST)_t; Object a = null; AST __t66 = _t; AST tmp64_AST_in = (AST)_t; match(_t,ETIME_KW); _t = _t.getFirstChild(); { if (_t==null) _t=ASTNULL; switch ( _t.getType()) { case LEFTPAREN: { AST tmp65_AST_in = (AST)_t; match(_t,LEFTPAREN); _t = _t.getNextSibling(); a=expr(_t); _t = _retTree; AST tmp66_AST_in = (AST)_t; match(_t,RIGHTPAREN); _t = _t.getNextSibling(); break; } case 3: { break; } default: { throw new NoViableAltException(_t); } } } _t = __t66; _t = _t.getNextSibling(); if(true) throw new ProEvalException("ETIME function is not supported."); _retTree = _t; return ret; }