Sunday, October 26, 2014

Assignment 5 Programming Language Concepts

Name : Alvin Theodora
NIM   : 1801428434

Here is the fifth assignment of Programming Language Concepts course. The question is taken from "Concepts of Programming Language, 10th edition" from Robert W. Sebesta in chapter 5:

Review Questions

1. What are the design issues for names?
= Case sensitivity and the relationship of names to special words, which are either reserved words or keywords, are the design issues for names.

2. What is the potential danger of case-sensitive names?
= To some people, it is a detriment to readability, because names that look similar in fact denote different entities.

3. In what way are reserved words better than keywords?
= From language design aspects, reserved words are better than keywords because the ability to redefine keywords can be confusing. For example, in Fortran could have the following statements:

Integer Real
Real Integer

These statements declare the program variable Real to be Integer type and the variable Integer to be Real type.

4. What is an alias?
= Aliases are two or more variables bound to the same storage address.

5. Which category of C++ reference variables is always aliases?
= Union type. Union is a type whose variables may store different type values at different times during program execution.

Problem Set

1. Which of the following identifier forms is most readable? Support your decision.
SumOfSales
sum_of_sales
SUMOFSALES
= sum_of_sales, because there are underscores which separate its word, and make it easier to read.

2. Some programming languages are typeless. What are the obvious advantages and disadvantages of having no types in a language?
= Advantage:
         1) It allows programmers to write sloppy programs quickly.

  Disadvantage:
         1) You are not in control of the data and variables, the compiler or interpreter is.
         2) If you mis-assign variables, there is no way for the compiler to catch any of your mistakes. It just “does what you said”,even if it is wrong.
         3) Supporting programs in a typeless language is much more difficult that in a strongly types one. It is often very difficult to determine what the original programmer wanted to do.

3. Write a simple assignment statement with one arithmetic operator in some language you know. For each component of the statement, list the various bindings that are required to determine the semantics when the statement is executed. For each binding, indicate the binding time used for the language.

= Java

count = count + 5;
Some of the bindings and their binding times for the parts of this assignment
statement are as follows:
• The type of count is bound at compile time.
• The set of possible values of count is bound at compiler design time.
• The meaning of the operator symbol + is bound at compile time, when the
types of its operands have been determined.
• The internal representation of the literal 5 is bound at compiler design
time.
• The value of count is bound at execution time with this statement.

4. Dynamic type binding is closely related to implicit heap-dynamic variables. Explain this relationship.
= Both are related to the assignment and the statement.

5. Describe a situation when a history-sensitive variable in a subprogram is useful.
= History sensitive variables may be useful in data manipulation subprograms, where some operation is performed on a variable, and the function exits, then the function is called again. This way, the function doesn’t have to take the variable as a parameter, but only to return it.




No comments:

Post a Comment