A topos foundation for theories of physics: I. Formal languages for physics