How do programs like BUGS/JAGS automatically determine conditional distributions for Gibbs sampling? Seems like full conditionals are often quite difficult to derive, yet programs like JAGS and BUGS derive them automatically. Can someone explain how they algorithmically generate full conditionals for any arbitrary model specification?
 A: Reading through the comments on the othe answers, I believe the correct answer to the question that was intended to be asked is "they don't", in general. As has been mentioned, they construct a DAG and look at the Markov blanket and then (roughly) do the following.


*

*If the Markov blanket around a node correspond to a full conditional that is in a lookup table (say, because it is conjugate) sample from using the technique in the lookup table.

*Else, check is the if the unnormalized full conditional density - which is trivial to calculate - is log-concave. If it is, use adaptive rejection sampling.

*Else, sample using Metropolis-within-Gibbs to sample from the distribution approximately. While this isn't an exact sample, it can be shown that this algorithm still leaves the posterior invariant. 


This isn't exactly what is being done; for example, JAGS will use some other tricks to construct block updates. But this should give an idea of what they are doing.
A: I'm not sure why you think full conditionals are hard to derive. Given a complete joint prior probability density $\pi(\cdot)$ for both the parameters and data, the full conditional of, say, $\theta_i$ given $\theta_{-i}$ and the data is easy to derive: it's just proportional to the joint prior for parameters and data. It's easy to tell by inspection which elements of $\theta_{-i}$ can be dropped from the full conditional for $\theta_i$. 
Automatic Gibbs samplers carry out this "inspection"  by parsing a model specification into a probabilistic directed acyclic graph model. They then compute full conditionals as proportional to the full joint density of $\theta_i$'s Markov blanket. 
