1. What is a compiler?
Ans: 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 informs its user of the presence of errors in the source program.
2. What are the two parts of a compilation? Explain briefly.
Ans: Analysis and Synthesis are the two parts of the compilation.
The analysis part divides the source program into constituent parts and creates an intermediate representation of the source program.
The synthesis part constructs the desired objective program from the intermediate representation.
3. List the parts or phases of the analysis part.
Ans: The analysis consists of three phases:
• Linear analysis.
• Hierarchical analysis.
• Semantic analysis.
4. Represent schematically how a language is processed.
Ans:
Skeletal source program
↓
Preprocessor
↓
Source program
↓
Compiler
↓
Destination assembly program
↓
Assembler
↓
Relocatable machine code
↓
Loader / link editor ← library, relocatable object files
↓
Absolute machine code
5. What is linear analysis?
Ans: The linear analysis is one in which the sequence of characters that make up the source program is read from left to right and is grouped into tokens that are sequences of characters that have a collective meaning.
It is also called lexical analysis or scanning.
6. Make a list of the various phases of a compiler.
Ans: The following are the various phases of a compiler:
• Lexicon Analyzer
• Syntax Analyzer
• Semantic analyzer
• Intermediate code generator
• Optimizer code
• Code generator
7. What are the classifications of a compiler?
Ans: Compilers are classified as:
• Single-pass
• Multiple pass
• Load and carry
• Debugging or optimization
8. What is a symbol table?
Ans: A symbol table is a data structure that contains a record for each identifier, with fields for the attributes of the identifier. The data structure allows us to quickly find the record of each identifier and store or retrieve data from that record quickly.
Each time a lexical analyzer detects an identifier, it is entered into the symbol table. The attributes of an identifier can not be determined by the lexical analyzer.
9. Name some of the cousins of a compiler.
Ans: Cousins of the compiler are:
• Preprocessors
• Assemblers
• Loaders and Link Editors
10. List the phases that make up the front of a compiler.
Ans: The front-end consists of those phases or parts of phases that depend mainly on the source language and are largely independent of the target machine. These include
• Lexicon and syntactic analysis
• The creation of the symbol table
• Semantic analysis
• Generation of intermediate code
You can also do a certain amount of code optimization by the front end. It also includes the error handling that accompanies each of these phases.
11. Name the back-end phases of a compiler.
Ans: The backend of the compiler includes those parts that depend on the target machine and generally those parts do not depend on the source language, only the intermediate language. These include
• Code optimization
• Generation of code, together with error handling and symbol table operations.
12. Define compiler-compiler.
Ans:Systems to help with the compiler's writing process are often referred to as compiler compilers, compiler generators or translators' writing systems.
To a large extent they are oriented around a particular model of languages, and are suitable for generating similar language compilers.
13. List the various compiler construction tools.
Ans: The following is a list of some compiler build tools:
• Analyzer generators
• Scanner generators
• Translation engines guided by syntax
• Automatic code generators
• Data flow engines
14. Differentiate tokens, patterns, lexeme.
Ans:
• Tokens: sequence of characters that have a collective meaning.
• Patterns: there is a set of strings in the entry for which the same token is generated 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 matches the pattern of a token.
15. Make a list of operations in languages.
Ans:
• 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)