 in programming languages, the associativity (or fixity) of an operator is a property that determines how operators of the same precedence are grouped in the absence of parentheses. if an operand is both preceded and followed by operators (for example, "^ 4 ^"), and those operators have equal precedence, then the operand may be used as input to two different operations (i.e. the two operations indicated by the two operators). the choice of which operations to apply the operand to, is determined by the "associativity" of the operators. operators may be associative (meaning the operations can be grouped arbitrarily), left-associative (meaning the operations are grouped from the left), right-associative (meaning the operations are grouped from the right) or non-associative (meaning operations can not be chained, often because the output type is incompatible with the input types). the associativity and precedence of an operator is a part of the definition of the programming language; different programming languages may have different associativity and precedence for the same type of operator. consider the expression a ~ b ~ c. if the operator ~ has left associativity, this expression would be interpreted as (a ~ b) ~ c. if the operator has right associativity, the expression would be interpreted as a ~ (b ~ c). if the operator is non-associative, the expression might be a syntax error, or it might have some special meaning. some mathematical operators have inherent associativity. for example, subtraction and division, as used in conventional math notation, are inherently left-associative. addition and multiplication, by contrast, have no inherent associativity, though most programming languages define an associativity for these operations as well. many programming language manuals provide a table of operator precedence and associativity; see, for example, the table for c and c++. the concept of notational associativity described here is related to, but different from the mathematical associativity. an operation that is mathematically associative, by definition requires no notational associativity. (for example, addition has the associative property, therefore it does not have to be either left associative or right associative.) an operation that is not mathematically associative, however, must be notationally left-, right-, or non-associative. (for example, subtraction does not have the associative property, therefore it must have notational associativity.) == examples == associativity is only needed when the operators in an expression have the same precedence. usually + and - have the same precedence. consider the expression 7 â 4 + 2. the result could be either (7 â 4) + 2 = 5 or 7 â (4 + 2) 
Operators_(programming) Parsing Programming_language_topics