NIM : 1801428434
Here is the seventh assignment of Programming Language Concepts course. The question is taken from "Concepts of Programming Language, 10th edition" from Robert W. Sebesta in chapter 7:
Review Questions
1. Define operator precedence and operator associativity.
=
- Operator precedence: defines order and priority of the operator evaluation from different precedence levels.
- Operator precedence: defines order and priority of the operator evaluation from different precedence levels.
- Operator associativity: defines the order of operators
evaluation when it is from the same precedence level.
2. What is a ternary operator?
= Ternary operator is an operator with three operands.
3. What is a prefix operator?
= Prefix operator is a operator that precede their operands
4. What operator usually has right associativity?
= Operator that usually has right associativity are operator
which can be found in Fortran and Ruby.
5. What is a nonassociative operator?
= Nonassociative
operator means that the expression is illegal.
Problem set:
1. When might you want the compiler to ignore type differences
in an expression?
= When I want to evaluate a string as a number.
2. State your own arguments for and against allowing mixed-mode
arithmetic expressions.
=
- For: A mixed mode arithmetic expression is needed in calculating expressions that might have decimal results. It is compulsory as it allows two different type of number data type such as float and integer to be summed without losing the precision of the float.
- For: A mixed mode arithmetic expression is needed in calculating expressions that might have decimal results. It is compulsory as it allows two different type of number data type such as float and integer to be summed without losing the precision of the float.
- Against: While it is compulsory to have mixed-mode
expressions, it is more error prone when expressions made are more likely to
have non-decimal results. A mixed mode might produce a decimal result even
though the result wanted is a non-decimal.
3. Do you think the elimination of overloaded operators in your
favourite language would be beneficial? , why or why not?
= No, it would not be beneficial. Overloading operator would
be a helpful feature in developing a complex program with complex arithmetic
operation as well. It allows developers to create a class whose function can
replace countless lines of codes with an operator. This clearly will help a
readability and writability of a program. Eliminating overloaded operators
would null this advantage.
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?
= No. Because it will affect the readability and writability,
and maybe it can make the answer ambiguous.
5. Should C’s assigning operations (for example, +=) be
included in other languages (that do not already have them)? Why or why not?
= No. assigning operations of C should not be included in
other languages. Because the assigning operations would be the different part
of the code if it is implemented on other code that might cause confusion for
the programmer.
No comments:
Post a Comment