NIM: 1801382963
Kali ini saya akan menjawab Assignment #7 dari Chapter 7 Programming Language Concepts R Sebesta
Review Questions
6. What
associativity rules are used by APL?
*In APL,
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.
7. What is
the difference between the way operators are implemented in C++ and Ruby?
*The
difference is in Ruby, all the arithmetic, relational, and assignment operator,
as well as array indexing, shifts, and bitwise logic operators, are implemented
as methods. While in C, they aren't implemented as methods.
8. Define functional side effect.
*A
functional side effect is a side effect of a function which occurs when the
function changes either one of its parameters or a global variable.
9. What is
a coercion?
*A coercion
is a process by which a compiler automatically converts a value of one type
into a value of another type when that second type is required by the
surrounding context.
10. What is
a conditional expression?
*A
conditional expression is an expression that returns value A or value B
depending on whether a Boolean value is true or false. A conditional expression
lets you write a single assignment statement that has the same effect as the
following:
if
condition:
x = true_value
else:
x = false_value
Problem Set
6. Should
C’s single-operand assignment forms (for example, ++count) be included in other
languages (that do not already have them)? Why or why not?
*Yes C
should, because those assigning operations make operation simpler and easy to
know if that operation is assigning operation. And it will ease the increment
or even decrement while we use in looping.
7. Describe
a situation in which the add operator in a programming language would not be
commutative.
*If the add
operator for a language is also used to concatenate strings, it’s quite
apparent that it would not be commutative.
For
example:
“abc” +
“def” = “abcdef”
“def” +
“abc” = “defabc”
These two
strings are obviously not equal, so the addition operator is not commutative.
8. Describe
a situation in which the add operator in a programming language would not be
associative.
*It is not
associative when it includes the other operator with higher precedence like the
multiplication and division.
9. Assume the following rules of
associativity and precedence for expressions:
Precedence
Highest *, /, not
+, –, &, mod
–
(unary)
=, /=, <, <=, >=, >
And
Lowest or, xor
Associativity Left to right
Show the order of evaluation of the
following expressions by parenthesizing all subexpressions and placing a superscript
on the right parenthesis to indicate order. For example, for the expression
a + b * c + d
the order of evaluation would be
represented as
((a
+ (b * c)1)2 + d)3
a.
a * b - 1 + c ((( a * b )1 - 1)2
+ c )3
b.
a * (b - 1) / c mod d (((
a * ( b - 1 )1 )2 / c )3 mod d )4
c.
(a - b) / c & (d * e / a - 3) (((a
- b)1 / c)2 & ((d * e)3 / a)4 -
3)5)6
d.
-a or c = d and e ((
-a )1 or ( ( c = d )2 and e )3 )4
e.
a > b xor c or d <= 17 (((a
> b)1 xor c)3 or (d <= 17)2 )4
f.
-a + b (–( a + b )1 )2
10. Show the order of evaluation of
the expressions of Problem 9, assuming that there are no precedence rules and
all operators associate right to left.
*
a. ( a * ( b – ( 1 + c )1
)2 )3
b. ( a * ( ( b – 1 )2 / (
c mod d )1 )3 )4
c. ( ( a – b )5 / ( c
& ( d * ( e / ( a – 3 )1 )2 )3 )4
)6
d. ( – ( a or ( c = ( d and e )1
)2 )3 )4
e. ( a > ( xor ( c or ( d <=
17 )1 )2 )3 )4
f. ( – ( a + b )1 )2
No comments:
Post a Comment