Finished expression rewriting based on precedence