Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

60
LINES

< > BotCompany Repo | #1017535 // Computation Tree Include v1

JavaX fragment (include)

abstract sclass CTNode {
  new LinkedHashSet<CTNode> children;
  
  toString { ret shortClassName(this) + ": " + toString2(); }
  abstract S toString2();
  
  bool add(CTNode n) { ret children.add(n); }
}

sclass TextNode > CTNode {
  S text;
  
  *() {}
  *(S *text) {}
  
  S toString2() { ret quote(text); }
}

sclass TokNode > CTNode {
  L<S> tok;
  
  *() {}
  *(LS *tok) {}
  
  S toString2() { ret sfu(tok); }
  
  public bool equals(O o) { ret stdEq(this, o, 'tok); }
  public int hashCode() { ret stdHash(this, 'tok); }
}

sclass ObjectNode > CTNode {
  O obj;
  
  *() {}
  *(O *obj) {}
  
  S toString2() { ret sfu(obj); }
  
  public bool equals(O o) { ret stdEq(this, o, 'obj); }
  public int hashCode() { ret stdHash(this, 'obj); }
}

sclass OpNode > CTNode {
  S op;
  bool haveResult;
  O result; // this is the result coming back up from the operation
  
  *() {}
  *(S *op) {}
  
  S toString2() { ret haveResult ? result + " <- " + op : op; }
  
  public bool equals(O o) { ret stdEq(this, o, 'op); }
  public int hashCode() { ret stdHash(this, 'op); }
  
  void setResult(O o) {
    result = o;
    haveResult = true;
  }
}

Author comment

Began life as a copy of #1017532

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1017535
Snippet name: Computation Tree Include v1
Eternal ID of this version: #1017535/4
Text MD5: 80674d47beb9d0cb6973e417e10e6007
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-07-29 17:00:14
Source code size: 1202 bytes / 60 lines
Pitched / IR pitched: No / No
Views / Downloads: 311 / 868
Version history: 3 change(s)
Referenced in: [show references]