While not exactly what you are asking - this might be of some assistance, http://stackoverflow.com/questions/4946213/petri-net-drawing-and-code-generation
In general, it is not possible to generate a Petri net N from an arbitrary source program P so that N precisely models the execution of P. The reason is that Petri nets are not Turing powerful. However, it is possible to ``approximate'' P and obtain a Petri net that precisely models the execution of the approximation. For a core fragment of Erlang we have written a tool that generates a Petri net from an approximation (http://mjolnir.cs.ox.ac.uk/soter/). You can also feed the Petri net to a model-checker.
The website has links to the papers that explains our method.
It is not exactly what you are looking for, but you can generate a Stochastic Petri Net from UML. Take a look at:
Juan Pablo López-Grao, José Merseguer, and Javier Campos. From UML Activity Diagrams to Stochastic Petri Nets: Application to software performance engineering. SIGSOFT Software Engineering Notes, 29(1):25–36, 2004.
In the following paper you can find a procedure to create a Petri Net starting from the specification of tasks. Paper is on hybrid PNs but if you don't have continuous or hybrid behavior you obtain a discrete PN.
Francesco Basile, Fabrizio Caccavale, Pasquale Chiacchio, Jolanda Coppola, Alessandro Marino, Diego Gerbasio, Automated synthesis of hybrid Petri net models for robotic cells in the aircraft industry, Control Engineering Practice, Volume 31, October 2014, Pages 35-49, ISSN 0967-0661, http://dx.doi.org/10.1016/j.conengprac.2014.05.008.