Concepts of Programming Languages

(Sean Pound) #1
Programming Exercises 345


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

  2. Explain why it is difficult to eliminate functional side effects in C.

  3. For some language of your choice, make up a list of operator symbols
    that could be used to eliminate all operator overloading.

  4. Determine whether the narrowing explicit type conversions in two lan-
    guages you know provide error messages when a converted value loses its
    usefulness.

  5. Should an optimizing compiler for C or C++ be allowed to change the
    order of subexpressions in a Boolean expression? Why or why not?

  6. Answer the question in Problem 17 for Ada.

  7. Consider the following C program:


int fun(int *i) {
*i += 5;
return 4;
}
void main() {
int x = 3;
x = x + fun(&x);
}

What is the value of x after the assignment statement in main, assuming

a. operands are evaluated left to right.


b. operands are evaluated right to left.



  1. Why does Java specify that operands in expressions are all evaluated in
    left-to-right order?

  2. Explain how the coercion rules of a language affect its error detection.


PROGRAMMING EXERCISES



  1. Run the code given in Problem 13 (in the Problem Set) on some system
    that supports C to determine the values of sum1 and sum2. Explain the
    results.

  2. Rewrite the program of Programming Exercise 1 in C++, Java, and C#,
    run them, and compare the results.

  3. Write a test program in your favorite language that determines and
    outputs the precedence and associativity of its arithmetic and Boolean
    operators.

Free download pdf