Trees, valuations, and the Bieri-Neumann-Strebel invariant