7-Expressions%20and%20Assignment%20Statements - 7...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
ICS 313 - Fundamentals of Programming Languages 1 7. Expressions and Assignment Statements 7.2 Arithmetic Expressions ± Their evaluation was one of the motivations for the development of the first programming languages ± Arithmetic expressions consist of operators, operands, parentheses, and function calls ± Design issues for arithmetic expressions ` What are the operator precedence rules? ` What are the operator associativity rules? ` What is the order of operand evaluation? ` Are there restrictions on operand evaluation side effects? ` Does the language allow user-defined operator overloading? ` What mode mixing is allowed in expressions?
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 7.2 Arithmetic Expressions (continued) ± A unary operator has one operand ± A binary operator has two operands ± A ternary operator has three operands ± The operator precedence rules for expression evaluation define the order in which “adjacent” operators of different precedence levels are evaluated (“adjacent” means they are separated by at most one operand) ± Typical precedence levels ` parentheses ` unary operators ` ** (if the language supports it) ` *, / ` +, - 7.2 Arithmetic Expressions (continued) ± The operator associativity rules for expression evaluation define the order in which adjacent operators with the same precedence level are evaluated ± Typical associativity rules: ` Left to right, except **, which is right to left ` Sometimes unary operators associate right to left (e.g., FORTRAN) ± APL is different; all operators have equal precedence and all operators associate right to left ± Precedence and associativity rules can be overriden with parentheses ± Operand evaluation order The process: ` Variables: just fetch the value ` Constants: sometimes a fetch from memory; sometimes the constant is in the machine language instruction ` Parenthesized expressions: evaluate all operands and operators first
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/15/2010 for the course ICS ics103 taught by Professor Alvi during the Spring '07 term at King Fahd University of Petroleum & Minerals.

Page1 / 8

7-Expressions%20and%20Assignment%20Statements - 7...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online