codesimian
Class CSBuilder
java.lang.Object
codesimian.CSBuilder
public class CSBuilder
- extends java.lang.Object
This class is obsolete for compiling.
It was replaced by inner classes of Compile.
Compile contains a lot of code from this class.
This class could be used for evolving code specified by a (CS) list of ints.
constructs a tree of CSs, given a sequence of ints.
Used as a CS, P(0).D() is the address where the new CS is put
(5/05 maybe it should put the compiled output in param0 instead of use param0 as an address),
and all params after that are used, in order, to build a tree.
Method Summary |
boolean |
addCS(CS addMe)
Adds in depth-first order
Returns if it was added
adds enough CSs to satisfy enoughParams() but not more (returns false then)
big-O(1) |
boolean |
addCS(int index)
Same as addCS(int,double) except Nums start at 0 |
boolean |
addCS(int index,
double numValue)
Makes a CS and calls addCS(CS) for it. |
int |
CSClassCount()
|
CS |
getTree()
|
static CS |
makeCS(java.lang.String CSs)
Compiles a String of CodeSimian code. |
void |
newTree()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
treeCount
public int treeCount
CSBuilder
public CSBuilder()
CSBuilder
public CSBuilder(int nodeVars)
CSClassCount
public int CSClassCount()
addCS
public boolean addCS(int index,
double numValue)
- Makes a CS and calls addCS(CS) for it.
index is the index of a CS in a CSFactory
index < CSClassCount()
numValue is only used if the CS added needs a double value (most dont)
addCS
public boolean addCS(int index)
- Same as addCS(int,double) except Nums start at 0
addCS
public boolean addCS(CS addMe)
- Adds in depth-first order
Returns if it was added
adds enough CSs to satisfy enoughParams() but not more (returns false then)
big-O(1)
getTree
public CS getTree()
newTree
public void newTree()
makeCS
public static CS makeCS(java.lang.String CSs)
- Compiles a String of CodeSimian code. Returns the compiled output: a tree of CSs.
CSs example "+( *(3.7 ?x ?z), /(?x ?y) )" //x, y, and z are other CSs
Infix notation "?x+?y" is not allowed. Instead use "+(?x ?y)".
All CSs must be followed by ( ). "num" is not valid, but "num()" is.
Case sensitive.
If multiple consecutive CSs exist but are not separated
by commas like in "divide( 3.5 add(x 2))", the commas are assumed.
CSs can not contain extra parenthesis. Example "add( 2.2, (mult(x,y)) )
Variables x, y, and z are converted to NodeVariables of different indexs.
Variable and class names can not contain: space comma parenthesis
should not be all numbers, will be confusing if you do it. Variable has priority over number.
String literals can be used in the code with single or double quotes.
Each char in the string is interpreted as a Const (subclass of CS).
This CodeSimian code: +( 3 print('add three") )
correctly uses a string literal.
It does not care that it uses 1 ' and 1 ".
They are used as the same symbol.
VariableOrder contains all variables to become NodeVariables
in the order they should receive NodeVariable indexs.
The first to appear in CSs gets NodeVariable(nodeVariableStart)
The second gets NodeVariable(nodeVariableStart+1)...
If variableOrder does not contain some variables in CSs,
they get indexs in the order they are found, after those in variableOrder.
If a NodeVariable or Num is created directly in CSs, it has an index or value of 0.
Some other variable might have 0 too, so dont do that.
Does not check CS.minP(). If you dont use enough
parameters in every CS in the tree, the tree will not work.
"sin:55(?x)" sets the myFuel for the Sin to 55. The first 55 times
that CS is executed, it calculates a new value. After that, unless
myFuel is reset, it returns the previous value of exec.
Its optional. You can still use "sine(?x)" to set myFuel to ALWAYS_CALCULATE.
$X is valid only for positive int values of X.