Expressions and Assignment Statements

Written on 18.30 by Unknown

We meet yet again through my blog and this time I'm gonna talk about my seventh assignment from Mr. Tri Djoko Wahjono, Ir, M.Sc. It is about "Expressions and Assignment Statements", the seventh chapter from Sebesta's Programming Language Concepts book, so i answered 5 questions from the review questions and 5 questions from the problem sets. So here is my answer for them :

Review Questions:
1.      Define operator precedence and operator associativity.
·         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 form the same precedence level.

2.      What is a ternary operator?
·         Ternary operator is conditional expressions that can be used where any other expression can be used.

3.      What is a prefix operator?
·         Prefix operator is an 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 non-associative operator?
·         Non-associative operator means that the expression is illegal.


Problem set:
1.      When might you want the compiler to ignore type differences in an expression?
·         Let Type is a sub-range of Integer. It may be useful for the difference between Type and Integer to be ignored by the compiler in an expression.

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.

·         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 favorite 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 which 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, it would not be a good idea. Although this custom precedence sounds like increasing flexibility, requiring parentheses to show a custom precedence would impact in readability and writability of a program.

5.      Should C’s assigning operations (for example, +=) be included in other languages (that do not already have them)? Why or why not?
·         Yes, because it’s simpler than the normal <operand> = <operand> + <some values> form, and it can save much time.

If you enjoyed this post Subscribe to our feed

No Comment

Posting Komentar