Chapter 7 - Expressions and Assignment Statements Flashcards Preview

Advanced Topics in Programming Languages > Chapter 7 - Expressions and Assignment Statements > Flashcards

Flashcards in Chapter 7 - Expressions and Assignment Statements Deck (17):
1

What are the 6 design issues with arithmetic expressions?

1) what are operator precedence rules

2) what the operator associativity rules

3) what is the order of operand evaluation

4) are there restrictions on operand evaluation side effects?

5) is user-defined operator overloading allowed?

6) what mode mixing is allowed in expressions

2

What are the definitions of unary, binary and ternary operators

unary = has one operand

binary = has two operands

ternary = has three operands

3

What is the typical order of operator precedence

parentheses
unary operators
** (exponentiation)
*,/
+,-

just like you learned in middle school

4

Examples of unary operators

'-' (ex: -5 changes five to its negative value)

'+' (ex: +5 this is valid syntax but it does ABSOLUTELY NOTHING)

'++' and '--'

5

What are the typical associativity rules?

exactly what you learned in school for the most part

left to right

EXCEPT for exponentiation operator which is right-to-left so:

2 ** 3 ** 4 == 2 ** (3 ** 4)

6

What is the order of operand evaluation?

1) variable - fetch the values

2) constants - fetch value

3) parenthesized expressions (evaluate fully)

4) function references

7

definition of functional side effects

when a function changes a two-way parameter or non-local variable

8

2 solutions for handling expressions containing function references that produce functional side effects relevant to other values in the expression

1) don't allow function side effects by disallowing two-way parameters and non-local references

2) make the language force operand evaluation order to be fixed

9

2 disadvantages of operator overloading

detriment to readability

loss of compiler error detection

10

definition of narrowing conversion

one that converts an object to a type that may not be able to hold some of the possible values of the original type

11

definition widening conversion

one that converts an object to a type that can at least approximate all the possible values of the original type if not hold them exactly

12

definition of a mixed-mode expression

an expression that contains operands of different types

13

Explicit type conversion vs implicit type conversion

explicit = conversion performed by some directive provided by the programmer (ie. casting)

implicit = conversion performed by the compiler with no directive from the programmer (ie, narrowing and widening conversions, coercion)

14

definition of a relational operator

an operator that compares the values of its two operands. The result of a relational expression is a boolean

ex) ==, !=

15

Precedence arithmetic ops, relational ops, and boolean ops

highest
-postfix arithmetic ops (++ and --)
-unary ops
normal arithmetic ops
relational ops: less than/greater than
relational ops: equal/not equal
boolean ops: AND
boolean ops OR

16

definition of short-circuit evaluation

an expression which can be fully evaluated without evaluating all of the operands and/or operators

ex: a < 5 && b > 10 (if a=6 then the expression will always be false regardless of the value of b)

a*(b-2) (if a=0, then the expression will always equal 0 regardless of the value of b)

17

Which PLs default to short-circuit boolean expressions?

C-based
Perl
Ruby
Python
ML