Java implementation of precedence climbing