Balanced input parsing