Deck 3: Compiler Construction and Parsing Algorithms
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/24
العب
ملء الشاشة (f)
Deck 3: Compiler Construction and Parsing Algorithms
1
In a compiler, keywords of a language are recognized during
A)parsing of the program
B)the code generation
C)the lexical analysis of the program
D)dataflow analysis
A)parsing of the program
B)the code generation
C)the lexical analysis of the program
D)dataflow analysis
the lexical analysis of the program
2
The lexical analysis for a modern computer language such as Java needs the power of which one of the following machine models in a necessary and sufficient sense?
A)Finite state automata
B)Deterministic pushdown automata
C)Non-Deterministic pushdown automata
D)Turing Machine
A)Finite state automata
B)Deterministic pushdown automata
C)Non-Deterministic pushdown automata
D)Turing Machine
Finite state automata
3
Consider the following statements:
(I) The output of a lexical analyzer is groups of characters.
(II) Total number of tokens in printf("i=%d, &i=%x", i, &i); are 11.
(III) Symbol table can be implementation by using array and hash table but not tree.
Which of the following statement(s) is/are correct?
A)Only (I)
B)Only (II) and (III)
C)All (I), (II), and (III)
D)None of these
(I) The output of a lexical analyzer is groups of characters.
(II) Total number of tokens in printf("i=%d, &i=%x", i, &i); are 11.
(III) Symbol table can be implementation by using array and hash table but not tree.
Which of the following statement(s) is/are correct?
A)Only (I)
B)Only (II) and (III)
C)All (I), (II), and (III)
D)None of these
None of these
4
Which one of the following statements is FALSE?
A)Context-free grammar can be used to specify both lexical and syntax rules.
B)Type checking is done before parsing.
C)High-level language programs can be translated to different Intermediate Representations.
D)Arguments to a function can be passed using the program stack.
A)Context-free grammar can be used to specify both lexical and syntax rules.
B)Type checking is done before parsing.
C)High-level language programs can be translated to different Intermediate Representations.
D)Arguments to a function can be passed using the program stack.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 24 في هذه المجموعة.
فتح الحزمة
k this deck
5
Consider the following statements related to compiler construction :
I. Lexical Analysis is specified by context-free grammars and implemented by pushdown automata.
II. Syntax Analysis is specified by regular expressions and implemented by finite-state machine.
Which of the above statement(s) is/are correct?
A)Only I
B)Only II
C)Both I and II
D)Neither I nor II
I. Lexical Analysis is specified by context-free grammars and implemented by pushdown automata.
II. Syntax Analysis is specified by regular expressions and implemented by finite-state machine.
Which of the above statement(s) is/are correct?
A)Only I
B)Only II
C)Both I and II
D)Neither I nor II
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 24 في هذه المجموعة.
فتح الحزمة
k this deck
6
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
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 24 في هذه المجموعة.
فتح الحزمة
k this deck
7
From the given data below : a b b a a b b a a b which one of the following is not a word in the dictionary created by LZ-coding (the initial words are a, b)?
A)a b
B)b b
C)b a
D)b a a b
A)a b
B)b b
C)b a
D)b a a b
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 24 في هذه المجموعة.
فتح الحزمة
k this deck
8
The number of tokens in the following C statement is printf("i=%d, &i=%x", i&i);
A)13
B)6
C)10
D)9
A)13
B)6
C)10
D)9
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 24 في هذه المجموعة.
فتح الحزمة
k this deck
9
In compiler optimization, operator strength reduction uses mathematical identities to replace slow math operations with faster operations. Which of the following code replacements is an illustration of operator strength reduction?
A)Replace P + P by 2 * P or Replace 3 + 4 by 7.
B)Replace P * 32 by P < < 5
C)Replace P * 0 by 0
D)Replace (P < <4) - P by P * 15
A)Replace P + P by 2 * P or Replace 3 + 4 by 7.
B)Replace P * 32 by P < < 5
C)Replace P * 0 by 0
D)Replace (P < <4) - P by P * 15
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 24 في هذه المجموعة.
فتح الحزمة
k this deck
10
Debugger is a program that
A)allows to examine and modify the contents of registers
B)does not allow execution of a segment of program
C)allows to set breakpoints, execute a segment of program and display contents of register
D)All of the above
A)allows to examine and modify the contents of registers
B)does not allow execution of a segment of program
C)allows to set breakpoints, execute a segment of program and display contents of register
D)All of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 24 في هذه المجموعة.
فتح الحزمة
k this deck
11
Consider the following two sets of LR(1) items of an LR(1) grammar.
X -> c.X, c/d
X -> .cX, c/d
X -> .d, c/d
X -> c.X, $
X -> .cX, $
X -> .d, $
Which of the following statements related to merging of the two sets in thecorresponding LALR parser is/are FALSE?
1) Cannot be merged since look aheads are different.
2) Can be merged but will result in S-R conflict.
3) Can be merged but will result in R-R conflict.
4) Cannot be merged since goto on c will lead to two different sets.
A)1 only
B)2 only
C)1 and 4 only
D)1, 2, 3, and 4
X -> c.X, c/d
X -> .cX, c/d
X -> .d, c/d
X -> c.X, $
X -> .cX, $
X -> .d, $
Which of the following statements related to merging of the two sets in thecorresponding LALR parser is/are FALSE?
1) Cannot be merged since look aheads are different.
2) Can be merged but will result in S-R conflict.
3) Can be merged but will result in R-R conflict.
4) Cannot be merged since goto on c will lead to two different sets.
A)1 only
B)2 only
C)1 and 4 only
D)1, 2, 3, and 4
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 24 في هذه المجموعة.
فتح الحزمة
k this deck
12
The grammar S ? aSa | bS | c is
A)LL(1) but not LR(1)
B)LR(1)but not LR(1)
C)Both LL(1)and LR(1)
D)Neither LL(1)nor LR(1)
A)LL(1) but not LR(1)
B)LR(1)but not LR(1)
C)Both LL(1)and LR(1)
D)Neither LL(1)nor LR(1)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 24 في هذه المجموعة.
فتح الحزمة
k this deck
13
Which of the following statements are TRUE?
I. There exist parsing algorithms for some programming languages whose complexities are less than O( n3).
II. A programming language which allows recursion can be implemented with static storage allocation.
III. No L-attributed definition can be evaluated in the framework of bottom-up parsing.
IV. Code improving transformations can be performed at both source language and intermediate code level.
A)I and II
B)I and IV
C)III and IV
D)I, III and IV
I. There exist parsing algorithms for some programming languages whose complexities are less than O( n3).
II. A programming language which allows recursion can be implemented with static storage allocation.
III. No L-attributed definition can be evaluated in the framework of bottom-up parsing.
IV. Code improving transformations can be performed at both source language and intermediate code level.
A)I and II
B)I and IV
C)III and IV
D)I, III and IV
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 24 في هذه المجموعة.
فتح الحزمة
k this deck
14
Which of the following describes a handle (as applicable to LR-parsing) appropriately?
A)It is the position in a sentential form where the next shift or reduce operation will occur
B)It is non-terminal whose production will be used for reduction in the next step
C)It is a production that may be used for reduction in a future step along with a position in the sentential form where the next shift or reduce operation will occur
D)It is the production p that will be used for reduction in the next step along with a position in the sentential form where the right hand side of the production may be found
A)It is the position in a sentential form where the next shift or reduce operation will occur
B)It is non-terminal whose production will be used for reduction in the next step
C)It is a production that may be used for reduction in a future step along with a position in the sentential form where the next shift or reduce operation will occur
D)It is the production p that will be used for reduction in the next step along with a position in the sentential form where the right hand side of the production may be found
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 24 في هذه المجموعة.
فتح الحزمة
k this deck
15
An LALR(1) parser for a grammar G can have shift-reduce (S-R) conflicts if and only if
A)the SLR(1) parser for G has S-R conflicts
B)the LR(1) parser for G has S-R conflicts
C)the LR(0) parser for G has S-R conflicts
D)the LALR(1) parser for G has reduce-reduce conflicts
A)the SLR(1) parser for G has S-R conflicts
B)the LR(1) parser for G has S-R conflicts
C)the LR(0) parser for G has S-R conflicts
D)the LALR(1) parser for G has reduce-reduce conflicts
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 24 في هذه المجموعة.
فتح الحزمة
k this deck
16
Consider the following two statements:
P: Every regular grammar is LL(1)
Q: Every regular set has a LR(1) grammar
Which of the following is TRUE?
A)Both P and Q are true
B)P is true and Q is false
C)P is false and Q is true
D)Both P and Q are false
P: Every regular grammar is LL(1)
Q: Every regular set has a LR(1) grammar
Which of the following is TRUE?
A)Both P and Q are true
B)P is true and Q is false
C)P is false and Q is true
D)Both P and Q are false
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 24 في هذه المجموعة.
فتح الحزمة
k this deck
17
Consider the following grammar. S -> S * E
S -> E
E -> F + E
E -> F
F -> id
Consider the following LR(0) items corresponding to the grammar above.
(i) S -> S * .E
(ii) E -> F. + E
(iii) E -> F + .E
Given the items above, which two of them will appear in the same set in the canonicalsets-of-items for the grammar?
A)(i) and (ii)
B)(ii) and (iii)
C)(i) and (iii)
D)None of the above
S -> E
E -> F + E
E -> F
F -> id
Consider the following LR(0) items corresponding to the grammar above.
(i) S -> S * .E
(ii) E -> F. + E
(iii) E -> F + .E
Given the items above, which two of them will appear in the same set in the canonicalsets-of-items for the grammar?
A)(i) and (ii)
B)(ii) and (iii)
C)(i) and (iii)
D)None of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 24 في هذه المجموعة.
فتح الحزمة
k this deck
18
A canonical set of items is given below
S --> L. > R
Q --> R.
On input symbol < the set has
A)a shift-reduce conflict and a reduce-reduce conflict.
B)a shift-reduce conflict but not a reduce-reduce conflict.
C)a reduce-reduce conflict but not a shift-reduce conflict.
D)neither a shift-reduce nor a reduce-reduce conflict.
S --> L. > R
Q --> R.
On input symbol < the set has
A)a shift-reduce conflict and a reduce-reduce conflict.
B)a shift-reduce conflict but not a reduce-reduce conflict.
C)a reduce-reduce conflict but not a shift-reduce conflict.
D)neither a shift-reduce nor a reduce-reduce conflict.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 24 في هذه المجموعة.
فتح الحزمة
k this deck
19
Consider the grammar defined by the following production rules, with twooperators ? and +
S --> T * P
T --> U | T * U
P --> Q + P | Q
Q --> Id
U --> Id
Which one of the following is TRUE?
A)+ is left associative, while ? is right associative
B)+ is right associative, while ? is left associative
C)Both + and ? are right associative
D)Both + and ? are left associative
S --> T * P
T --> U | T * U
P --> Q + P | Q
Q --> Id
U --> Id
Which one of the following is TRUE?
A)+ is left associative, while ? is right associative
B)+ is right associative, while ? is left associative
C)Both + and ? are right associative
D)Both + and ? are left associative
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 24 في هذه المجموعة.
فتح الحزمة
k this deck
20
Consider the following grammar:
S ? FR
R ? S | ?
F ? id
In the predictive parser table, M, of the grammar the entries M[S, id] and M[R, $]respectively.
A){S ? FR} and {R ? ? }
B){S ? FR} and { }
C){S ? FR} and {R ? *S}
D){F ? id} and {R ? ?}
S ? FR
R ? S | ?
F ? id
In the predictive parser table, M, of the grammar the entries M[S, id] and M[R, $]respectively.
A){S ? FR} and {R ? ? }
B){S ? FR} and { }
C){S ? FR} and {R ? *S}
D){F ? id} and {R ? ?}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 24 في هذه المجموعة.
فتح الحزمة
k this deck
21
Consider the following translation scheme. S ? ER R ? *E{print("*");}R | ? E? F + E {print("+");} | F F ? (S) | id {print(id.value);} Here id is a token that represents an integer and id.value represents the corresponding integer value. For an input '2 * 3 + 4', this translation scheme prints
A)2 * 3 + 4
B)2 * +3 4
C)2 3 * 4 +
D)2 3 4+*
A)2 * 3 + 4
B)2 * +3 4
C)2 3 * 4 +
D)2 3 4+*
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 24 في هذه المجموعة.
فتح الحزمة
k this deck
22
The grammar A ? AA | (A) | ? is not suitable for predictive-parsing because the grammar is
A)ambiguous
B)left-recursive
C)right-recursive
D)an operator-grammar
A)ambiguous
B)left-recursive
C)right-recursive
D)an operator-grammar
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 24 في هذه المجموعة.
فتح الحزمة
k this deck
23
Consider the grammar S ? (S) | a Let the number of states in SLR(1), LR(1) and LALR(1) parsers for the grammar be n1, n2 and n3 respectively. The following relationship holds good
A) n1 < n2 < n3
B) n1 = n3 < n2
C) n1 = n2 = n3
D) n1 ? n3 ? n2
A) n1 < n2 < n3
B) n1 = n3 < n2
C) n1 = n2 = n3
D) n1 ? n3 ? n2
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 24 في هذه المجموعة.
فتح الحزمة
k this deck
24
Consider the following expression grammar. The seman-tic rules for expressioncalculation are stated next to each grammar production.
E ? number E.val = number. val
| E '+' E E(1).val = E(2).val + E(3).val
| E '×' E E(1).val = E(2).val × E(3).val
The above grammar and the semantic rules are fed to a yacc tool (which is an LALR (1)parser generator) for parsing and evaluating arithmetic expressions. Which one of thefollowing is true about the action of yacc for the given grammar?
A)It detects recursion and eliminates recursion
B)It detects reduce-reduce conflict, and resolves
C)It detects shift-reduce conflict, and resolves the conflict in favor of a shift over a reduce action
D)It detects shift-reduce conflict, and resolves the conflict in favor of a reduce over a shift action
E ? number E.val = number. val
| E '+' E E(1).val = E(2).val + E(3).val
| E '×' E E(1).val = E(2).val × E(3).val
The above grammar and the semantic rules are fed to a yacc tool (which is an LALR (1)parser generator) for parsing and evaluating arithmetic expressions. Which one of thefollowing is true about the action of yacc for the given grammar?
A)It detects recursion and eliminates recursion
B)It detects reduce-reduce conflict, and resolves
C)It detects shift-reduce conflict, and resolves the conflict in favor of a shift over a reduce action
D)It detects shift-reduce conflict, and resolves the conflict in favor of a reduce over a shift action
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 24 في هذه المجموعة.
فتح الحزمة
k this deck