Latest Compiler Design Interview Questions
What Is A Compiler?
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.
What Are The Two Parts Of A Compilation? Explain Briefly.
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.
List The Sub Parts Or Phases Of Analysis Part.
Analysis consists of three phases:
Linear Analysis.
Hierarchical Analysis.
Semantic Analysis.
Suggest A Suitable Approach For Computing Hash Function.
Using hash function we should obtain exact locations of name in symbol table.
The hash function should result in uniform distribution of names in symbol table.
The hash function should be such that there will be minimum number of collisions.
Collision is such a situation where hash function results in same location for storing the names.
What Is Code Motion?
Code motion is an optimization technique in which amount of code in a loop is decreased. This transformation is applicable 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.
What Are The Properties Of Optimizing Compiler?
The source code should be such that it should produce minimum amount of target code.
There should not be any unreachable code.
Dead code should be completely removed from source language.
The optimizing compilers should apply following code improving transformations on source language.
common subexpression elimination
dead code elimination
code movement
strength reduction
What Are The Various Ways To Pass A Parameter In A Function?
Call by value
Call by reference
Copy-restore
Call by name
Mention The Issues To Be Considered While Applying The Techniques For Code Optimization.
The semantic equivalence of the source program must not be changed.
The improvement over the program efficiency must be achieved without changing the algorithm of the program.
The machine dependent optimization is based on the characteristics of the target machine for the instruction set used and addressing modes used for the instructions to produce the efficient target code.
The machine independent optimization is based on the characteristics of the programming languages for appropriate programming structure and usage of efficient arithmetic properties in order to reduce the execution time.
Available expressions.
Reaching definitions.
Live variables.
Busy variables.
What Are The Basic Goals Of Code Movement?
•To reduce the size of the code i.e. to obtain the space complexity.
•To reduce the frequency of execution of code i.e. to obtain the time complexity.
List The Different Storage Allocation Strategies.
The strategies are:
Static allocation
Stack allocation
Heap allocation
What Are The Contents Of Activation Record?
The activation record is a block of memory used for managing the information needed by a single execution of a procedure.
Various fields f activation record are:
Temporary variables
Local variables
Saved machine registers
Control link
Access link
Actual parameters
Return values
What Is Dynamic Scoping?
In dynamic scoping a use of non-local variable refers to the non-local data declared in most recently called and still active procedure. Therefore each time new findings are set up for local names called procedure. In dynamic scoping symbol tables can be required at run time.
Define Symbol Table.
Symbol table is a data structure used by the compiler to keep track of semantics of the variables. It stores information about scope and binding information about names.
What Is Linear Analysis?
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.
List The Various Phases Of A Compiler.
The following are the various phases of a compiler:
Lexical Analyzer
Syntax Analyzer
Semantic Analyzer
Intermediate code generator
Code optimizer
Code generator
What Are The Classifications Of A Compiler?
Compilers are classified as:
Single- pass
Multi-pass
Load-and-go
Debugging or optimizing
What Is A Symbol Table?
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.
Mention Some Of The Cousins Of A Compiler.
Cousins of the compiler are:
Preprocessors
Assemblers
Loaders and Link-Editors
List The Phases That Constitute The Front End Of A Compiler.
The front end consists of those phases or parts of phases that depend primarily on the source language and are largely independent of the target machine.
These include
· Lexical and Syntactic analysis
· The creation of symbol table
· Semantic analysis
· Generation of intermediate code
A certain amount of code optimization can be done by the front end as well. Also includes error handling that goes along with each of these phases.
Mention The Back-end Phases Of A Compiler.
The back end of compiler includes those portions that depend on the target machine and generally those portions do not depend on the source language, just the intermediate language.
These include
· Code optimization
· Code generation, along with error handling and symbol- table operations.