Stochastic chains with memory of variable length