Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
    
in which language would "int x = y = 5" work? I would assume the use of parentheses would clarify evaluation order and hence, LHS and RHS. itu.dk/courses/BPRD/E2009/fundamental-1967.pdf is about as authorative as it comes... –  lwm Aug 30 '13 at 8:57
    
It's a general statement, none of this is in a particular language - I've seen such statements in a few languages, C# and Java come to mind I think but it's been a while since I touched either, so might not have been those - have definitely seen it used (and warned against) before though. Although it's not something I ever use myself. I think (don't quote me - like I say, it's not something I ever personally use) the flow is the same as y = 5; int x = y;. –  Kai Aug 30 '13 at 9:03
    
The point was the terms LHS and RHS doesn't work so well when there are 3 "sides" to an expression, and it seems there ought to be be a none-side-specific term for each "chunk" of an equation. As in, the LHS and RHS are collectively an ... [insert answer here]. 'chunk' or 'component' or 'part' are the best terms I have so far. –  Kai Aug 30 '13 at 9:05
2  
@Kai (et al) the term term suggests itself. –  High Performance Mark Aug 30 '13 at 9:07
1  
Are you thinking of "lvalue" and "rvalue" ? stackoverflow.com/questions/3601602/… –  rwong Aug 30 '13 at 10:49

1 Answer 1

up vote 5 down vote accepted

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.

share|improve this answer
    
Very nice, learnt a few new terms here. Best suggestion so far :) –  Kai Aug 30 '13 at 12:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.