CC1
CC1
CC1
Advantage: More effective than multi-pass compilers in the compiler point of view.
Disadvantage: It compiles less efficient programs.
6. What is multi-pass compiler? Explain diagrammatically with its advantages
Disadvantages.
= A multi-pass compiler is a type of compiler that processes the source code or abstract
syntax tree of a program several times.
Advantages: It can be played very role useful when optimizing code. Disadvantages: It is a
very Slower process which takes a lot of time to compile the codes.
7. List phases of compiler. What is phase in compiler? Explain structure of compiler
diagrammatically.
= Analysis phase and Synthesis phase. The analysis phase creates an intermediate
representation from the given source code. The synthesis phase creates an equivalent
target program from the intermediate representation.
Lexical Analysis: Lexical analyzer phase is the first phase of compilation process. It takes
source code as input. It reads the source program one character at a time and converts it
into meaningful lexemes. Lexical analyzer represents these lexemes in the form of tokens.
Syntax Analysis: Syntax analysis is the second phase of compilation process. It takes
tokens as input and generates a parse tree as output. In syntax analysis phase, the parser
checks that the expression made by the tokens is syntactically correct or not.
Semantic Analysis: Semantic analysis is the third phase of compilation process. It checks
whether the parse tree follows the rules of language. Semantic analyzer keeps track of
identifiers, their types and expressions. The output of semantic analysis phase is the
annotated tree syntax.
Intermediate Code Generation: In the intermediate code generation, compiler generates
the source code into the intermediate code. Intermediate code is generated between the
high-level language and the machine language. The intermediate code should be
generated in such a way that you can easily translate it into the target machine code.
Code Optimization: Code optimization is an optional phase. It is used to improve the
intermediate code so that the output of the program could run faster and take less space. It
removes the unnecessary lines of the code and arranges the sequence of statements in
order to speed up the program execution.
Code Generation: Code generation is the final stage of the compilation process. It takes
the optimized intermediate code as input and maps it to the target machine language. Code
generator translates the intermediate code into the machine code of the specified
computer.
8. Enlist types of compilers.= *Cross Compilers. *Bootstrap Compilers. *Source to
source/transcompiler *Decompiler
9. "Symbol table is not required in all phases of compilers". State true or false.
= True. Maintained
= A multi-pass compiler is a type of compiler that processes the source code or abstract
syntax tree of a program several times.
Advantages: It can be played very role useful when optimizing code. Disadvantages: It is a
very Slower process which takes a lot of time to compile the codes.
10. "Symbol table is not required in all phases of compilers". State true or false.
by compilers in order to store information about the occurrence of various entities such as
variable names, function names, objects, classes, interfaces, etc.
11. What is scanner? How the FA in used in scanner? Explain in detail.
= The scanner is a subroutine which is frequently called by an application program like a
compiler. The primary function of a scanner is to combine characters from the input stream
into recognizable units called tokens. 2) A finite automaton (FA) is a simple idealized
machine used to recognize patterns within input taken from some character set (or
alphabet) C. The job of an FA is to accept or reject an input depending on whether the
pattern defined by the FA occurs in the input.
18. Which phase in compiler is used for parsing?
= syntax analysis phase in compiler is used for parsing.
12. What is the need of code optimizationin?
= Optimization is a program transformation technique, which tries to improve the code by
making it consume less resources (i.e. CPU, Memory) and deliver high speed. In
optimization, high-level general programming constructs are replaced by very efficient low-
level programming codes.
13. Define bootstrapping. How to use it?
= bootstrapping is the technique for producing a self-compiling compiler — that is, a
compiler (or assembler) written in the source programming language that it intends to
compile. 2) Step-1: First we write a compiler for a small of C in assembly language. Step-
2: Then using with small subset of C i.e. C0, for the source language c the compiler is
written. Step-3: Finally we compile the second compiler. using compiler 1 the compiler 2 is
compiled. Step-4: Thus we get a compiler written in ASM which compiles C and generates
code in ASM.
16. What is lexical analysis? What is the purpose of lexical analysis phase in
compiler?
= Lexical Analysis is the first phase of the compiler also known as a scanner. It converts the
High level input program into a sequence of Tokens. First step of lex to create lexical
analyser. 2) To convert the input from a simple sequence of characters into a list of tokens
of different kinds, such as numerical and string constants, variable identifiers, and
programming language keywords.
17. Define cross compiler.
= A cross compiler is a compiler capable of creating executable code for a platform other
than the one on which the compiler is running. For example, a compiler that runs on a PC
but generates code that runs on an Android smartphone is a cross compiler.
22. Differentiate between one-pass, multi-pass and cross compilers.
One-Pass Compiler Multi-Pass Compiler
It reads the code only once It reads the code multiple times, each time changing it
and translates it at a similar into numerous forms.
time.
They are faster. They are "slower." As more number of passes means
more execution time.
It is also called a "Narrow It is also called a "wide compiler." As they can scan
compiler." It has limited scope. every portion of the program.
The compiler requires large The memory occupied by one pass can be reused by a
memory. subsequent pass; therefore, small memory is needed by
the compiler.
It is used to build programs for same It is used to build programs for other
system/machine & OS it is installed. system/machine like AVR/ARM.
It can generate executable file like .exe It can generate raw code .hex
20. Define error in compiler. How to handle it in compiler? Explain with example.
= An Error is the blank entries in the symbol table. Errors in the program should be
detected and reported by the parser. Whenever an error occurs, the parser can handle it
and continue to parse the rest of the input. Example: for(;), this will report an error as for
having two semicolons inside braces.
23. Describe data types and data structures in compiler.
= A Data type is one of the forms of a variable to which the value can be assigned of a
given type only. This value can be used throughout the program. A Data structure is a
collection of data of different data types. This collection of data can be represented using
an object and can be used throughout the program.
24. With the help of example describe scope rules.
= The scope rules of this language make the decision that which part of the program a
specific piece of code or data item is accessible. Scope is a source-code level concept, and
a property of name bindings, particularly variable or function name bindings—names in the
source code are references to entities in the program—and is part of the behavior of a
compiler or interpreter of a language. Example: Given a function f(), entities that are
declared in all containing functions or the main program are said global to f().
25. What semantic analysis? Describe in detail.
= semantic analysis is the process of drawing meaning from text. It allows computers to
understand and interpret sentences, paragraphs, or whole documents, by analyzing their
grammatical structure, and identifying relationships between individual words in a particular
context. This helps in extracting important information from achieving human level accuracy
from the computers. Semantic analysis is used in tools like machine translations, chatbots,
search engines and text analytics.
26. What is symbol table? How to manage it?
= Symbol table is an important data structure created and maintained by compilers in order
to store information about the occurrence of various entities such as variable names,
function names, objects, classes, interfaces, etc. Symbol table is used by both the analysis
and the synthesis parts of a compiler. 2) If a compiler is to handle a small amount of data,
then the symbol table can be implemented as an unordered list, which is easy to code, but
it is only suitable for small tables only. A symbol table can be implemented in one of the
following ways: Linear (sorted or unsorted) list. Binary Search Tree.
28. What is parse tree? Explain with example.
= Parse tree is the hierarchical representation of terminals or non-terminals. These symbols
(terminals or non-terminals) represent the derivation of the grammar to yield input strings.
In parsing, the string springs using the beginning symbol. Example: A parse tree or parsing
tree or derivation tree or concrete syntax tree is an ordered, rooted tree that represents the
syntactic structure of a string according to some context-free grammar.
29. Explain the term intermediate code generation in detail.
= Intermediate code can translate the source program into the machine program.
Intermediate code is generated because the compiler can't generate machine code directly
in one pass. Therefore, first, it converts the source program into intermediate code, which
performs efficient generation of machine code further.