From c275a149eec2f8641dbce4cdf114ab0dca5216ff Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Thu, 24 Apr 2014 22:14:39 +0200 Subject: Initial commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Already did some programming though… --- factorial.trt | 9 ++ io.trt | 11 ++ newlojban.trt | 6 + primes.trt | 29 +++++ pshpll.trt | 38 ++++++ treetree.js | 384 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ treetree.md | 212 ++++++++++++++++++++++++++++++++ 7 files changed, 689 insertions(+) create mode 100644 factorial.trt create mode 100644 io.trt create mode 100644 newlojban.trt create mode 100644 primes.trt create mode 100644 pshpll.trt create mode 100755 treetree.js create mode 100644 treetree.md diff --git a/factorial.trt b/factorial.trt new file mode 100644 index 0000000..f2e628b --- /dev/null +++ b/factorial.trt @@ -0,0 +1,9 @@ +"Factorial for num:" OUT +INP FLT +#loop + DUP + 1 DIF +DUP 1 GRT @loop IFJ +SWP +PI_ +STR OUT \ No newline at end of file diff --git a/io.trt b/io.trt new file mode 100644 index 0000000..1986ff3 --- /dev/null +++ b/io.trt @@ -0,0 +1,11 @@ +inp out +"io.trt" ifi +inp out " +" out +"io.out.txt" ofi +inp out " +" out +ius +inp out +ous +inp out \ No newline at end of file diff --git a/newlojban.trt b/newlojban.trt new file mode 100644 index 0000000..f319e57 --- /dev/null +++ b/newlojban.trt @@ -0,0 +1,6 @@ +RND RND RND RND RND +SWP +26 MOD +97 SUM +"" SUM +SIG OUT \ No newline at end of file diff --git a/primes.trt b/primes.trt new file mode 100644 index 0000000..84a0f55 --- /dev/null +++ b/primes.trt @@ -0,0 +1,29 @@ +"Up to which number do you want a list of primes?" OUT +INP INT +"Here you go:" OUT +2 2 +"2" OUT +#MAIN +1 SUM +DUP +2 PLL +DUP +3 PSH +MOD +PI_ +NOT +@NOPRIME IFJ +DUP +2 PSH +1 GRB +1 PLL +DUP +STR +OUT +#NOPRIME +DUP +3 PLL +DUP +4 PSH +SML +@MAIN IFJ \ No newline at end of file diff --git a/pshpll.trt b/pshpll.trt new file mode 100644 index 0000000..5418c15 --- /dev/null +++ b/pshpll.trt @@ -0,0 +1,38 @@ +2 pll + +{ +[3, + [2, + [1,false,false], + ["a", + false, + ["b",false,false]]], + ["b", + ["xx",false,false], + false]] + + +3--"b" +| | +| "xx" +| +2--"a"--"b" +| +| +| +1 + +----------> +1 +| +| +| +3--"b" +| | +| "xx" +| +2--"a"--"b" + + +[1,[3,[2,false,["a",false,["b",false,false]]],["b",["xx",false,false],false]],false] +} \ No newline at end of file diff --git a/treetree.js b/treetree.js new file mode 100755 index 0000000..1c0e0ff --- /dev/null +++ b/treetree.js @@ -0,0 +1,384 @@ +#!/usr/bin/env node + +var fs=require("fs"),util=require("util"),kbd=require("kbd"); + +var flags={"debug":false},TRpreload=undefined; + +if(process.argv.length<3){ + console.log("Please supply a treetree source file on the command line."); + console.log("\t-d Debug stuff."); + console.log("\t-s Preload stack in internal JSON array format in next parameter."); + process.exit(1); +} else { + var i,j,skipArg=false; + for(i=2;i0){ //PSH + var next_part,next_part_parent,moved_node,i; + next_part_parent=TR; + for(i=0;i NaN) + +- SUM + _Sum_ + 1. The sum of two numbers. + 2. Concatenation of two strings. +- DIF + _Difference_ + The difference between two numbers +- PRO + _Product_ + 1. The product of two numbers + 2. A number of times a string concatenated to itself. +- QUO + _Quotient_ + The quotient of two numbers +- POW + _Power_ + The first parameter raised to the second parameter's power. +- ROO + _Root_ + The first parameter's root of the first parameter's degree. +- LOG + _Logarithm_ + The second parameter's log of the first parameter. +- MOD + _Modulo_ + The remainder of a division of the first and second parameter. +- SIG + _Sigma/Summation_ + The sum of the root node and all its secondary children. +- PI\_ + _Pi/Product_ + The product of the root node and all its secondary children. +- OR\_ + _Bitwise Or_ + The bitwise or of two integers. +- AND + _Bitwise And_ + The bitwise and of two integers. +- XOR + _Bitwise Xor_ + The bitwise xor of two integers. +- INV + _Bitwise Invert_ + The bitwise inversion of an integer. +- NOT + _Not_ + A boolean not of an integer. (equal to n<1) +- EQU + _Equal_ + Compare to datatypes and put true when they are equal and otherwise put false. +- NEQ + _Not Equal_ + Compare to datatypes and put true when they are not equal and otherwise put false. +- SML + _Smaller than_ + Compare to datatypes and put true when the first is smaller than the second and otherwise put false. +- GRT + _Greater than_ + Compare to datatypes and put true when the first is greater than the second and otherwise put false. + +## Constants and Generated Variables + +- TAU + _Tau_ + **put 1 flt** + Put the ratio of a circle's circumference to its radius, equal to 2π. +- E__ + _e_ + **put 1 flt** + Put Euler's number. +- RND + _Random_ + **put 1 int** + Put a random integer. + +## Loops and Conditions + +- JMP + _Jump_ + **pop 1 int** + Let the n-th command be the next one. +- EXJ + _Extended Jump_ + **pop 1 int** + **put 1 int** + Let the n-th command be the next and put back an integer with the position of the command after this EXJ. +Useful for functions. +- IFJ + _If Jump_ + **pop 1 int** + If the second parameter is true, jump to the first parameters position. +- STP + _Stop_ + Terminate the program + +## Debug functions + +- STK + _Stack_ + Output the stack without popping anything. + +## Literals + +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 -- cgit v1.2.3