aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtreetree.js33
-rw-r--r--treetree.md6
2 files changed, 29 insertions, 10 deletions
diff --git a/treetree.js b/treetree.js
index c71b12c..2b186ae 100755
--- a/treetree.js
+++ b/treetree.js
@@ -281,12 +281,29 @@ function runCmds(cmds,TR){
TR[1]=inserted_tree;
TR[2]=after_inserted;
break;
- case "INT":break;
- case "FLT":break;
- case "STR":break;
- case "NAN":break;
- case "LEN":break;
- case "SPL":break;
+ case "INT":
+ if(TR==false)throw new TTerror("Cannot INT a non-existant root node!");
+ TR[0]=parseInt(TR[0],10);
+ break;
+ case "FLT":
+ if(TR==false)throw new TTerror("Cannot INT a non-existant root node!");
+ TR[0]=parseInt(TR[0],10);
+ break;
+ case "STR":
+ if(TR==false)throw new TTerror("Cannot INT a non-existant root node!");
+ TR[0]=TR[0].toString();
+ break;
+ case "NAN":
+ TR=[NaN,TR,false];
+ break;
+ case "LEN":
+ if(TR==false)throw new TTerror("Cannot LEN a non-existant root node!");
+ if(typeof TR[0]!="string")TR=[NaN,TR,false];
+ else TR=[TR[0].length,TR,false];
+ break;
+ case "SPL":
+ throw new TTerror("SPL not implemented!");
+ break;
case "SUM":break;
case "DIF":break;
case "PRO":break;
@@ -308,7 +325,9 @@ function runCmds(cmds,TR){
case "GRT":break;
case "TAU":break;
case "E__":break;
- case "RND":break;
+ case "RND":
+ TR=[~~(Math.pow(2,31)*Math.random()),TR,false];
+ break;
case "JMP":break;
case "EXJ":break;
case "IFJ":break;
diff --git a/treetree.md b/treetree.md
index 28e62ff..a5a4fe9 100644
--- a/treetree.md
+++ b/treetree.md
@@ -91,7 +91,7 @@
_Split_
**pop 1 int**
**put 1 str**
- Split the string in two between the the n-th character from the beginning of the string for positive numbers and between the (length+n)-th character for negative values of n. For all values for n that are out of string bounds throw an error.
+ Split the string at the root node (when the int is popped) in two between the the (n-1)-th and the n-th character from the beginning of the string for positive numbers and between the (length-n-1)-th and the (length-n)-th character for negative values of n. For all values for n that are out of string bounds or if no string was found at all, throw an error.
## Math, Arithmetic and Bitwise operators
@@ -176,7 +176,7 @@ Operations on illegal types will throw an error, and math errors will result in
- RND
_Random_
**put 1 int**
- Put a random integer.
+ Put a random integer between zero and an implementation-defined number, at least 32767, inclusively.
## Loops and Conditions
@@ -209,4 +209,4 @@ Useful for functions.
Integers and floating points are written down as one normally would, accepting an 'e' for an exponent, a minus sign in front for negative and a dot ('.') as the decimal separator. Strings are enclosed in "double quotes" and comments in 'single quotes' or, more preferably, in {braces}.
Special characters in strings can be written down as they are, with the sole exception of the double quote ("), which cannot be put in a string literal.
-Bare literals in the code get pushed into the tree such that the old root node becomes the first child of the newly pushed thing, and thus the newly pushed thing becomes the new root node. \ No newline at end of file
+Bare literals in the code get pushed into the tree such that the old root node becomes the first child of the newly pushed thing, and thus the newly pushed thing becomes the new root node.