Given an expression, such as int x = y + 5
, we’d call int x
the left-hand side
(or LHS
), and y + 5
the right-hand side
(or RHS
). The whole expression is called, of course, an expression
(or equation
), but is there a generic term for a “side” of an expression?
LHS
and RHS
don’t quite cut it when it comes to an expression such as int x = y = 5
(gloss over the fact here that such assignments are generally bad practice!).
I’m toying with the term component
to describe any “side”, but was interested to see if there was a formal standard term already in use. Wikipedia only has “Sides of an equation”, any better suggestions?
10
I think you’re looking for the word operand. A unary operator has one operand. A binary operator has two operands; if the operator is infix, i.e. if the expression is written horizontally with the operator between the two operands, then the operands are known as the left-hand side and right-hand side (very commonly abbreviated LHS and RHS). There are other names when the operator is written differently, for example numerator and denominator for the fraction operator arranged vertically and marked by a horizontal bar. A ternary operator has three operands (which don’t have standard names; if they’re written from left to right, you might call them left, middle and right operand), and so on.
Assuming C, x ? y : z
has three operands for the ?:
operator which are x
, y
and z
. The syntactic element int x = y = 5
is not parsed as an expression with a single operator; x
, y
and z
are subexpressions but so is y = 5
. y
and 5
are operands of the operator =
. There is no generic term to designate x
and y = 5
here: in general parsing terminology, they are operands of the declaration operator, but in C terminology, the word operand is reserved for things that C calls operators.
If you want to treat int _ = _ = _
as a single unit (which isn’t how C syntax works), you can refer to the pieces as the left, middle and right subterms.
The word subterm can be used more or less interchangeably with subexpression in general parsing literature, but specific languages often make a difference between the two (often an expression is a particular kind of term, but occasionally it’s the opposite). You can refer to subterms which are one step down from a node in the parse tree as immediate subterms.
A term that cannot be decomposed any further is an atom.
0
IIRC from my high school days (some SIXTY years ago!), the left-hand side was called the comparator, and the right-hand side was called the “comparand”.
1