java - How to add all elements in list to Abstract Syntax Tree without knowing how many elements? -


so have abstractsyntaxtreenode.java class (here part of it)

public abstract class astreenode implements iterable<astreenode>{  protected list<astreenode> children;  protected astreenode(){   children = new linkedlist<astreenode>(); }  protected astreenode(astreenode... children){   this();   for(astreenode c: children) {   this.addchild(c); } 

and have class operation extends astreenode

public class operation extends astreenode {   char s;    private operation(term t)   {   //question regarding part     super(t, t.getchild(0), t.getchild(1));   } } 

how throw in of object t's (which extends astreenode) children super ctor arguments? without hardcoding that? tried super(t, t.children) constructor not take list in argument, astreenodes taken.

oh , class term

public class term extends astreenode {   char symbol;  private term(factor f) {   super(f, f.getchild(0)); } } 

and theres bunch more classes send children node

add constructor in astreenode accept's list it's argument.

public abstract class astreenode ... {      public astreenode(list<? extends astreenode> children) {         this.children = children;     } }  public class operation extends astreenode {     char s;      private operation(term t) {         super(t.getchildren());         this.addchild(t);     } } 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -