Programming-by-Demonstration for Long-Horizon Robot Tasks