Chapter 7 Flashcards
Expressions and Assignment Statements
___ are the fundamental means of specifying computations in a programming language.
Expressions
It is crucial for a programmer to understand both the ___ and ___ of expressions of the used language.
syntax and semantics
To understand expression evaluation, it is necessary to be familiar with the ___ of ___ and ___ evaluation.
order, operator, operand
Although the value of an expression sometimes depends on it, the order of operand evaluation in expressions is often ___ by language designers.
unstated
Implementors being allowed to choose order of operand evaluations in expressions can lead to the possibility of programs producing ___ results in different implementations.
different
Other issues in expression semantics are ___ ___, ___, and ___-___ evaluation.
type mismatches, coercions, short-circuit
The essence of imperative programming languages is the ___ role of assignment statements.
dominant
The purpose of assignment statements in imperative languages is to cause the ___ ___ of changing the values of variables, or the state, of the program.
side effect
An integral part of all imperative languages is the concept of variables whose values change during program ___.
execution.
Functional languages use variables of a different sort, such as the parameters of ___.
functions
Functional languages, like imperative languages, also have declaration statements that bind values to ___.
names
Declarations of functional languages are similar to assignment statements, but do not have ___ ___
side effects
Automatic evaluation of arithmetic expressions similar to those found in mathematics, science, and engineering was one of the ___ of the first ___-___ programming languages.
goals, high-level
Most of the characteristics of arithmetic expressions in programming languages were inherited from convention that had evolved in ___.
mathematics.
In programming languages, arithmetic expressions consist of ___, ___, ___, and ___ ___.
operators, operands, parentheses, and function calls.
An operator can be ___, meaning it has a single operand, ___, meaning it has two operands, or ___, meaning it has three operands.
unary, binary, ternary
In most programming languages, binary operators are ___, which means they appear between their operands.
infix
Some languages, such as Perl, has some operators that are ___, which means they precede their operands.
prefix
Some languages have operators that are ___, which means they come after their operands.
postfix
The ___ precedence and ___ rules of a language dictate the order of evaluation of its operators.
operator, associativity
The ___ ___ rules for expression evaluation partially define the order in which the operators of different precedence levels are evaluated.
operator precedence rules
The operator precedence rules for expressions are based on the ___ of operator priorities, as seen by the language designer.
hierarchy
The operator precedence rules of the common imperative languages are nearly all the same, because they are based on those of ____.
mathematics
Unary addition is called the ___ operator because it usually has no associated operation and thus has no effect on its operand.
identity
Associatiativity in common languages is __ to __; however, there are exceptions in, such as in exponentiation in Fortran & Ruby which is ___ to __.
left to right; right to left
An ___ exception can cause addition/subtraction not to be associative.
overflow
All arithmetic and logic operations in Lisp are performed by ___.
subprograms
If neither of the operands of and operator has ___ ___, then operand evaluation order is irrelevant.
side effects
Operand evaluation order becomes relevant when there are ___ ___.
side effects
A ___ ____ of a function, occurs when the function changes either one of its parameters or a global variable.
side effect
Two possible solutions to the problem of operand evaluation order and side effects are:
1) Language designer could disallow functional side effects
2) The language definition could state that operands in expressions are to be evaluated in a particular order
The problem with disallowing function side effects in the imperative languages is difficult and it eliminates some ___ for the programmer.
flexibility (i.e., disallowing access to global variables)
The problem with having a strict evaluation order is that some code optimization techniques used by compilers involve ___ operand evaluations.
reordering
A program has the property of ___ ___ if any two expressions in the program that have the same value can be substituted for one another anywhere in the program, without affecting the action of the program.
referential transparency
result1 = (fun(a) + b / (fun(a) - c); temp = fun(a) result2 = (temp = b)/ (temp - c)
The example code above has referential transparency if ___?
result 1 = result2
The most important advantage of referentially transparent programs is that the ___ of such programs is much easier to understand than those that are not referentially transparent.
easier
Being referentially transparent makes a function equivalent to a ___ function, in terms of ease of understanding.
mathematical
Because they do not have variables, programs written in pure ___ languages are referentially transparent.
functional
Functions in a pure functional languages cannot have ___, which would be stored in local variables.
state
The multiple use of an operator is called ___ ___ and is generally thought to be acceptable, as long as neither readability nor reliability suffers.
operator overloading
A ___ conversion converts a value to a type that cannot store even approximations of all of the values of the original type.
Narrowing
Ex: converting a double to a float in Java is a narrowing conversion because the range of double is much larger than that of float.
A ___ conversion converts a value to a type that can include at least all of the values of the original type.
Widening
Between widening and narrowing conversions, ___ is nearly always safe, although they can result in ___ accuracy.
widening, reduced
ex: integer to float can be a loss in precision because both are stored in 32 bits; float allows for 7 decimal places while integer allows for 9 (in many language implementations)
Expressions that allow operands of different types are called ___-___ expressions.
mixed mode
Languages that allow mixed-mode expressions must define ___ for implicit operand type conversions.
conventions
Explicit type conversions are called ___.
casts
The most common error occurs when the result of an operation cannot be represented in the memory cell where it must be stored; this is called ___ or ___ depending on whether the result was too large or too small.
overflow, underflow
Floating-point overflow, underflow, and division by zero are examples of run-time errors, which are sometimes called ___.
exceptions
A ___ operator is an operator that compares the values of its two operands.
relational
Unless not available in the language, the value of a relational expression is ___.
Boolean
Boolean expressions consist of Boolean ___, Boolean ___, ___ ___, and Boolean ___.
variables, constants, relational expressions, operators (ex: AND OR NOT XOR)
A ___-___ evaluation of an expression is one in which the result is determined without evaluating all of the operands and/or operators.
short-circuit
(13 * a) * (b / 13 - 1) can be short-circuited when a = ___
0 because anything multiplied by 0 is 0
The Boolean expression
(A >= 0) && (b < 10) can be short-circuited when
A < 10 because && dictates both statements must be true, if the first is false, no need to continue
Programming languages that use an ___ as an assignment operator must use something different for the equality relational operator to avoid confusion with their assignment operator.
=
A ___ assignment operator is a shorthand method of specifying a commonly needed form of assignment.
compound
ex: sum += value same as
sum = sum + value
What are the two special unary arithmetic operators and what do they do?
++ increment, – decrements
ex: sum = ++ count (The value of count is incremented by 1 and assigned to sum)
sum = count ++ (The value of count is assigned to sum, then count is incremented