In Ppml, the function operator allows us to build functions that take abstract syntax trees as arguments and return an integer result according to the pattern of the tree's operator. We call our function prec, and define it before the rules section in the Exp-basic.ppml file:
function prec is prec (*op where *op in {assign}) = 4; prec (*op where *op in {plus,minus}) = 3; prec (*op where *op in {prod}) = 2; prec (*op where *op in {uminus}) = 1; prec (*op) = 0; end prec ;
The last pattern catches all other operators and assigns them the highest priority. In Exp, these are variable and integer, which will never be surrounded by parentheses.