Monthly Archives: April 2013

concept of programming languages: chapter 6

Standard

review question:

1. What is descriptor?

Descriptor is a collection of the attributes of a variable that space in a memory what stores the attribute

2. What is the advantages and disadvantages of decimal data types?

Advantages: can store the decimal value of a number.

Disadvantages: range of value are restricted because no exponent are allowed.

4. Describe the three string length option

– Static length string
The length of the string is set when the string is created and it is always static.
-Limited dynamic length string
This kind allows string to have varying length up to a declared and fixed maximum set by the variable’s definition.
– Dynamic length string
This option allows string to have varying length with no maximum limit such as JavaScript.
5. Define ordinal, enumeration, and sub range type

Ordinal: one in which the range of possible value can be easily associated with the set of positive integers.

Enumeration: one in which all of the positive values, which are name constant, are provided or enumerated in the definition.

Sub range type: a contiguous subsequence of an ordinal type.

6. What are the advantages of user-defined enumeration types?

Readability is enhanced very directly and named values are easily recognized, whereas coded values are not. In reliability this enumeration types provide two other advantages 1) No arithmetic operations are legal on enumeration types 2) No enumeration variable can be assigned a value outside its defined range.

12. What languages support negative subscripts?

Ruby and Lua support negative subscripts.

17. Define row major order and column major order.

Row major order: the elements of the array that have as their first subscript the lower bound value of the subscript are store first, followed by the elements of the second value of  the first subscript, and so forth.

Column major order: the elements of the array that have as their last subscript the lower bound value bound value of the subscript are store first, , followed by the elements of the second value of  the first subscript, and so forth.

22. Define fully qualified and elliptical references to fields in records.

Fully qualified reference makes all intermediate record names, from the largest enclosing record to the specific field, are named in the reference. While in elliptical references, the field is named, but any or all of the enclosing record names can be omitted, as long as the resulting reference is unambiguous in the referencing environment.

31. Define union, free union and discriminated union.

A union is a type whose variables may store different type values at different times during program execution. Free unions are union constructs in which there is no language support for type checking. Discriminated union is union with discriminant where as discriminant is an indicator required in each union construct.

43. What is a compatible type?

A compatible type is one that either is legal for the operator or is allowed under language rules to be implicitly converted by compiler-generated code to a legal type.

44. Define type error.

Type error is an application of an operator to an operand of an inappropriate type.

45. Define strongly typed.

Strongly typed is a method when the type error are always detected.

 

problem set:

1. What are the arguments for and against four signed integer sized in Java?

Bytes =1 byte, short = 2 bytes, integer = 4 bytes, long  = 8 bytes. As a result, depending on the domain of the variable required, data types are used.

2. How are negative integers stored in memory?

negative integer stored in memory by turning the value into binary and makes the compliment of its binary.
For example : integer 1 in binary is 0001 to get -1 the computer uses the compliment so it will be 1110. The 1110 binary might be 14 or -1 depends on the data type.
5. What disadvantages are there in implicit dereferencing of pointers, but only in certain contexts? For example, consider the implicit dereference of a pointer to a record in Ada when it is used to deference a record field.
When implicit dereferencing of pointers occurs only in certain contexts, it makes the language slightly less orthogonal. The context of the reference to the pointer determines its meaning. This detracts from the readability of the language and makes it slightly more difficult to learn.
8. What are the differences between the reference type variable of C++ and those of Java?
The differences between the reference type variable of C++ and those of Java are first in Java we can’t actually get to and manipulate the underlying value of a reference in Java but in C we can manipulate it. Second in java references are strictly controlled than in C. Third in Java reference will be implemented as pointers, but that is not required by the specification in the other hand C reference is not implemented as pointer.
19. Any type defined with typedef is type equivalent to its parent type.
How does the use of typedef differ in C and C++?
Typedef in C uses struct to do typedef, with the fortmat typedef struct name_of struct; Typedef in c++ we don’t need to uses the keyword typedef and it has a formattypedef existing_type new_type_name
21. In what way is dynamic type checking is better than static type checking?
It is better to detect errors at the compile time than at the run time, because the earlier correction is usually less costly.

 

concepts of programming languages: chapter 5

Standard

review question:

1. What is the design issue for names?

The design issue for names are (1) Are names care sensitive? (2) Are the special words of the language reserved words or keywords

2. What is the potential danger of case-sensitive names?

Potential danger of case-sensitive names is when user input the name that is not similar to what the program want, the process won’t be executed/ file not found.

4. What is an Alias?

Alias is when more than one variable name can be used to access the same memory location.

6. What is the L-value of a variable? What is the R-value?

L-value is usually used to call the address of a variable. R-value is usually used to call the value of a variable.

7. Define binding and binding time.

A binding is an association between an attribute and an entity, such as between a variable and its type or value, or between an operation and a symbol. Binding time is the time at which a binding takes place.

18. What is a block?

A block is when sections of code have its own local variables and the storage of its variables is allocated when the section is entered and deallocated when the section is exited.

 

problem set:

1. Decide which of the following identifier names is valid in C language.
Support your decision.
_Student
int
Student
123Student
Student123
Answer:
the valid identifier names in C language are _Student, Student and Student123 because the valid identifier names in C should not be integer in beginning, reserved word (int, float, etc.) and it doesn’t contain space.
4. Why is the type declaration of a variable necessary? What is the value range of the int type variable in Java?
Declaration of a variable is necessary because it define the type of the variable that declared which make the variable unambiguous. The range value of int type variable in java is 2.147.483.648 to 2.147.483.647.
5. Describe a situation each where static and dynamic type binding is required?

Static binding: A class with multiple methods that have the same name, but with different parameter lists, requires static binding to call this methods.

Dynamic binding: In case if inheritance, if both base class and the derived class have method of the same name with the same parameter list and return type, dynamic binding would be used to call this method.