Recent questions tagged goclasses-compiler-practice-questions

2 2 votes
3 3 answers
603
603 views
A lexical analyzer is designed for a new language with the following rules for token generation:$\mathrm{KEYWORD1}: \verb|if|$ $\mathrm{KEYWORD2}: \verb|iff|$ $\mathrm{ID...
2 2 votes
5 5 answers
595
595 views
Consider the following arammar $G$ :$$\begin{aligned}& S \rightarrow(L) \mid a \\& L \rightarrow L, S \mid S\end{aligned}$$Which of the following statement(s) is/are TRUE...
5 5 votes
2 2 answers
320
320 views
Consider a Bottom-Up parser for a grammar $G$. During the parsing of an input string $w$, the parser reaches a configuration where the stack contains the prefix $\alpha$ ...
2 2 votes
2 2 answers
333
333 views
Which of the following statement(s) is/are TRUE regarding Lexical Analysis and Regular Expressions?The number of states in a minimal Deterministic Finite Automaton (DFA) ...
1 1 vote
2 2 answers
323
323 views
Consider the following Syntax Directed Translation (SDT) scheme where $S$ is the start symbol and $id.\mathrm{val}$ represents the numerical value of an identifier:$$\beg...
1 1 vote
2 2 answers
388
388 views
A lexical analyzer for a specific language identifies tokens using the following regular expressions:$$\begin{aligned}& L_1: a(a \mid b)^* \\& L_2: a b(a \mid b)^* \\& L_...
1 1 vote
1 1 answer
311
311 views
Consider the following basic block of intermediate code:1. a = 10 2. b = a + 5 3. c = b * 2 4. a = c - b 5. d = a + bAssuming that only the variable $\verb|d|$ is "live" ...
2 2 votes
2 2 answers
307
307 views
Consider the following L-attributed Syntax Directed Definition (SDD). $S$ is the start symbol, and S.val is a synthesized attribute. A.inh is an inherited attribute.$S \r...
1 1 vote
1 1 answer
287
287 views
In the context of Code Optimization, consider the following code segment inside a loop:for (i = 0; i < n; i++) { x = y + z; a[i] = 2 * i + x; }Moving the statemen...
2 2 votes
3 3 answers
368
368 views
Consider the following syntax-directed translation scheme (SDTS) where $S$ is the start symbol:$$\begin{aligned}& S \rightarrow E\{\text { print }(\text { E.val })\} \\& ...
2 2 votes
1 1 answer
316
316 views
Consider the following grammar $g$ :$$\begin{gathered}s \rightarrow l=r \mid r \\l \rightarrow * r \mid i d \\r \rightarrow l\end{gathered}$$Which of the following statem...
1 1 vote
1 1 answer
283
283 views
Consider the following basic block of three-address code:$\mathrm{t 1=a+b}$ $\mathrm{t 2=c* d}$ $\mathrm{t} 3=\mathrm{t} 1+\mathrm{t} 2$ $\mathrm{a=t 3}$ $\mathrm{t 4=c*d...
2 2 votes
1 1 answer
301
301 views
Consider the following regular expression over the alphabet $\{a, b\}$ used for a lexical analyzer token definition:$$R=(a+b)^*(a a+b b)(a+b)^*$$Which of the following de...
1 1 vote
2 2 answers
310
310 views
Consider the following SDT scheme used to evaluate an expression. The synthesized attribute $\mathrm{val}$ stores the numerical value.\[\begin{aligned}E &\rightarrow E_1 ...
2 2 votes
1 1 answer
291
291 views
Consider the following grammar $G$ with terminal set $\Sigma=\{a, b, c, d\}$ and non-terminal set $V=\{S, A, B\}$ :$$\begin{gathered}S \rightarrow a A b \mid b B a \\A \r...
0 0 votes
1 1 answer
354
354 views
Consider the following sequence of three-address code (TAC) instructions:1. i = 1 2. j = 1 3. t1 = 5 * i 4. t2 = t1 + j 5. a[t2] = 0 6. j = j + 1 7. if j <= 5 goto (3) 8....
2 2 votes
2 2 answers
344
344 views
Consider the following grammar $G$ with start symbol $S$ :$$\begin{aligned}& S \rightarrow L=R \\& S \rightarrow R \\& L \rightarrow * R \\& L \rightarrow i d . \\& R \ri...
1 1 vote
1 1 answer
314
314 views
Consider the following basic block of Three-Address Code:1. a = 1 2. b = a + 1 3. c = a + b 4. a = c + b 5. return aA variable is live at a point if its current value wil...
1 1 vote
2 2 answers
307
307 views
Consider the following Syntax-Directed Translation (SDT) scheme with the grammar rules and actions provided below:$$\begin{aligned}& S \rightarrow S_1 \# T\left\{S . \mat...
2 2 votes
3 3 answers
380
380 views
Consider the following lexical specification for a scanner:$\mathrm{KEYWORD\_IF: \verb|if|}$ $\mathrm{ID: [a-z][0-9]*}$ $\mathrm{NUM: [0-9]+}$ The scanner follows the Lon...
1 1 vote
1 1 answer
274
274 views
Consider the following three-address code sequence used for a loop:i = 0 L1: t1 = i * 4 t2 = base + t1 val = load t2 i = i + 1 if i < 100 goto L1Which optimization techni...
1 1 vote
1 1 answer
266
266 views
An $\mathrm{LR(1)}$ parser is being constructed for a grammar. If a particular state in the corresponding $\mathrm{LR}(1)$ canonical collection contains the item $[A \rig...
1 1 vote
2 2 answers
270
270 views
In a compiler's optimization phase, a Directed Acyclic Graph (DAG) is often used instead of a standard syntax tree to represent expressions. Consider the expression: $a=(...
0 0 votes
1 1 answer
289
289 views
Consider a syntax tree for the expression $a+b * c-d / e$. If the expression is evaluated using a post-order traversal of this tree, and the values at the leaves are $a=2...
1 1 vote
1 1 answer
248
248 views
Consider the expression tree shown below. Each leaf represents a numerical value, which can be chosen from the set $\{-1,1\}$. Over all possible choices of the values at ...
0 0 votes
2 2 answers
293
293 views
Consider the following basic block consisting of three-address code instructions. Assume that only the variable $\verb|x|$ is "live" at the exit of this basic block.1. a ...
1 1 vote
1 1 answer
246
246 views
Consider the following C-style code segment:while (a < b) { if (c < d) x = y + z; else x = y - z; }Assume this code is translated into Three-Address Code (TAC) us...
1 1 vote
1 1 answer
283
283 views
In a compiler's optimization phase, a Directed Acyclic Graph (DAG) is constructed for the following basic block:1. t1 = a + b 2. t2 = c * d 3. t3 = t1 + t2 4. t4 = a + b ...
1 1 vote
1 1 answer
276
276 views
Consider the following S-attributed SDT scheme used to calculate the value of an expression. The grammar generates simple arithmetic additions and is suitable for an LR p...
3 3 votes
2 2 answers
342
342 views
Consider the following regular expression over the alphabet $\Sigma=\{a, b\}$ that represents a specific class of tokens in a new programming language:$$r=(a+b)^* a b b$$...