07-expressions - CSE 452: Programming Languages Expressions...

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

View Full Document Right Arrow Icon
1 CSE 452: Programming Languages Expressions and Control Flow 2 Organization of Programming Languages-Cheng Outline of Today’s Lecture Expressions and Assignment Statements Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-circuit evaluation Assignment Statements Mixed mode assignment
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 3 Organization of Programming Languages-Cheng Expressions Expressions are the fundamental means of specifying computations in a programming language Types: Arithmetic Relational/Boolean 4 Organization of Programming Languages-Cheng 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 2
3 5 Organization of Programming Languages-Cheng Arithmetic Expressions Types of operators A unary operator has one operand: - x A binary operator has two operands: x + y Infix: operator appears between two operands Prefix: operator precede their operands A ternary operator has three operands: (x > 10)? 0 : 1 Evaluation Order Operator evaluation order Operand evaluation order 6 Organization of Programming Languages-Cheng Operator Evaluation Order Four rules to specify order of evaluation for operators Operator precedence rules o Define the order in which the operators of different precedence levels are evaluated (e.g., + vs * ) Operator associativity rules o Define the order in which adjacent operators with the same precedence level are evaluated (e.g., left/right associative) Parentheses o Precedence and associativity rules can be overriden with parentheses Conditional Expressions ( ?: operator in C/C++/Perl) o Equivalent to if-then-else statement
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 7 Organization of Programming Languages-Cheng Operand Evaluation Order When do we evaluate operand? Variables are evaluated by fetching their values from memory Constants Sometimes, constants are evaluated by fetching its value from memory; At other times, it is part of the machine language instruction Parenthesized expressions If operand is a parenthesized expression, all operators it contains must be evaluated before its value can be used as an operand Function calls Must be evaluated before its value can be used as an operand 8 Organization of Programming Languages-Cheng Operand Evaluation Order Functional Side Effects When function changes one of its params/global variable a + fun(a) If fun does not have the side effect of changing a , then the order evaluation of the two operands,
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 14

07-expressions - CSE 452: Programming Languages Expressions...

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

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