Monday, April 8, 2013

Answers of Concepts of Programming Languages Chapter 7


1.
2. operator requiring 3 operands
3. operator preceding the operands
4. the exponentiation
5. an expression needed to be parenthesized to show the desired order
6. APL uses right to left associativity rule
7.
8. functional side effect is the unwanted output that occurs when the function changes either one of its parameters or a global variable
9.
10. conditional expression is the expression used to determine which actions should be taken based on certain condition

Problem set
1
2
3. I think it will be beneficial, because it can eliminate the confusion of those operators function, thus increases the readibility
4. I don't think it will be a good idea, because when we eliminate the precedence rules, it means we need extra effort to determine the precedence by adding more syntax or operators. It will just waste of time and decrease efficiency.
5. Yes, because it really will simplify the length of the statement and make the user looks like more professional.
6. Yes, because it will be really helpful, especially in looping, so we don't need to write longer statements, instead, just by using the ++ sign to refer to increment by 1.
7.
8. When there is 2 integers which has really big number. When we want to add both of them, it will cause an overflow exception, because the result will pass over the range supported.
9
10
11
12
13. a. sum1 = 46, sum2 = 46
    b. sum1 = 44, sum2 = 44

Answers of Concepts of Programming Languages Chapter 6


1. A descriptor is the collection of the attribute of a variable
2.
3. the design issues are : whether strings should be simply a special kind of character array or a primitive type and whether string should have static or dynamic length
4. The three string length options are : static length string, dynamic length string, and limited dynamic length string
5.
6.
7.
8. design issues for arrays are :
   - 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 array allowed, or both?
   - can arrays be initialized when they have their storage allocated?
   - what kinds of slices are allowed, if any?
9.
10. a reference to a nonexistent element yields undef, but no error will be reported
11. when we assign an index which is more than the initialized one, it will automatically add the gap with undefined datas and the statement will run
12. Perl, Ruby, Lua
13
14. Ada provides the => operator that makes users available to initialize specified value to specifid index.
15. Parenthized lists of constants
16. Ada provides catenation for the single dimensioned array
17. row major order : the elements of the array that have as their first subscirpt the lower bound value of that subscript are stored first
    column major order : the elements of the array that have as their last subscirpt the lower bound value of that subscript are stored first
18.
19
20
21. level numbers are used to indicate by their relative values the hierarchical structure of the record
22.
23. tuple is similar to record, but in tuple, the elements are not named
24. no

Problem set
1.
2. negative integer is stored in sign-magnitude notation
3. precision is the accuracy of the fractional part of a value
   range is a combination of the range of fractions and range of exponents
4.
5
6. in Java, boolean type can't be represented by any integer, while in C, it can.
7. reference type variable in C++ is a constant pointer that is always implicitly dereferenced, while pointer requires explicit dereference
8. Java reference type variable is not a constant, thus it is safer.
9. struct is used to store more than one data types into a group, while union is used to group multiple variables to share the memory
10.
11
12
13. reference type is used when we want to pass it to another function, while value is used when it is required by the function itself.
    Example : void print(int *jumlah) {}
              void main() {int value=0; }

Answers of Concepts of Programming Languages Chapter 5


1. Whether the names are case sensitive and whether the special words of languages are reserved words or keywords
2. it can harm the readibility of the program
3. Because the ability to redefine keywords can be confusing
4. Variables accessing the same memory location
5. In C++ reference, aliases are used in the union types
6. l-value is the address of a variable, while r-value is the value of the variable

Problem set
1. all valid except _Student and 123Student
2. l-value is the address of a variable.
   Example of the error ->  "   = 1+2; "
3.
4. Type declaration of a variable is necessary because it determines the range of values it can store and the set of operations it can use
   int type in Java ranges a value range of -2147483648 to 2147483647

Answers of Concepts of Programming Languages Chapter 4


Review Questions
1.
2. -Simplicity : techniques for lexical analysis are less complex than syntax analysis
   -Efficiency : lexical analysis requires a significant portion of total compilation time, so it is not good enough to optimize the syntax analyzer
   -Portability : lexical analysis is platform dependent while syntax analyzer is platform independent
3. Lexeme : logical groupings consist of characters collected by lexical analyzer
   tokens : internal codes for categories of lexemes
4.
5. -Write a formal description of the token patterns of the language using a descriptive language related to regular expressions
   -Design a state transition diagram that describes the token patterns of the language and write a program that implements the program
   -Design a state transition diagram that describes the token patterns of the language and hand-construct a table-driven implementation of the state diagram
6. State transition diagram is a directed graph, whose nodes are labeled with state names.
7.
8. -checking the input program to determine whether it is syntactically correct
   -producing a complete parse tree
9. top-down : building tree from the root downward to the leaves
   bottom-up : builidng tree from the leaves to the root
10. it is too complicated and inefficient
11. it is too complicated and inefficient
12. it is in order to increase the speed of parsing

Problem Set
1.a. pass
  b. not pass
  c. pass

2.a. pass
  b. pass
  c. not pass

3. void expr()
   {
      printf("Enter expr\n");
 
 
     term();

     while(nextToken== ADD_OP || nextToken==MULT_OP)
     {
        lex();
        term();
     }

     printf("Exit expr\n");
   }