TreeExpression implementation and tests