Frequently asked Compiler Design Viva Questions

In this post, we will discuss about Compiler Design Viva Questions which is another important topic for placement interviews as well as exams. So, without wasting time lets proceed.

Top Compiler Design Viva Questions

Q1. What Is A Compiler?

Answer: A compiler is a program that reads a program written in one language –the source language and translates it into an equivalent program in another language-the target language. The compiler reports to its user the presence of errors in the source program.

Q2. What Are The Two Parts Of A Compilation? Explain Briefly.

Answer: Analysis and Synthesis are the two parts of compilation. The analysis part breaks up the source program into constituent pieces and creates an intermediate representation of the source program. The synthesis part constructs the desired target program from the intermediate representation.

Q3. List The Sub Parts Or Phases Of Analysis Part ?

Answer: Analysis consists of three phases: Linear Analysis, Hierarchical Analysis, and Semantic Analysis.

Q4. What Is Code Motion?

Answer: Code motion is an optimization technique in which the amount of code in a loop is decreased. This transformation applies to the expression that yields the same result independent of the number of times the loop is executed. Such an expression is placed before the loop.

Q5.What Are The Properties Of Optimizing Compiler?

Answer: The source code should be such that it should produce a minimum amount of target code.

There should not be any unreachable code.

Dead code should be completely removed from the source language.

The optimizing compilers should apply the following code improving transformations on the source language.

  1. common subexpression elimination
  2. dead code elimination
  3. code movement
  4. strength reduction

Q6.  List The Different Storage Allocation Strategies?

Answer: The strategies are:

  1. Static allocation
  2. Stack allocation
  3. Heap allocation

Q7. What Are The Contents Of Activation Record?

Answer: The activation record is a block of memory used for managing the information needed by a single execution of a procedure.

Various fields of activation record are:

  1.  Temporary variables
  2.  Local variables
  3.  Saved machine registers
  4.  Control link
  5.  Access link
  6.  Actual parameters
  7.  Return values

Q8. Define Symbol Table.

Answer: A symbol table is a data structure used by the compiler to keep track of the semantics of the variables. It stores information about the scope and binding information about names.

Q9. What Is Linear Analysis?

Answer: Linear analysis is one in which the stream of characters making up the source program is read from left to right and grouped into tokens that are sequences of characters having a collective meaning. Also called lexical analysis or scanning.

Q10. List The Various Phases Of A Compiler?

Answer: The following are the various phases of a compiler:

  1. Lexical Analyzer
  2. Syntax Analyzer
  3. Semantic Analyzer
  4. Intermediate code generator
  5. Code optimizer
  6. Code generator

Q11. What Are The Classifications Of A Compiler?

Answer: Compilers are classified as:

  1. Single-pass
  2. Multi-pass
  3. Load-and-go
  4. Debugging or optimizing

Q12. What Is A Symbol Table?

Answer: A symbol table is a data structure containing a record for each identifier, with fields for the attributes of the identifier. The data structure allows us to find the record for each identifier quickly and to store or retrieve data from that record quickly.

Whenever an identifier is detected by a lexical analyzer, it is entered into the symbol table. The attributes of an identifier cannot be determined by the lexical analyzer.

Q13. Mention Some Of The Cousins Of A Compiler.

Answer: Cousins of the compiler are:

  1. Preprocessors
  2. Assemblers
  3. Loaders and Link-Editors

Q14. Define Compiler-compiler.

Answer: Systems to help with the compiler-writing process are often been referred to as compiler-compilers, compiler-generators, or translator-writing systems.

Largely they are oriented around a particular model of languages, and they are suitable for generating compilers of languages similar model.

Q15. List The Various Compiler Construction Tools.

Answer: The following is a list of some compiler construction tools:

  1. Parser generators
  2. Scanner generators
  3. Syntax-directed translation engines
  4. Automatic code generators
  5. Data-flow engines

Q16. Differentiate Tokens, Patterns, Lexeme.

Answer: Tokens- Sequence of characters that have a collective meaning.

