DCG can be a great choice!
I used a similar approach to generate UML class diagrams (in fact, the code for the graphical code for such diagrams) from simple English sentences (shameless-plug: document here ). Instead, it should be possible to do something similar with generating Perl code.
(CHR) , . / DCG.
, DCG , Perl.