Deck 4: Compilation and Programming Languages
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/22
العب
ملء الشاشة (f)
Deck 4: Compilation and Programming Languages
1
Which of the following grammar rules violate the requirements of an operator grammar ?
P, Q, R are nonterminals, and r, s, t are terminals.
1) P ? Q R
2) P ? Q s R
3) P ? ?
4) P ? Q t R r
A)1 only
B)1 and 3 only
C)2 and 3 only
D)3 and 4 only
P, Q, R are nonterminals, and r, s, t are terminals.
1) P ? Q R
2) P ? Q s R
3) P ? ?
4) P ? Q t R r
A)1 only
B)1 and 3 only
C)2 and 3 only
D)3 and 4 only
1 and 3 only
2
Consider the grammar with the following translation rules and E as the start symbol.
E ? E1 # T { E.value = E1.value * T.value } |
T{ E.value = T.value }T ? T1 &
F { T.value = T1.value + F.value }
| F{ T.value = F.value }F ? num { F.value = num.value }
Compute E.value for the root of the parse tree for the expression: 2 # 3 & 5 # 6 & 4.
A)200
B)180
C)160
D)40
E ? E1 # T { E.value = E1.value * T.value } |
T{ E.value = T.value }T ? T1 &
F { T.value = T1.value + F.value }
| F{ T.value = F.value }F ? num { F.value = num.value }
Compute E.value for the root of the parse tree for the expression: 2 # 3 & 5 # 6 & 4.
A)200
B)180
C)160
D)40
160
3
Assume that the SLR parser for a grammar G has n1 states and the LALR parser for G has n2 states. The relationship between n1 and n2 is:
A) n1 is necessarily less than n2
B) n1 is necessarily equal to n2
C) n1 is necessarily greater than n2
D)none of these
A) n1 is necessarily less than n2
B) n1 is necessarily equal to n2
C) n1 is necessarily greater than n2
D)none of these
n1 is necessarily equal to n2
4
Consider the grammar shown below S ? i E t S S' | a S' ? e S | ? E ? b In the predictive parse table. M, of this grammar, the entries M[S', e] and M[S', $] respectively are
A){S' ? e S} and {S' ? e}
B){S' ? e S} and {}
C){S' ? ?} and {S' ? ?}
D){S' ? e S, S'? ?} and {S' ? ?}
A){S' ? e S} and {S' ? e}
B){S' ? e S} and {}
C){S' ? ?} and {S' ? ?}
D){S' ? e S, S'? ?} and {S' ? ?}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 22 في هذه المجموعة.
فتح الحزمة
k this deck
5
Consider the translation scheme shown below
S ? T R
R ? + T {print ('+');} R | ?
T ? num {print (num.val);}
Here num is a token that represents an integer and num.val represents thecorresponding integer value. For an input string '9 + 5 + 2', this translation scheme willprint
A)9 + 5 + 2
B)9 5 + 2 +
C)9 5 2 + +
D)+ + 9 5 2
S ? T R
R ? + T {print ('+');} R | ?
T ? num {print (num.val);}
Here num is a token that represents an integer and num.val represents thecorresponding integer value. For an input string '9 + 5 + 2', this translation scheme willprint
A)9 + 5 + 2
B)9 5 + 2 +
C)9 5 2 + +
D)+ + 9 5 2
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 22 في هذه المجموعة.
فتح الحزمة
k this deck
6
Which of the following is essential for converting an infix expression to the postfix from efficiently?
A)An operator stack
B)An operand stack
C)An operand stack and an operator stack
D)A parse tree
A)An operator stack
B)An operand stack
C)An operand stack and an operator stack
D)A parse tree
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 22 في هذه المجموعة.
فتح الحزمة
k this deck
7
The grammar whose productions are
? if id then
? if id then else
? id := id
Is ambiguous because
A- the sentence if a then if b then c:= d has two parse trees
B- the left most and right most derivations of the sentence if a then if b then c:= d give rise to different parse trees
C- the sentence if a then if b then c:= d else c:= f has more than two parse trees
D- the sentence if a then if b then c:= d else c:= f has two parse trees
A)a
B)b
C)c
D)d
Is ambiguous because
A- the sentence if a then if b then c:= d has two parse trees
B- the left most and right most derivations of the sentence if a then if b then c:= d give rise to different parse trees
C- the sentence if a then if b then c:= d else c:= f has more than two parse trees
D- the sentence if a then if b then c:= d else c:= f has two parse trees
A)a
B)b
C)c
D)d
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 22 في هذه المجموعة.
فتح الحزمة
k this deck
8
Consider the following grammars
(S1) :
A --> aBCD
B --> bc|c
C --> d|?
D -> b(S2) :
A --> aBCD
B --> bc|?
C --> d|c
D -> b
( S3) :
A --> aBCD
B --> bc|?
C --> d|?
D -> b
( S4) :
A --> aBCD
B --> bc|c
C --> d|c
D -> b
Which of the following grammar has same follow set for variable B?
A)Only (S1), (S2) and ( S33), ( S4)
B)Only (S1), ( S33) and (S2), ( S4)
C)Only (S2), ( S33) and (S1), ( S4)
D)None of the above
(S1) :
A --> aBCD
B --> bc|c
C --> d|?
D -> b(S2) :
A --> aBCD
B --> bc|?
C --> d|c
D -> b
( S3) :
A --> aBCD
B --> bc|?
C --> d|?
D -> b
( S4) :
A --> aBCD
B --> bc|c
C --> d|c
D -> b
Which of the following grammar has same follow set for variable B?
A)Only (S1), (S2) and ( S33), ( S4)
B)Only (S1), ( S33) and (S2), ( S4)
C)Only (S2), ( S33) and (S1), ( S4)
D)None of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 22 في هذه المجموعة.
فتح الحزمة
k this deck
9
Which is True about SR and RR-conflict:
A)If there is no SR-conflict in CLR(1) then definitely there will be no SR-conflict in LALR(1).
B)RR-conflict might occur if lookahead for final items(reduce-moves) is same.
C)Known that CLR(1) has no RR-conflict, still RR-conflict might occur in LALR(1).
D)All of the above.
A)If there is no SR-conflict in CLR(1) then definitely there will be no SR-conflict in LALR(1).
B)RR-conflict might occur if lookahead for final items(reduce-moves) is same.
C)Known that CLR(1) has no RR-conflict, still RR-conflict might occur in LALR(1).
D)All of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 22 في هذه المجموعة.
فتح الحزمة
k this deck
10
Which of the following statement(s) regarding a linker software is/are true ? I A function of a linker is to combine several object modules into a single load module. II A function of a linker is to replace absolute references in an object module by symbolic references to locations in other modules.
A)Only I
B)Only II
C)Both I and II
D)Neither I nor II
A)Only I
B)Only II
C)Both I and II
D)Neither I nor II
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 22 في هذه المجموعة.
فتح الحزمة
k this deck
11
Shift-Reduce parsers perform the following:
A)Shift step that advances in the input stream by K(K > 1) symbols and Reduce step that applies a completed grammar rule to some recent parse trees, joining them together as one tree with a new root symbol.
B)Shift step that advances in the input stream by one symbol and Reduce step that applies a completed grammar rule to some recent parse trees, joining them together as one tree with a new root symbol.
C)Shift step that advances in the input stream by K(K = 2) symbols and Reduce step that applies a completed grammar rule to form a single tree
D)Shift step that does not advance in the input stream and Reduce step that applies a completed grammar rule to form a single tree.
A)Shift step that advances in the input stream by K(K > 1) symbols and Reduce step that applies a completed grammar rule to some recent parse trees, joining them together as one tree with a new root symbol.
B)Shift step that advances in the input stream by one symbol and Reduce step that applies a completed grammar rule to some recent parse trees, joining them together as one tree with a new root symbol.
C)Shift step that advances in the input stream by K(K = 2) symbols and Reduce step that applies a completed grammar rule to form a single tree
D)Shift step that does not advance in the input stream and Reduce step that applies a completed grammar rule to form a single tree.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 22 في هذه المجموعة.
فتح الحزمة
k this deck
12
Incremental-Compiler is a compiler
A)which is written in a language that is different from the source language
B)compiles the whole source code to generate object code afresh
C)compiles only those portion of source code that have been modified.
D)that runs on one machine but produces object code for another machine
A)which is written in a language that is different from the source language
B)compiles the whole source code to generate object code afresh
C)compiles only those portion of source code that have been modified.
D)that runs on one machine but produces object code for another machine
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 22 في هذه المجموعة.
فتح الحزمة
k this deck
13
Which one of the following is FALSE?
A)A basic block is a sequence of instructions where control enters the sequence at the beginning and exits at the end.
B)Available expression analysis can be used for common subexpression elimination.
C)Live variable analysis can be used for dead code elimination.
D)x = 4 ? 5 => x = 20 is an example of common subexpression elimination.
A)A basic block is a sequence of instructions where control enters the sequence at the beginning and exits at the end.
B)Available expression analysis can be used for common subexpression elimination.
C)Live variable analysis can be used for dead code elimination.
D)x = 4 ? 5 => x = 20 is an example of common subexpression elimination.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 22 في هذه المجموعة.
فتح الحزمة
k this deck
14
Consider the following C code segment.
For (i = 0, i{
For (j=0; j{
If (i%2)
{
X += (4*j + 5*i);
Y += (7 + 4*j);
}
}
}
Which one of the following is false?
A)The code contains loop invariant computation
B)There is scope of common sub-expression elimination in this code
C)There is scope of strength reduction in this code
D)There is scope of dead code elimination in this code
For (i = 0, i
For (j=0; j
If (i%2)
{
X += (4*j + 5*i);
Y += (7 + 4*j);
}
}
}
Which one of the following is false?
A)The code contains loop invariant computation
B)There is scope of common sub-expression elimination in this code
C)There is scope of strength reduction in this code
D)There is scope of dead code elimination in this code
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 22 في هذه المجموعة.
فتح الحزمة
k this deck
15
Consider the intermediate code given below:
1) i = 1
2) j = 1
3) T1 = 5 * i
4) T2 = T1 + j5
) T3 = 4 * T2
6) t4 = T3
7) a[ t4] = -1
8) j = j + 1
9) if j <= 5 goto(3)
10) i = i + 1
11) if i < 5 goto(2)
The number of nodes and edges in the control-flow-graph constructed for the abovecode, respectively, are
A)5 and 7
B)6 and 7
C)5 and 5
D)7 and 8
1) i = 1
2) j = 1
3) T1 = 5 * i
4) T2 = T1 + j5
) T3 = 4 * T2
6) t4 = T3
7) a[ t4] = -1
8) j = j + 1
9) if j <= 5 goto(3)
10) i = i + 1
11) if i < 5 goto(2)
The number of nodes and edges in the control-flow-graph constructed for the abovecode, respectively, are
A)5 and 7
B)6 and 7
C)5 and 5
D)7 and 8
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 22 في هذه المجموعة.
فتح الحزمة
k this deck
16
Consider the following code segment.
X = u - t;
Y = x * v;
X = y + w;
Y = t - z;
Y = x * y;
The minimum number of total variables required to convert the above code segment tostatic single assignment form is Note : This question was asked as Numerical AnswerType.
A)6
B)8
C)9
D)10
X = u - t;
Y = x * v;
X = y + w;
Y = t - z;
Y = x * y;
The minimum number of total variables required to convert the above code segment tostatic single assignment form is Note : This question was asked as Numerical AnswerType.
A)6
B)8
C)9
D)10
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 22 في هذه المجموعة.
فتح الحزمة
k this deck
17
A linker reads four modules whose lengths are 200, 800, 600 and 500 words respectively. If they are loaded in that order, what are the relocation constants?
A)0, 200, 500, 600
B)0, 200, 1000, 1600
C)200, 500, 600, 800
D)200, 700, 1300, 2100
A)0, 200, 500, 600
B)0, 200, 1000, 1600
C)200, 500, 600, 800
D)200, 700, 1300, 2100
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 22 في هذه المجموعة.
فتح الحزمة
k this deck
18
A language L allows declaration of arrays whose sizes are not known during compilation. It is required to make efficient use of memory. Which of the following is true?
A)A compiler using static memory allocation can be written for L
B)A compiler cannot be written for L, an interpreter must be used
C)A compiler using dynamic memory allocation can be written for L
D)None of the above
A)A compiler using static memory allocation can be written for L
B)A compiler cannot be written for L, an interpreter must be used
C)A compiler using dynamic memory allocation can be written for L
D)None of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 22 في هذه المجموعة.
فتح الحزمة
k this deck
19
The expression (a*b)* c op........ where 'op' is one of '+', '*' and '?' (exponentiation) can be evaluated on a CPU with a single register without storing the value of (a * b) if
A)'op' is '+' or '*'
B)'op' is '?' or '*'
C)'op' is '?' or '+'
D)not possible to evaluate without storing
A)'op' is '+' or '*'
B)'op' is '?' or '*'
C)'op' is '?' or '+'
D)not possible to evaluate without storing
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 22 في هذه المجموعة.
فتح الحزمة
k this deck
20
Which of the following macros can put a micro assembler into an infinite loop?
(i)
)MACRO M1 X
)IF EQ, X ;if X=0 then
M1 X + 1
)ENDC
)IF NE X ;IF X?0 then
)WORD X ;address (X) is stored
Here
)ENDC
)ENDM
(ii)
)MACRO M2X
)IF EQ XM2 X.
ENDC
)IF NE, X
)WORD X+1
)ENDC
)ENDM
A)(ii) only
B)(i) only
C)Both (i) and (ii)
D)None of the above
(i)
)MACRO M1 X
)IF EQ, X ;if X=0 then
M1 X + 1
)ENDC
)IF NE X ;IF X?0 then
)WORD X ;address (X) is stored
Here
)ENDC
)ENDM
(ii)
)MACRO M2X
)IF EQ XM2 X.
ENDC
)IF NE, X
)WORD X+1
)ENDC
)ENDM
A)(ii) only
B)(i) only
C)Both (i) and (ii)
D)None of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 22 في هذه المجموعة.
فتح الحزمة
k this deck
21
Consider the following expressionu
*v+a-b*c
Which one of the following corresponds to a static single assignment from the above expressions
A)x1 = a - b y1 = p * c x2 = u * v y2 = p + q
B)x 1 = a - b y1 = x2 * c x3 = u * v y2 = x4 + y3
C)x1 = a - b y2 = x1 * c x2 = u * v y3 = x2 + y2
D)p = a - b q = p * c p = u * v q = p + q
*v+a-b*c
Which one of the following corresponds to a static single assignment from the above expressions
A)x1 = a - b y1 = p * c x2 = u * v y2 = p + q
B)x 1 = a - b y1 = x2 * c x3 = u * v y2 = x4 + y3
C)x1 = a - b y2 = x1 * c x2 = u * v y3 = x2 + y2
D)p = a - b q = p * c p = u * v q = p + q
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 22 في هذه المجموعة.
فتح الحزمة
k this deck
22
In multi-programmed systems, it is advantageous if some programs such as editors and compilers can be shared by several users. Which of the following must be true of multi-programmed systems in order that a single copy of a program can be shared by several users?
I. The program is a macro
II. The program is recursive
III.The program is reentrant
A)I only
B)II only
C)Ill only
D)I, II and III
I. The program is a macro
II. The program is recursive
III.The program is reentrant
A)I only
B)II only
C)Ill only
D)I, II and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 22 في هذه المجموعة.
فتح الحزمة
k this deck