GATE 2003
107 questions
MCQ 1071-mark 107
Questions 86–90 of 107
Which of the following statements is FALSE?
Answer: (C)
In a statically typed language the type of each variable is fixed at compile time and checked then. So (A) is true.
Because the declared type never changes, every value the variable holds during execution is a value of that one type. This still holds with unions or subtyping: a union variable has the single union type, and a variable of a base type that holds a derived-type object still has the single declared type, since that object is also a value of the base type. So (D) is true.
In an untyped language (such as assembly or machine code) values are just bit patterns and carry no type. So (B) is true.
In a dynamically typed language, a variable is not tied to one type, but it is not typeless. The value it holds has a type, and that type is found and checked at run time. For example, a variable holding 5 has an integer value now and may hold a string later. So "variables have no types" is false; it is the variable's type that can change, not that types are missing.
Answer: (C)
Because the declared type never changes, every value the variable holds during execution is a value of that one type. This still holds with unions or subtyping: a union variable has the single union type, and a variable of a base type that holds a derived-type object still has the single declared type, since that object is also a value of the base type. So (D) is true.
In an untyped language (such as assembly or machine code) values are just bit patterns and carry no type. So (B) is true.
In a dynamically typed language, a variable is not tied to one type, but it is not typeless. The value it holds has a type, and that type is found and checked at run time. For example, a variable holding 5 has an integer value now and may hold a string later. So "variables have no types" is false; it is the variable's type that can change, not that types are missing.
Answer: (C)
In a bottom-up evaluation of a syntax directed definition, inherited attributes can
Answer: (B)
A synthesized attribute is computed from the children, so a bottom-up (LR) parser can compute it when it reduces a production. An inherited attribute is computed from the parent or the siblings, so its value is needed before the subtree below is reduced.
An SDD is L-attributed if every inherited attribute of a symbol on the right side depends only on the inherited attributes of the head and on the attributes of the symbols to its left. So, in a left-to-right pass, every value needed is already known when the parser reaches that symbol. A bottom-up parser can then evaluate these attributes: each embedded action is replaced by a marker non-terminal (an empty production) that copies the needed values from the parser stack.
(A) is wrong: an inherited attribute that depends on a symbol to its right is not available in a left-to-right bottom-up pass. (C) is wrong: having synthesized attributes does not help evaluate inherited ones. (D) is wrong: L-attributed definitions show they can be evaluated.
Answer: (B)
An SDD is L-attributed if every inherited attribute of a symbol on the right side depends only on the inherited attributes of the head and on the attributes of the symbols to its left. So, in a left-to-right pass, every value needed is already known when the parser reaches that symbol. A bottom-up parser can then evaluate these attributes: each embedded action is replaced by a marker non-terminal (an empty production) that copies the needed values from the parser stack.
(A) is wrong: an inherited attribute that depends on a symbol to its right is not available in a left-to-right bottom-up pass. (C) is wrong: having synthesized attributes does not help evaluate inherited ones. (D) is wrong: L-attributed definitions show they can be evaluated.
Answer: (B)
Consider the syntax directed definition shown below
Here, gen is a function that generates the output code, and newtemp is a function that returns the name of a new temporary variable on every call. Assume that ti's are the temporary variable names generated by newtemp. For the statement 'X:= Y + Z', the 3-address code sequence generated by this definition is
Here, gen is a function that generates the output code, and newtemp is a function that returns the name of a new temporary variable on every call. Assume that ti's are the temporary variable names generated by newtemp. For the statement 'X:= Y + Z', the 3-address code sequence generated by this definition is
Answer: (B)
For the parse tree is below.
- only sets to the name of the identifier. It calls no gen, so it makes no code and no temporary. So and .
- gets a new temporary , generates , and sets .
- generates .
The code is then . Options C and D copy Y and Z into temporaries, which no rule does. Option A has no temporary, but the rule for always makes one.
Answer: (B)
- only sets to the name of the identifier. It calls no gen, so it makes no code and no temporary. So and .
- gets a new temporary , generates , and sets .
- generates .
The code is then . Options C and D copy Y and Z into temporaries, which no rule does. Option A has no temporary, but the rule for always makes one.
Answer: (B)
Consider the translation scheme shown below
S TR
R + T {print ('+');}R |
T num {print (num.val);}
Here num is a token that represents an integer and num. val represents the corresponding integer value. For an input string '9 + 5+ 2', this translation scheme will print
S TR
R + T {print ('+');}R |
T num {print (num.val);}
Here num is a token that represents an integer and num. val represents the corresponding integer value. For an input string '9 + 5+ 2', this translation scheme will print
Answer: (B)
The actions run in a left to right, depth first walk of the parse tree. A print action sits after the symbols before it, so it runs once they are done.
For :
1. : prints 9.
2. : after reading +, T prints 5. Only then does the action print +.
3. The new R reads the second +, T prints 2, and then the action prints +.
4. prints nothing.
The output is , that is 95+2+.
Answer: (B)
For :
1. : prints 9.
2. : after reading +, T prints 5. Only then does the action print +.
3. The new R reads the second +, T prints 2, and then the action prints +.
4. prints nothing.
The output is , that is 95+2+.
Answer: (B)
Which of the following is NOT an advantage of using shared, dynamically linked libraries as opposed to using statically linked libraries?
Answer: (C)
Dynamic linking makes program startup slower, not faster. Before the program runs, the loader must find and map the shared libraries and set up the global offset table (GOT) so that library calls can be resolved. A statically linked program has all of this done already, at link time.
The other three are real advantages of shared libraries:
- (A) The library code is not copied into each executable, so executables are smaller.
- (B) One copy of the library in memory is shared by many processes, so less memory is used and the overall page fault rate in the system is lower.
- (D) A newer version of a library is picked up when the program is loaded, so existing programs need not be re-linked.
Answer: (C)
The other three are real advantages of shared libraries:
- (A) The library code is not copied into each executable, so executables are smaller.
- (B) One copy of the library in memory is shared by many processes, so less memory is used and the overall page fault rate in the system is lower.
- (D) A newer version of a library is picked up when the program is loaded, so existing programs need not be re-linked.
Answer: (C)