Compiler Design: Lecture Notes
Introduction to Compilers & Language Processing Systems
Prepared For: Mantaka Mahir
Institution: Military Institute of Science and Technology (MIST), Dhaka
Source: Classroom Audio Extraction
1. What is a Compiler?
A Compiler is fundamentally a software program that translates a high-level programming language
into a low-level programming language.
• Input: High-Level Language (Source Code) — e.g., C, Java, Python. These languages are human-
readable.
• Output: Low-Level Language (Target Code) — Usually Assembly Language or directly Machine
Code.
2. IDE vs. Compiler
It is crucial to distinguish between a Compiler and an Integrated Development Environment (IDE).
The Classroom Analogy:
Think of the classroom as an IDE. It contains everything needed for teaching and learning: a
whiteboard, projector, AC, desks, and chairs. An IDE similarly provides all the tools a developer
needs (code editor, debugger, file manager) in one unified environment (e.g., Code::Blocks).
The Compiler is just one specific tool attached to the IDE (like MinGW in Code::Blocks). Its sole
job is to translate the code.
3. The Language Processing System
The journey of a high-level C program (e.g., one containing #include <stdio.h>) to executable machine
code (0s and 1s) goes through a complete Language Processing System.
Page 1 of 3
Source Code (High-Level Language)
Preprocessor
Pure High-Level Language
Compiler
Assembly Language
Assembler
Relocatable Machine Code
Linker & Loader
Target Machine Code (Executable)
Detailed Phases of the System:
• Preprocessor: Processes preprocessor directives (like #include <stdio.h>) by fetching the details of
library functions and adding them to the code. It also replaces macros (e.g., #define PI 3.1416) with
their actual values. The output is "Pure" High-Level Language.
• Compiler: Takes the pure high-level language and converts it into Assembly Language (e.g.,
instructions like MOV A, ADD B).
• Assembler: Translates the assembly language into Relocatable Object/Machine Code.
• Linker: Links the relocatable machine code with necessary external library functions.
• Loader: Loads the linked code into the Main Memory (RAM) for execution, finally generating the
absolute executable machine code.
Page 2 of 3
4. Compiler vs. Interpreter
Both are language translators, but they operate differently:
• Compiler: Reads the entire source code at once. If there are any errors, it displays all of them
together after scanning the whole program.
• Interpreter: Translates and executes the code line-by-line.
Note on Java: Java utilizes both a compiler and an interpreter. The Java compiler translates
source code into bytecode, which is then executed line-by-line by the Java Virtual Machine (JVM),
acting as an interpreter.
Page 3 of 3