parser and tree re-writing