How to represent software code for code generation / automatic programming? How to integrate procedural and declarative knowledge?
Use some form of metamodelling :


  The outputs are represented as abstract syntax trees (ASTs):





  and constructed by a decoder with a dynamically-determined modular structure paralleling the structure of the output tree.




References


Modelling homogeneous generative meta-programming
Abstract Syntax Networks for Code Generation and Semantic Parsing
Canonical Abstract Syntax Trees
Pattern Reification as the Basis for Description-Driven Systems
Metamodelling: State of the Art and Research Challenges
DSL development based on target meta-models. Using AST transformations for automating semantic analysis in a textual DSL framework
The Machine that Builds Itself:
How the Strengths of Lisp Family Languages
Facilitate Building Complex and Flexible
Bioinformatic Models
Reasoning About LLVM Code Using Codewalker
Foundations of meta-programming