Combining logic programs and monadic second order logics by program transformation