From 6ec10e1b7f7babaac0a30d73778ed00e29a88f7d Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Tue, 29 Apr 2014 15:05:15 +0200 Subject: More stuff. No description, really --- newlojban.trt | 2 +- treetree.js | 77 ++++++++++++++++++++++++++++++++++++++++++++++------------- treetree.md | 2 ++ 3 files changed, 63 insertions(+), 18 deletions(-) diff --git a/newlojban.trt b/newlojban.trt index f319e57..8cf7aaf 100644 --- a/newlojban.trt +++ b/newlojban.trt @@ -1,6 +1,6 @@ RND RND RND RND RND SWP -26 MOD +'26 MOD 97 SUM "" SUM SIG OUT \ No newline at end of file diff --git a/treetree.js b/treetree.js index 2b186ae..d0d863e 100755 --- a/treetree.js +++ b/treetree.js @@ -47,16 +47,23 @@ function extractCmd(code,startat){ var i; while((code[startat]==" "||code[startat]=="\t"||code[startat]=="\n")&&startatTR[1][0].length)throw new TTerror("Invalid split position "+TR[0]+" in SPL!"); + if(TR[0]==0)TR[0]=""; + else { + TR[0]=TR[1][0].slice(0,TR[0]); + TR[1][0]=TR[1][0].slice(TR[0]); + } + break; + case "SUM": + var total,item,addto; + if(TR==false||TR[1]==false)throw new TTerror("Not enough tree items in SUM!"); + if(TR[2]!=false&&TR[1][2]!=false)throw new TTerror("Only one base node can have secondary children in SUM!"); + if(TR[2]==false&&TR[1][2]==false){ + TR[0]+=TR[1][0]; + TR[1]=TR[1][1]; + break; + } + if(TR[2]!=false){ + addto=TR[1][0]; + TR[1]=TR[1][1]; + TR[0]=TR[0]+addto; + for(item=TR[2];item!=false;item=TR[2]){ + if(item[1]!=false)throw new TTerror("No primary children allowed in chain of secondary children (in SUM)!"); + item[0]=item[0]+addto; + } + } else { + addto=TR[0]; + TR=TR[1]; + TR[0]=addto+TR[0]; + for(item=TR[2];item!=false;item=TR[2]){ + if(item[1]!=false)throw new TTerror("No primary children allowed in chain of secondary children (in SUM)!"); + item[0]=addto+item[0]; + } + } break; - case "SUM":break; case "DIF":break; case "PRO":break; case "QUO":break; @@ -326,7 +369,7 @@ function runCmds(cmds,TR){ case "TAU":break; case "E__":break; case "RND": - TR=[~~(Math.pow(2,31)*Math.random()),TR,false]; + TR=[~~(/*Math.pow(2,31)*/10*Math.random()),TR,false]; break; case "JMP":break; case "EXJ":break; @@ -373,14 +416,14 @@ this node) and the third containing the second child. An absent child is of course indicated with the literal value `false`. For example, the following program: 1 2 3 SWP 4 -makes the tree (*'s indicating absence of children, / is a primary child, -- +makes the tree (*'s indicating absence of children, | is a primary child, -- is a secondary child): - 4 * - / - 3--2 * - * / - 1 * - * +4* +| +3--2* +* | + 1* + * and is represented in `TR` like: [4, [3, diff --git a/treetree.md b/treetree.md index a5a4fe9..d8b33ad 100644 --- a/treetree.md +++ b/treetree.md @@ -1,3 +1,5 @@ +# Treetree language specification + ## Input and Output operations - INP -- cgit v1.2.3