Hi Shemida,
It's funny you should ask this, because it is something I have been working on. If you use true BPMN tool such as MagicDraw, then you can save (and load) your BPMN model in XMI format. This is a standard XML based format for saving UML models. Because it is XML, you can programatically generate it in any language. When you read the programatically generated XMI back into the modelling tool, you have a model. This is the first approach.
The second approach needs a BPMN tool that has a scripting language. You can then write plug-in to generate a BPMN model from some other representation that you create programatically externally to the tool.
Personally, I find generating the XMI most flexible. I have tried this with UML and the MagicDraw, Enterprise Architect and Visual Paradigm tools, and it works a treat. It should also work for BPMN in MagicDraw (at least), because if you use MagicDraw with the Cameo BPMN plug-in, BPMN is just treated as another UML profile - so the generated XMI is standard.
In terms of working out precisely what XMI to generate, you can look at the BPMN metamodel, but in many ways it is easier to do it by inspection. So when I wrote an XMI generator for Clojure (a version of Lisp than runs on the JVM), I created simple UML models in MagicDraw and exported these as XMI. I could then see exactly how the tool was representing the model in XML, and therefore, what I needed to generate. I have a blog post on some aspects of this here:
http://www.clearviewtraining.com/blog/
It is a work in progress.