Senin, 08 April 2013

Concepts of Programming Languages - Chapter 7

Review Questions
2. Operator that has three operands.
3. Operator that precede its operands.
4. Exponentiation operator.
11. Multiple use of an operator.
18. Short circuit evaluation is one in which the result is determined without evaluating all of the operands and/or operators.
25. Ada doesn't allowed mixed mode assignment.
26. Mixed mode assignment are allowed in Java only if the required coercion is widening.

Problem Set
5. No, it shouldn't be included in other language because in C there are some characteristics assigning operations that available just in C language, in case that the assigning operator in C make it unique and different from the other language.
6. No, it shouldn't be included in other language because in C there are some characteristics single operand assignment forms that available just in C language, in case that the single operand assignment forms in C make it unique and different from the other language.
9.
a. ( ( (a*b)1 -1 )2 +c)3
b. ( ( ( a* (b-1)1 )2 /c)3 mod d)4
c. ( ( ( ( ( (a-b)1 /c)2 (d*e)3 /a)4 -3)5 &)6
d. (- ( ( (a or c)1 (d and e) )2 = )3 )4
e. ( ( ( (a>b)1 xor c )2 or (d<=17) )3
f. (- (a+b)1 )2
15. Because C is a structured programming language that makes C must read every line on that code, so if there is a simple error it will be detected immediately, in that case it makes C difficult to eliminate its functional side effect.
21. Because Java is using associativity rules of the language that makes Java read an expression from left to right.

Concepts of Programming Languages - Chapter 6

Review Questions
1. Collection of the attributes of a variable.
3.
Should strings be simply a special kind of character array or a primitive type ?
Should strings have static or dynamic length ?
5. Ordinal is one in which the range of possible values can be easily associated with the set of positive integers. Enumeration is one in which all of the possible values, which are named constants, are provided, or enumerated, in the definition. Subrange is a contiguous subsequence of an ordinal type.
8.
What types are legal for subscripts ?
Are subscripting expressions in element references range checked ?
When are subscript ranges bound ?
When does array allocation take place ?
Are ragged or rectangular multidimensioned arrays allowed, or both ?
Can arrays be initialized when they have their storage allocated ?
What kinds of slices are allowed, if any ?
11. The subscript values need not be contiguous.
12. Ruby and Lua.
17. In row major order the elements of the array that have as their first subscript the lower bound value of that subscript are stored first, followed by the elements of the second value of the first subscript, and so forth. In column major order, the elements of an array that have as their last subscript the lower bound value of that subscript are stored first, followed by the elements of the second value of the last subscript, and so forth.
31. Union is a type whose variables may store different type values at different times during program execution. Free union is the unions in C and C++ which are allowed complete freedom from type checking in their use.  Discriminated union is a union with a discriminant.
33. Yes, they are
35.
What are the scope and lifetime of a pointer variable ?
What is the lifetime of a heap-dynamic variable (the value a pointer references) ?
Are pointers restricted as to the type of value to which they can point ?
Are pointers used for dynamic storage management, indirect addressing, or both ?
Should the language support pointer types, reference types, or both ?
36. Dangling pointers and Lost Heap-Dynamic variables
38. A C++ reference type variable is a constant pointer that is always implicitly dereferenced, used primarily for the formal parameters in function definitions.
44. Type error is the application of an operator to an operand of an inapropriate type.
50. Name type equivalence means that two variables have equivalent types if they are defined either in the same declaration or in declarations that use the same type name.

Problem Set
2. A negative integer could be stored in sign-magnitude notation, in which the sign bit is set to indicate negative and the remainder of the bit string represents the absolute value of the number. Sign-magnitude notation, however, doesn't lend itself to computer arithmetic. Most computers now use a notation called twos complement to store negative integers, which is convenient for addition and subtraction. In twos-complement notation, the representation of a negative integer is formed by taking the logical complement of the positive version of the number and adding one. Ones-complement notation is still used by some computers. In ones-complement notation, the negative of an integer is stored as the logical complement of its absolute value. Ones-complement notation has the disadvantage that it has two representations of zero.
7. C++ pointer used in the same way as address, can point at any variables, C++ reference type variable is a pointer that is implicity dereferenced and constant.

8. in C++ is a constant, must be initialized with the address of variable, after initialization a variable that pass by reference can't be set to the other variable, in Java variable can be assigned to reference, and it isn't constant.

21. Dynamic type better than static type to detect error in compile time than in run time.
22. Take deallocation of heap dynamic variable out, because if a program can''t deallocate heap dynamic variable explicitly, it won't be any dangling pointer.

Minggu, 07 April 2013

Concepts of Programming Languages - Chapter 5

Review Question
1. Are name case sensitive ? Are the special words of the language reserved words or keywords ?
4. Two or more variables name that can be used to access the same memory location.
5.  Two pointers variables are aliases when they point to the same memory location.
7. Binding is an association between an attribute and an entity. Binding time is the time which binding takes place.
9. Static binding if it first occurs before run time begins and remain s unchanged throughout program execution Dynamic binding if the binding first occurs during run time or can change in the course of program execution.
18. Such variables are typically stack dynamic, so their storage is allocated when the section is entered and deallocated when the section is exited.

Problem Set
1. Student , Student123 because in C we can't use _ ,etc. and begin it with number for the variables name.
4. Because a variable must have data type before it assigned. Range int type in Java -2,147,483,648 to +2,147,483,648.
10.
1 -> a,b,c (definition 1)
2 -> a (definition 1) b (definition 2) c,d,e (definition 3)
3 -> a (definition 1) b,c d (definition 2)
4 -> a,b,c (definition 1)