aboutsummaryrefslogtreecommitdiff
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
parentd964b6139f127c6720e927d0e6f467293d6d9eba (diff)
Added REL
-rw-r--r--test.trt54
-rwxr-xr-xtreetree.js27
2 files changed, 75 insertions, 6 deletions
diff --git a/test.trt b/test.trt
index e2a3afa..24095f4 100644
--- a/test.trt
+++ b/test.trt
@@ -1,3 +1,51 @@
-1 2 stk
-swp stk
-dup stk \ No newline at end of file
+5 4 3 swp stk
+"e" "d" "c" "b" "a" stk
+4 grb stk
+3 rel stk
+
+{
+Outputs:
+
+3--4
+ |
+ 5
+
+a
+|
+b
+|
+c
+|
+d
+|
+e
+|
+3--4
+ |
+ 5
+
+a--b
+| |
+| c
+| |
+| d
+| |
+| e
+|
+3--4
+ |
+ 5
+
+
+a--e
+|
+b
+|
+c
+|
+d
+|
+3--4
+ |
+ 5
+}
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;