Patterns- There is a set of strings in the input for which the same token is produced as output. This set of strings is described by a rule called a pattern associated with the token

Lexeme- A sequence of characters in the source program that is matched by the pattern for a token.

Q17. List The Operations On Languages.

Answer: Union – L U M ={s | s is in L or s is in M}

Concatenation – LM ={st | s is in L and t is in M}

Kleene Closure – L* (zero or more concatenations of L)

Positive Closure – L+ ( one or more concatenations of L)

Q18. What Is The Function Of A Hierarchical Analysis?

Answer: Hierarchical analysis is one in which the tokens are grouped hierarchically into nested collections with collective meaning. Also termed as Parsing.

Q19. What Does A Semantic Analysis Do?

Answer: Semantic analysis is one in which certain checks are performed to ensure that components of a program fit together meaningfully. Mainly performs type checking.

Q20. List The Various Error Recovery Strategies For A Lexical Analysis.

Answer :Possible error recovery actions are:

  1. Panic mode recovery
  2. Deleting an extraneous character
  3. Inserting a missing character
  4. Replacing an incorrect character by a correct character
  5. Transposing two adjacent characters

Q21. Mention The Basic Issues In Parsing.

Answer: There are two important issues in parsing.

  • Specification of syntax
  • Representation of input after parsing.

Q22. Why Lexical And Syntax Analysers Are Separated?

Answer: Reasons for separating the analysis phase into lexical and syntax analyzers:

  • Simpler design.
  • Compiler efficiency is improved.
  • Compiler portability is enhanced.

Q23. Define A Context-Free Grammar.

Answer: A context-free grammar G is a collection of the following

V is a set of nonterminals

T is a set of terminals

S is a start symbol

P is a set of production rules

G can be represented as G = (V,T,S,P)

Production rules are given in the following form

Nonterminal → (V U T)*

Q24. Briefly Explain The Concept Of Derivation.

Answer: Derivation from S means generation of string w from S. For constructing derivation two things are important.

i) Choice of the non-terminal from several others.

ii) Choice of rule from production rules for a corresponding non-terminal.

Instead of choosing the arbitrary non-terminal one can choose

i) either leftmost derivation – leftmost non-terminal in a sentinel form.

ii) or rightmost derivation – rightmost non-terminal in a sentinel form.

Q25. Define Ambiguous Grammar.

Answer: A grammar G is said to be ambiguous if it generates more than one parse tree for some sentence of language L(G).

i.e. both leftmost and rightmost derivations are the same for the given sentence.

Q26. What Is A Operator Precedence Parser?

Answer: A grammar is said to be operator precedence if it possesses the following properties:

1. No production on the right side is ε.

2. There should not be any production rule possessing two adjacent non-terminals on the right-hand side.

Q27. List The Properties Of Lr Parser?

Answer: 1. LR parsers can be constructed to recognize most of the programming languages for which context-free grammar can be written.

2. The class of grammar that can be parsed by LR parser is a superset of the class of grammars that can be parsed using predictive parsers.

3. LR parsers work using the non-backtracking shift-reduce technique yet it is an efficient one.

Q28. Mention The Types Of LR Parser?

Answer: SLR parser- simple LR parser, LALR parser- lookahead LR parser and Canonical LR parser.

Q29. What Are The Problems With Top-Down Parsing?

Answer: The following are the problems associated with the top-down parsing:

  1. Backtracking
  2. Left recursion
  3. Left factoring
  4. Ambiguity

Q30. What Are Kernel & Non-kernel Items?

Answer: Kernel items, which include the initial item, S’→ .S, and all items whose dots are not at the left end.

Non-kernel items, which have their dots at the left end.


Hope you find this post helpful. We have discussed the Compiler Design Viva Questions. We hope that you found it easy to understand.

Also read about SQL MCQ for Interview.

Stay tuned for more posts and updates. Until then, Happy Coding!

Leave a Comment

Your email address will not be published. Required fields are marked *