converting TD and BU grammar formats into each other