Compiler Design MCQ Quiz in தமிழ் - Objective Question with Answer for Compiler Design - இலவச PDF ஐப் பதிவிறக்கவும்

Last updated on Mar 8, 2025

பெறு Compiler Design பதில்கள் மற்றும் விரிவான தீர்வுகளுடன் கூடிய பல தேர்வு கேள்விகள் (MCQ வினாடிவினா). இவற்றை இலவசமாகப் பதிவிறக்கவும் Compiler Design MCQ வினாடி வினா Pdf மற்றும் வங்கி, SSC, ரயில்வே, UPSC, மாநில PSC போன்ற உங்களின் வரவிருக்கும் தேர்வுகளுக்குத் தயாராகுங்கள்.

Latest Compiler Design MCQ Objective Questions

Top Compiler Design MCQ Objective Questions

Compiler Design Question 1:

Which of the following is/are the functionality of a lexical analyzer?

  1. it recognizes lexemes and produces a stream of tokens.
  2. It recognizes white space, comments, tab, and ignore it.
  3. It gives lexical error and also gives line number.
  4. It matches the longest prefix of the identifier.

Answer (Detailed Solution Below)

Option :

Compiler Design Question 1 Detailed Solution

Lexical analyzer recognizes the lexemes (alphanumeric characters in a token ) and recognize the white spaces, comments, tab and ignore them.

example;

a = \* comment*/          b;

so total 4 tokens are there (a, =, b and ;)

all spaces, tabs and comments are ignored by lexical analyzer. 

when any error occur during lexical analyzer phase then lexical analyzer show the error with line number where error is occured.

and also check the longest prefix of the identifier.

So, all the options are correct.

Compiler Design Question 2:

What are the number of nodes and edges in the DAG (directed acyclic graph) representation of the following basic block:

d = b * c

e = a + b

b = b * c

a = e – d

  1. 4 and 7
  2. 7 and 4
  3. 6 and 6
  4. 6 and 5

Answer (Detailed Solution Below)

Option 3 : 6 and 6

Compiler Design Question 2 Detailed Solution

Directed acyclic graph is a representations for single expressions.  DAG representation perform several code improving transformations on the code represented by the block. It can eliminate local common subexpression, can eliminate dead code and can reorder statements that do not depend on one another.

For the given basic block:

d = b * c

e = a + b

b = b * c

a = e – d

DAG can be constructed as :

STEP 1:

F1 Shraddha Raju 24.08.2020 D2

STEP 2:

F1 Shraddha Raju 24.08.2020 D3

STEP 3:

F1 Shraddha Raju 24.08.2020 D4

So, total number of nodes are 6 and total number of edges are 6.

Compiler Design Question 3:

Consider the grammar defined by the following production rules, with two operators ∗ and +

S → T * P

T → U|T * U

P → Q + P|Q

Q → Id

U → Id

Which one of the following is TRUE?

  1. + is left associative, while ∗ is right associative
  2. + is right associative, while ∗ is left associative
  3. Both + and ∗ are right associative
  4. Both + and ∗ are left associative

Answer (Detailed Solution Below)

Option 2 : + is right associative, while ∗ is left associative

Compiler Design Question 3 Detailed Solution

In second production T → T * U here T is generating T*U left recursively so * is left associative.

In third production P → Q + P, Here P is generating Q + P right recursively so + is right associative.

Hence option 2 is the correct answer.

Compiler Design Question 4:

Consider the below given table in which regular expression is mapped to unique token:

Regular Expression Token
p*(p | q)p* 3
qp* 1
p+(r | q) pq 2

What will be the output when the string ''pppqppqprpqp" is scanned by the lexical analyzer if the analyzer outputs the token that matches the longest possible prefix if it is mandatory to use all the tokens at least once?

  1. 3121
  2. 3213
  3. 2133
  4. 3123

Answer (Detailed Solution Below)

Option 4 : 3123

Compiler Design Question 4 Detailed Solution

String: pppqppqprpqp

Regular expression

p*(p | q)p*

qp*

 

p+(r | q) pq

 

p*(p | q)p*

Token

3

1

2

3

String

pppqpp

q

prpq

p

 

The output is 3123

Compiler Design Question 5:

What is a compiler?

  1. A compiler does a conversion line by line as the program is run
  2. A compiler converts the whole of a high-level program code into machine code in one step
  3. A compiler is a general-purpose language providing very efficient execution
  4. None of these

Answer (Detailed Solution Below)

Option 2 : A compiler converts the whole of a high-level program code into machine code in one step

Compiler Design Question 5 Detailed Solution

The correct answer is option 2

CONCEPT:

  • Compiler, Computer software that translates source code written in a high-level language into a set of machine-language instructions that can be understood by a digital computer’s CPU.
  • It scans the entire program and translates the whole of it into machine code at once.
  • Compiler always generates an intermediary object code.
  • It will need further linking. Hence more memory is needed.
  • Source code → Compiler → Machine code → Output
  • Compilers are very large programs, with error-checking and other abilities.
  • Compiler can diagnose grammatical errors only

 

Compiler Design Question 6:

Consider the following program

Program 1:

int main()

{

       char a[10] =”Testbook”;

       %%

       %%

       return 0;

}

Program 2:

int main()

