Programming Language Concept – Chapter 7

Review Question

1. Define operator precedence and operator associativity.

answer: operator precedence = expression evaluation partially define the order in which the operators of different precedence levels are evaluated. operator associativity = When an expression contains two adjacent occurrences of operators with the same level of precedence, the question of which operator is evaluated first

3.What is a prefix operator?

answer: the operator precede the operands

5. What operator usually has right associativity?

asnwer: the indices never need to be stored

6. What associativity rules are used by APL?

answer: all operators have the same level of precedence. Thus, the order of evaluation of operators in APL expressions is determined entirely by the associativity rule, which is right to left for all operators.

8. Define functional side effect.

answer: A side effect of a function, naturally called a functional side effect,occurs when the function changes either one of its parameters or a global variable. (A global variable is declared outside the function but is accessible in the function).

9. What is a coercion?

answer: an implicit type conversion that is initiated by the compiler

10. What is an overloaded operator?

answer: This multiple use of an operator and is generally thought to be acceptable, as long as neither readability nor reliability suffers.

14. What is a mixed-mode expression?

answer: Languages that allow arithmetic expressions is whether an operator can have operands of different types

15. What is referential transparency?

answer: 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

Problem Set

1. When might you want the compiler to ignore type differences in an expression?

answer: run time

3.Do you think the elimination of overloaded operators in your favorite language would be beneficial?Why or why not?

answer: no, because operator need to multiply use the operator, so it won’t be hard to use the operator again and again

4. Would it be a good idea to eliminate all operator precedence rules and
require parentheses to show the desired precedence in expressions? Why
or why not?

answer: no, because it partially define the order in which the operators of different precedence levels are evaluated

14. What is your primary argument against (or for) the operator precedence
rules of APL?

answer: The operator precedence rules of the common imperative languages are nearly all the same, because they are based on those of mathematics.

15. Explain why it is difficult to eliminate functional side effect in C.

answer: Because C programming is sensitive and it not detecting where is functional side effect. The operator precedence rules of the common imperative languages are nearly all the same, because they are based on those of mathematics.

Leave a comment