Haphazard Inc.:
command node1 port1 node2 port2... ;comment
::
token node port
where command is a node that you want to make do something, and each node<number> and
port<number> is a where the node out puts to, at which port."token" is the data of a token
(aka. message) that you want to send node at port before you start the program. token can be
either an integer or a string (if the string has a space in it you need to put quotes around it).
public void addToken(Token token);
- adds a token in, I'll talk about those later.public void evaluate();
- makes the token do what it needs to dopublic boolean getCanDo();
- tells if it can evaluate it right nowpublic boolean constRepeat();
- if getCanDo() always returns true make this return
true or else any program that uses it will never stop
public WorkObject newOne(dataflow parent,StringTokenizer st);
- makes a new copy of
this node, using st for all the arguments
((WorkObject)parent.objects.get(thetoken.tokenTo - 1)).addToken(thetoken);
That is, if parent is the name of the parent dataflow object.
That brings us to tokens...
public class Token {
public Object data;
public int tokenTo;
public int port;
}
Pretty much self explanatory. data is the token's data(normally a String or Integer),tokenTo is
the target node's number, and port is the target node's port.
In case you need an example, there are a few in dataflow.java
dataflow a = new dataflow();
)
Then you should add in the nodes. It is recomended you first load in the defaults:
a.addNode("copy",(new CopyObject()));
a.addNode("+",(new AddObject()));
a.addNode("*",(new MulObject()));
a.addNode("-",(new SubObject()));
a.addNode("rsend",(new RSendObject()));
a.addNode("input",(new InpObject()));
a.addNode("gate",(new GateObject()));
a.addNode("/",(new DivObject()));
a.addNode("print",(new PrintObject()));
a.addNode("if",(new IfObject()));
The arguments are: the name you want it to have, an example of it.
You can use more of those to add on more nodes you created.
Next, you have to parse a file. Use a.parse(String filename);
.
Then you have to do: a.evalAll();