{

       char a[10]  =”Testbook”;

       int p=20,q=30,r,s,s;

       if(p>q;

                 r = 20;

}

Program 3:

int main()

{

       char a[10]  =”Testbook”;

       int p=20,q=30,r,s,s;

}

Program 4:

int main()

{

       char a[10]  =”Testbook”;

       /* He*/llo /*

       If(a!=’\0’)

       b = 10;

}

Lexical errors are present in programs

  1. Program 1
  2. Program 2
  3. Program 3
  4. Program 4

Answer (Detailed Solution Below)

Option :

Compiler Design Question 6 Detailed Solution

The correct answer is option 1 and option 4.

Key Points

Lexical phase errors:

These errors are detected during the lexical analysis phase.

  • Typical lexical errors are Exceeding the length of identifier or numeric constants.
  • The appearance of illegal characters
  • Unmatched string

Syntactic phase errors:

These errors are detected during the syntax analysis phase.  Typical syntax errors are

  • Errors in structure
  • Missing operator
  • Misspelt keywords
  • Unbalanced parenthesis

Semantic errors:

These errors are detected during the semantic analysis phase.

  • Typical semantic errors are Incompatible types of operands
  • Undeclared variables
  • Not matching of actual arguments with the formal one

Program 1:

int main()

{

       char a[10] =”Testbook”;

       %%  / The appearance of illegal characters  leads to lexical errors.

       %%

       return 0;

}

Program 2:

int main()

{

       char a[10]  =”Testbook”;

       int p=20,q=30,r,s,s;

       if(p>q;       / Missing operator it leads to syntactic errors but no lexical errors.

       r = 20;

}

Program 3:

int main()

{

       char a[10]  =”Testbook”;

       int p=20,q=30,r,s,s;

}

Program 4:

int main()

{

       char a[10]  =”Testbook”;

       /* He*/llo /*    /The appearance of illegal characters leads to lexical errors.

       If(a!=’\0’)

       b = 10;

}

Compiler Design Question 7:

Which of the following statements is/are true about the parser?

A. Leftmost derivation is used for Bottom-up parser.

B. Rightmost in reverse derivation is used by LL parser.

  1. Only A
  2. Only B
  3. Both A and B
  4. Neither A nor B

Answer (Detailed Solution Below)

Option 4 : Neither A nor B

Compiler Design Question 7 Detailed Solution

 Parser

 Derivation

 LR parsers or Bottom-up Parsers 

 Rightmost reverse Derivation 

 LL parsers or Top-down Parsers

 Leftmost Derivation

Therefore, both statements are false. Hence option 4 is correct

Compiler Design Question 8:

Which of the following statements about parser is/are CORRECT?

I. Canonical LR is more powerful than SLR.

II. SLR is more powerful than LALR.

III. SLR is more powerful than Canonical LR.

  1. I only
  2. II only
  3. III only
  4. II and III only

Answer (Detailed Solution Below)

Option 1 : I only

Compiler Design Question 8 Detailed Solution

Concept: LR parsers in terms of their power:

CLR > LALR > SLR > LR (0)

Explanation:

I. Canonical LR is more powerful than SLR. TRUE

II. SLR is more powerful than LALR. FALSE

III. SLR is more powerful than Canonical LR. FALSE

Compiler Design Question 9:

A lexical analyzer uses the following patterns to recognize three tokens T1, T2, and T3 over the alphabet {a,b,c}.

𝑇1: 𝑎? (𝑏|𝑐)∗𝑎

𝑇2: 𝑏? (𝑎|𝑐)∗𝑏

𝑇3: 𝑐? (𝑏|𝑎)∗𝑐

Note that ‘x?’ means 0 or 1 occurrence of the symbol x. Note also that the analyzer outputs the token that matches the longest possible prefix. If the string 𝑏𝑏𝑎𝑎𝑐𝑎𝑏𝑐 is processed by the analyzer, which one of the following is the sequence of tokens it outputs?

  1. 𝑇1𝑇2𝑇3
  2. 𝑇1𝑇1𝑇3
  3. 𝑇2𝑇1𝑇3
  4. 𝑇3𝑇3

Answer (Detailed Solution Below)

Option 4 : 𝑇3𝑇3

Compiler Design Question 9 Detailed Solution

Concept:

Take relational algebra which generates the longest subsequence.

With  T3 we get a subsequence of 5, and T1 we get a subsequence of only 4, T2 we get a subsequence of only 3.

Hence, T3 preferred over Tand T1

Explanation

String = 𝑏𝑏𝑎𝑎𝑐𝑎𝑏𝑐

(𝑏|𝑎)∗ = (a + b)*

𝑐? = (ϵ + c)

𝑇3𝑐? (𝑏|𝑎)∗𝑐

T3 = bbaac (longest prefix match)

T3= abc

𝑇3𝑇3 = 𝑏𝑏𝑎𝑎𝑐 𝑎𝑏𝑐

Therefore option 4 is correct

Compiler Design Question 10:

What will be the result of following code after constant propagation?

int x =4;

int y = x * 2;

int z = a[y];

  1. int x = 4;

    int y = 4 * 2;

    int z = a[y];
  2. int y =4 *2;

    int z = a[y]
  3. int y = 8;

    int z = a[y];

  4. int z = a[8];

Answer (Detailed Solution Below)

Option 4 : int z = a[8];

Compiler Design Question 10 Detailed Solution

Concept:

If the value of a variable is constant, then replace the variable with the constant and it must be propagated forward from the assignment point.

Explanation:

Given code:

Int x =4;

Int y = x * 2;

Int z = a[y];

Here we use the value of constant x = 4 and replace x by its value.

STEP 1: int y = 4 * 2; int z = a[y];

STEP 2: int y = 8; int z = a[y];

STEP 3: int z = a[8];
Get Free Access Now
Hot Links: teen patti club apk teen patti gold apk download teen patti winner teen patti vip teen patti master golden india