sherpa.models.op.get_precedence_lhs(lstr: str, lp: int, p: int, a: bool) str[source] [edit on github]

Return the string to use for the left side of a binary operator.

This is only needed when the operator (represented by the p value) is written in infix form - such as ‘a + b’- rather than prefix form like ‘np.add(a, b)’.

  • lstr (str) – The term to the left of the operator.

  • lp (int) – Precedences of any operator in lstr.

  • p (int) – Precedences of the current operator.

  • a (bool) – Do we care about power-like terms.


term – Either lstr or (lstr).

Return type:



>>> get_precedence_lhs("a", NO_PRECEDENCE, lprec[np.divide], False)
>>> get_precedence_lhs("a + b", lprec[np.add], lprec[np.divide], False)
'(a + b)'
>>> get_precedence_lhs("a * b", lprec[np.multiply], lprec[np.add], False)
'a * b'