Compiler interview questions

16. What is an translator ?
A translator is a program that takes as input a program written in one language and produces as output a program in another language. Beside program translation, the translator performs another very important role, the error-detection. Any violation of d HLL specification would be detected and reported to the programmers.

17. What is Syntax-Directed Definition(SDD) for translation ?
a. SDD is a set of semantic rules predefined for each productions respectively for translation.
b. A translation is an input-output mapping procedure for translation of an input X,
a.1) Construct a parse tree for X.
a.2) Synthesize attributes over the parse tree.
a.2.a) Suppose a node n in parse tree is labeled by X and X.a denotes the value of attribute a of X at that node.
a.2.b) Compute X’s attributes X.a using the semantic rules associated with X.

18. What is Shift-reduce parsing ?
Shift-reduce parsing is a type of bottom-up parsing that attempts to construct a parse tree for an input string beginning at the leaves (the bottom) and working up towards the root.

19. What are the different types of LR parser ?
SLR parser – simple LR parser
LALR parser – lookahead LR parser
Canonical LR parse

20. What are the phases of a compiler ?
A compiler operates in phases. There are two phases of compilation.
a. Analysis (Machine Independent/Language Dependent)
b. Synthesis(Machine Dependent/Language independent)

Author: user

Leave a Reply