public GrammarAST getLastChild() { if (getChildCount() == 0) return null; return (GrammarAST)getChild(getChildCount() - 1); }
public GrammarAST getLastChild() { if (getChildCount() == 0) return null; return (GrammarAST)getChild(getChildCount() - 1); }
public void setTreeEnclosingRuleNameDeeply(String rname) { enclosingRuleName = rname; if (getChildCount() == 0) return; for (Object child : getChildren()) { if (!(child instanceof GrammarAST)) { continue; } GrammarAST grammarAST = (GrammarAST)child; grammarAST.setTreeEnclosingRuleNameDeeply(rname); } }
public final int countAltsForBlock(GrammarAST t) { int n = 0; for ( int i = 0; i < t.getChildCount(); i++ ) { if ( t.getChild(i).getType() == ALT ) n++; } return n; }
public final int countAltsForBlock(GrammarAST t) { int n = 0; for ( int i = 0; i < t.getChildCount(); i++ ) { if ( t.getChild(i).getType() == ALT ) n++; } return n; }
public void setTreeEnclosingRuleNameDeeply(String rname) { enclosingRuleName = rname; if (getChildCount() == 0) return; for (Object child : getChildren()) { if (!(child instanceof GrammarAST)) { continue; } GrammarAST grammarAST = (GrammarAST)child; grammarAST.setTreeEnclosingRuleNameDeeply(rname); } }
public void _findAllType(int ttype, List<GrammarAST> nodes) { // check this node (the root) first if ( this.getType()==ttype ) nodes.add(this); // check children for (int i = 0; i < getChildCount(); i++){ GrammarAST child = (GrammarAST)getChild(i); child._findAllType(ttype, nodes); } }
public void _findAllType(int ttype, List<GrammarAST> nodes) { // check this node (the root) first if ( this.getType()==ttype ) nodes.add(this); // check children for (int i = 0; i < getChildCount(); i++){ GrammarAST child = (GrammarAST)getChild(i); child._findAllType(ttype, nodes); } }
private static List<GrammarAST> getChildrenForDupTree(GrammarAST t) { List<GrammarAST> result = new ArrayList<GrammarAST>(); for (int i = 0; i < t.getChildCount(); i++){ GrammarAST child = (GrammarAST)t.getChild(i); int ttype = child.getType(); if (ttype == ANTLRParser.REWRITES || ttype == ANTLRParser.REWRITE || ttype==ANTLRParser.ACTION) { continue; } if (ttype == ANTLRParser.BANG || ttype == ANTLRParser.ROOT) { for (GrammarAST subchild : getChildrenForDupTree(child)) result.add(subchild); } else { result.add(child); } } if ( result.size()==1 && result.get(0).getType()==ANTLRParser.EOA && t.getType()==ANTLRParser.ALT ) { // can't have an empty alt, insert epsilon result.add(0, new GrammarAST(ANTLRParser.EPSILON, "epsilon")); } return result; }
private static List<GrammarAST> getChildrenForDupTree(GrammarAST t) { List<GrammarAST> result = new ArrayList<GrammarAST>(); for (int i = 0; i < t.getChildCount(); i++){ GrammarAST child = (GrammarAST)t.getChild(i); int ttype = child.getType(); if (ttype == ANTLRParser.REWRITES || ttype == ANTLRParser.REWRITE || ttype==ANTLRParser.ACTION) { continue; } if (ttype == ANTLRParser.BANG || ttype == ANTLRParser.ROOT) { for (GrammarAST subchild : getChildrenForDupTree(child)) result.add(subchild); } else { result.add(child); } } if ( result.size()==1 && result.get(0).getType()==ANTLRParser.EOA && t.getType()==ANTLRParser.ALT ) { // can't have an empty alt, insert epsilon result.add(0, new GrammarAST(ANTLRParser.EPSILON, "epsilon")); } return result; }
public static GrammarAST dupTree(GrammarAST t) { if ( t==null ) { return null; } GrammarAST root = dup(t); // make copy of root // copy all children of root. for (int i= 0; i < t.getChildCount(); i++) { GrammarAST child = (GrammarAST)t.getChild(i); root.addChild(dupTree(child)); } return root; }
public void addRule(GrammarAST grammarTree, GrammarAST t) { GrammarAST p = null; for (int i = 0; i < grammarTree.getChildCount(); i++ ) { p = (GrammarAST)grammarTree.getChild(i); if (p == null || p.getType() == ANTLRParser.RULE || p.getType() == ANTLRParser.PREC_RULE) { break; } } if (p != null) { grammarTree.addChild(t); } }
public static GrammarAST dupTree(GrammarAST t) { if ( t==null ) { return null; } GrammarAST root = dup(t); // make copy of root // copy all children of root. for (int i= 0; i < t.getChildCount(); i++) { GrammarAST child = (GrammarAST)t.getChild(i); root.addChild(dupTree(child)); } return root; }
public void addRule(GrammarAST grammarTree, GrammarAST t) { GrammarAST p = null; for (int i = 0; i < grammarTree.getChildCount(); i++ ) { p = (GrammarAST)grammarTree.getChild(i); if (p == null || p.getType() == ANTLRParser.RULE || p.getType() == ANTLRParser.PREC_RULE) { break; } } if (p != null) { grammarTree.addChild(t); } }
public GrammarAST getBlockALT(int i) { if ( this.getType()!=ANTLRParser.BLOCK ) return null; int alts = 0; for (int j =0 ; j < getChildCount(); j++) { if (getChild(j).getType() == ANTLRParser.ALT) { alts++; } if (alts == i) { return (GrammarAST)getChild(j); } } return null; } }
public GrammarAST getBlockALT(int i) { if ( this.getType()!=ANTLRParser.BLOCK ) return null; int alts = 0; for (int j =0 ; j < getChildCount(); j++) { if (getChild(j).getType() == ANTLRParser.ALT) { alts++; } if (alts == i) { return (GrammarAST)getChild(j); } } return null; } }
/** Remove any lexer rules from a COMBINED; already passed to lexer */ protected final void trimGrammar() { if ( grammar.type != Grammar.COMBINED ) { return; } // form is (header ... ) ( grammar ID (scope ...) ... ( rule ... ) ( rule ... ) ... ) GrammarAST p = root; // find the grammar spec while ( !p.getText().equals( "grammar" ) ) { p = p.getNextSibling(); } for ( int i = 0; i < p.getChildCount(); i++ ) { if ( p.getChild( i ).getType() != RULE ) continue; String ruleName = p.getChild(i).getChild(0).getText(); //Console.Out.WriteLine( "rule " + ruleName + " prev=" + prev.getText() ); if (Rule.getRuleType(ruleName) == Grammar.LEXER) { // remove lexer rule p.deleteChild( i ); i--; } } //Console.Out.WriteLine( "root after removal is: " + root.ToStringList() ); }
/** Remove any lexer rules from a COMBINED; already passed to lexer */ protected final void trimGrammar() { if ( grammar.type != Grammar.COMBINED ) { return; } // form is (header ... ) ( grammar ID (scope ...) ... ( rule ... ) ( rule ... ) ... ) GrammarAST p = root; // find the grammar spec while ( !p.getText().equals( "grammar" ) ) { p = p.getNextSibling(); } for ( int i = 0; i < p.getChildCount(); i++ ) { if ( p.getChild( i ).getType() != RULE ) continue; String ruleName = p.getChild(i).getChild(0).getText(); //Console.Out.WriteLine( "rule " + ruleName + " prev=" + prev.getText() ); if (Rule.getRuleType(ruleName) == Grammar.LEXER) { // remove lexer rule p.deleteChild( i ); i--; } } //Console.Out.WriteLine( "root after removal is: " + root.ToStringList() ); }
boolean lr=false; this.numAlts = ((GrammarAST)retval.start).getChildCount(); try {
boolean lr=false; this.numAlts = ((GrammarAST)retval.start).getChildCount(); try {