aboutsummaryrefslogtreecommitdiff
path: root/treetree.js
diff options
context:
space:
mode:
authortomsmeding <hallo@tomsmeding.nl>2014-04-29 12:24:47 +0200
committertomsmeding <hallo@tomsmeding.nl>2014-04-29 12:24:47 +0200
commit571038785a3750db34261b462206e4fb73b206a7 (patch)
tree6263f0abe3056bb8252b493dbf682dfe6cc6a5df /treetree.js
parentd964b6139f127c6720e927d0e6f467293d6d9eba (diff)
Added REL
Diffstat (limited to 'treetree.js')
-rwxr-xr-xtreetree.js27
1 files changed, 24 insertions, 3 deletions
diff --git a/treetree.js b/treetree.js
index f32bfdd..c71b12c 100755
--- a/treetree.js
+++ b/treetree.js
@@ -242,11 +242,12 @@ function runCmds(cmds,TR){
newroot=[TR[0],TR,objcpy(TR[2])];
TR=newroot;
break;
- case "GRB": //TODO CHECK WHETHER THIS SHIT WORKS
+ case "GRB":
var inserted_tree,end_tree,rest_tree,i,n;
if(TR==false)throw new TTerror("Cannot GRB from a non-existant root node!");
+ if(TR[2]!=false)throw new TTerror("Cannot operate multiple times (in GRB), but the root node ('"+TR[0]+"') has secondary children!");
n=TR[0];
- if(typeof n!="number")throw new TTerror("Integer expected (in GRB), got '"+n.toString()+"'!")
+ if(typeof n!="number")throw new TTerror("Integer expected (in GRB), got '"+n.toString()+"'!");
TR=TR[1];
if(n==0)break;
inserted_tree=objcpy(TR[1]);
@@ -259,7 +260,27 @@ function runCmds(cmds,TR){
TR[2]=inserted_tree;
TR[1]=rest_tree;
break;
- case "REL":break;
+ case "REL":
+ var i,n,inserted_tree,last_inserted,after_inserted,rest_main_tree;
+ if(TR==false)throw new TTerror("Cannot REL from a non-existant root node!");
+ if(TR[2]!=false)throw new TTerror("Cannot operate multiple times (in REL), but the root node ('"+TR[0]+"') has secondary children!");
+ n=TR[0];
+ if(typeof n!="number")throw new TTerror("Integer expected (in REL), got '"+n.toString()+"'!");
+ if(n==0)break;
+ TR=TR[1];
+ rest_main_tree=TR[1];
+ inserted_tree=TR[2];
+ if(inserted_tree==false)throw new TTerror("Not enough secondary children to REL!");
+ last_inserted=inserted_tree;
+ for(i=0;i<n-1;i++){
+ if(last_inserted==false)throw new TTerror("Not enough secondary children to REL!");
+ last_inserted=last_inserted[1];
+ }
+ after_inserted=objcpy(last_inserted[1]);
+ last_inserted[1]=rest_main_tree;
+ TR[1]=inserted_tree;
+ TR[2]=after_inserted;
+ break;
case "INT":break;
case "FLT":break;
case "STR":break;