NBC 101 • Unit 317 min readVery High Exam Frequency

Language Translators: Compilers, Interpreters, Assemblers, Linkers & Loaders

Unit 3: Computer Software, Translators & Operating SystemsFundamentals of Computer

👨‍🏫 Professor's Mental Model: Book Publisher vs Live Diplomatic Interpreter

Compiler ek professional book publisher jaisa hai jo poori English kitaab (Source Code) ko ek hi baar me padhta hai, saare grammatical errors ki list deta hai, aur poori printed Hindi book (.exe binary) bana deta hai. Interpreter ek live court translator jaisa hai jo speaker ka ek-ek sentence sunta hai aur turant translate karke execute karta hai. Agar kisi line me syntax error ho toh Interpreter wahi ruk jata hai!

The 6-Stage C/C++ Compilation & Execution Pipeline

Click any stage in the pipeline below to inspect input/output files, translator tools, and intermediate code transformations.

Guaranteed 10/15-Mark Exam Architecture
Stage 3: Compilation (6 Phases)Tool: Compiler (e.g., gcc / clang)
Assembly Generation

Performs Lexical Analysis (tokens) -> Syntax Analysis (Parse Tree) -> Semantic Analysis (type checking) -> Optimization -> Generates CPU-specific Assembly code.

Input File:Expanded Source (.i)
Output File Generated:Assembly Language File (.s)
Code State at Stage 3 (Compilation (6 Phases)):
.LC0:
    .string "Hello, BCA Developers!"
main:
    pushq   %rbp
    movq    %rsp, %rbp
    leaq    .LC0(%rip), %rax
    movq    %rax, %rdi
    call    puts
    movl    $0, %eax
    popq    %rbp
    ret

1. The 3 Types of Language Translators

CPU can only execute pure binary machine code (0s and 1s). Translators convert human-written code into machine code: • Assembler: Translates low-level Assembly mnemonics (MOV, ADD, JMP, SUB) into binary machine code. • Compiler: Translates entire High-Level source code (C, C++, Java) into machine code in one pass, producing a standalone `.exe` object file. • Interpreter: Translates and executes High-Level code (Python, JavaScript, Ruby) line-by-line in memory without generating an intermediate object file.

2. The 6 Compilation Phases In-Depth

1. Lexical Analysis (Scanner): Converts raw character streams into meaningful tokens (Keywords, Identifiers, Operators, Literals). Strips whitespace and comments. 2. Syntax Analysis (Parser): Verifies grammatical rules using Context-Free Grammars and constructs the hierarchical Parse Tree (Abstract Syntax Tree). 3. Semantic Analysis: Checks type compatibility, variable declarations, and array bounds (Type Checking). 4. Intermediate Code Generation (ICG): Generates machine-independent intermediate code (e.g., Three-Address Code - TAC). 5. Code Optimization: Eliminates dead code, optimizes loops, and removes redundant computations to maximize CPU execution speed. 6. Target Code Generation: Emits final CPU-specific Assembly / Machine Opcodes.

3. Linker vs Loader Roles in Program Execution

• Linker (Static & Dynamic): A program that takes one or more compiled object files (`.o` / `.obj`) and library archive binaries (e.g. `libc.a`, `math.h`), resolves cross-file external symbol references, and packages them into a single standalone executable (`.exe` / `a.out`). • Loader: The operating system module that loads the executable file from secondary disk into primary RAM, allocates heap and stack address spaces, binds dynamic library DLLs, initializes CPU registers (Program Counter = Entry Point), and kicks off CPU execution!
Master 8-Parameter Comparison: Compiler vs Interpreter
ParameterCompilerInterpreter
Translation ModeTranslates entire source program in ONE single passTranslates and executes source code LINE-BY-LINE
Executable FileGenerates permanent standalone executable (.exe / .out)No executable binary generated (Executed directly in RAM)
Execution SpeedMuch Faster (Pre-compiled native machine code)Slower (Translation overhead during runtime)
Error ReportingReports all syntax errors together after full compilationStops execution immediately at the first encountered error
Memory RequirementRequires more memory during compilation phaseRequires less memory (Lightweight runtime)
Debugging DifficultyDifficult (Must recompile whole project after fixes)Easier (Interactive line-by-line debugging)
Source Code PrivacySource code is hidden; only compiled binary is distributedSource code must be distributed to the client machine
Example LanguagesC, C++, Rust, Go, FortranPython, JavaScript, Ruby, PHP, Perl

🎯 University Exam Scoring Blueprint

  • Draw the complete 6-Stage Compilation Pipeline diagram (Source -> Preprocessor -> Compiler -> Assembler -> Linker -> Loader -> RAM).
  • Write the master 8-parameter table comparing Compiler vs Interpreter.
  • Explain the difference between a Linker and a Loader in 4 marks.

Top Viva Questions on Language Translators: Compilers, Interpreters, Assemblers, Linkers & Loaders

1 Questions
1

What is the difference between an Object File (.obj) and an Executable File (.exe)?