I started development of simulator for simulation of distributed algorithms in language C. My work consist of creating simple language for algorithm description and simulator which takes the described algorithm and simulates it.
At first I decided how to represent distributed environment. This simulator will run on single machine so there was need to somehow simulate entities which create distributed environment and do some task according to provided algorithm. Every entity will be represented as data structure called Entity. This data structure will contain all data related to entity, for example state of the entity, local registers of the entity.
For representing topology and connections I want to use some library for graphs in C to represent topology as set of vertices and edges. This vertices and edges will certainly be part of Entity so it can get access it's neighbors for example when it is sending data to them.
Next step was to create simple language so user can easily describe the algorithm and simulate it.
For better depiction here is the example of algorithm flooding.
STATUS = INITIATOR, IDLE, DONE; INIT = INITIATOR, IDLE; TERM = DONE; REGISTERS = ; INITIATOR RANDOM begin SEND(x, NEIGHBORS); BECAME(DONE); end IDLE RECEIVE(x) begin SEND(x, NEIGHBORS - SENDER) BECAME(DONE); end
At this stage I am working on specification for this language and I got stuck. I am not sure how to properly specify this language. It should be simple but when i for example want to implement command for sending message to another entity I must consider that targets may be various. Targets could be all neighbors or all neighbors except sender or maybe only sender or later in development it should by possible to declare specific target from all entities in environment.
At this point I have two options in mind.
First is using Flex and Bison to analyze and parse input. then gather all data needed and run threads and let them behave according to all possible behaviors in input file with algorithm.
Second option is not to use Flex and Bison and implement every command as C macro. User will use this macros to write input file with algorithm and this file will be linked to simulator with gcc compiler, so when user uses macro in wrong way the compiler will throw an error.
I would like to ask if someone was developing something similar or what kind of approach or technique to choose if exists. I want to implement it in C but maybe other language would be more better for this type of thing.