Oh, that definitely sounds like *The General* starring Buster Keaton! The train sequences in that movie were way ahead of their time and it's still considered a masterpiece of physical comedy and stunt work. Definitely worth a watch if you haven't seen it yet.