Unit 1 Introduction: Cocsc14 Harshita Sharma
Unit 1 Introduction: Cocsc14 Harshita Sharma
Harshita Sharma
OVERVIEW
Language processors
The compilation process
Types of compilers
compiler-construction tools
applications of compiler technology
Transition diagrams
Bootstrapping
just-in-time compilation.
LANGUAGE PROCESSORS
DEFINITION AND PURPOSE
Language processors are essential software tools that facilitate the
translation of human-readable source code into machine-
executable code or perform various language-related tasks.
They play a crucial role in bridging the gap between human
understanding and machine processing.
CATEGORIES
Program Translations
Binary translation, Hardware synthesis, Database Query Interpreters, Compiled Simulation
Translates program for same hardware/platform/machine on it is Translates program for different hardware/platform/machine other
running. than the platform which it is running.
It can generate executable file like .exe It can generate raw code .hex
Generates machine code for the same platform it’s running on. Generates machine code for a different platform than it’s running on.
Used for development and testing on the same system. Used for cross-platform development, porting, and cross-compiling.
Advantage:- Advantage:-
Typically faster and more efficient than cross compilers. Enables developers to compile code for multiple platforms.
Disadvantage:- Disadvantage:-
Cannot be used for cross-platform development Can be slower and less efficient than native compilers.
BOOTSTRAPPING
Bootstrapping is a process in which simple language is used to translate more
complicated program which in turn may handle for more complicated program. This
complicated program can further handle even more complicated program and so on.
Writing a compiler for any high level language is a complicated process. It takes lot
of time to write a compiler from scratch. Hence simple language is used to generate
target code in some stages.
Bootstrapping is a common practice in compiler development and has been used to
create many well-known compilers, such as GCC (GNU Compiler Collection). It
showcases the power of using a simple tool to create more advanced and capable
software, leading to a self-sustaining cycle of improvement.
to clearly understand the Bootstrapping technique consider a following scenario.
Suppose we want to write a cross compiler for new language X.
The implementation language of this compiler is say Y and the target code being
generated is in language Z. That is, we create XYZ.
Now if existing compiler Y runs on machine M and generates code for M then it is
denoted as YMM. Now if we run XYZ using YMM then we get a compiler XMZ.
That means a compiler for source language X that generates a target code in
language Z and which runs on machine M.
EXAMPLE
Compiler which takes C language and generates an assembly language as an output
with the availability of a machine of assembly language.
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.
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.
Bootstrapping is the process of writing a compiler for a programming language using
the language itself. In other words, it is the process of using a compiler written in a
particular programming language to compile a new version of the compiler written in
the same language.
ADVANTAGES
1. it ensures that the compiler is compatible with the language it is designed to
compile. This is because the compiler is written in the same language, so it is better
able to understand and interpret the syntax and semantics of the language.
2. it allows for greater control over the optimization and code generation process.
Since the compiler is written in the target language, it can be optimized to
generate code that is more efficient and better suited to the target platform.
DISADVATAGES
However, bootstrapping also has some disadvantages.
One disadvantage is that it can be a time-consuming process, especially for complex
languages or compilers.
It can also be more difficult to debug a bootstrapped compiler, since any errors or
bugs in the compiler will affect the subsequent versions of the compiler.