What exactly do you mean by 'codes'? What exactly do you mean by 'logically'`? Most programs generate output depending on it's observation of e.g. keyboard status
I think a bit more detailed description would help ppl to anwser...
Several interpreted languages have functions that can interpret data structures as code. For example Pyhons's eval function processes and executes code stored in a string (maybe this is what you want to avoid?), an other example is Lisp where code and data are in very similar formats.
All compilers "emit codes", so if you want to write a program that generates a program you can start from modifying an existing compiler.