STAGES IN TRANSLATION TRB CSI › Programming with C++ › stages in translation

STAGES IN TRANSLATION

Translation என்பது programmer high-level programming language-ல் எழுதும் source program-ஐ computer execute செய்யக்கூடிய lower-level / machine-oriented form-ஆக மாற்றும் process. Simple Tamil: நாம் எழுதும் C++ code-ஐ CPU execute செய்யக்கூடிய…

Premium — locked Advanced 25 min 257 cards 27 programs 10 MCQs v3
This is a premium lesson. You can see the shape of every card — unlock to read them. Unlock

STAGES IN TRANSLATION…

Premium This card is part of the premium lesson. Unlock
Definition

Translation என்பது programmer high-level programming language-ல் எழுதும் source program-ஐ computer execute செ……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

Computer இதை direct-ஆக understand செய்யாது. இதன……

Premium This card is part of the premium lesson. Unlock

COMPLETE TRANSLATION FLOW

Explanation

C/C++ program-ன் overall translation flow: Source Program ↓ Preprocessing ↓ Lexical Analysis ↓ Syntax Analysi……

Premium This card is part of the premium lesson. Unlock

TWO WAYS TO UNDERSTAND TRANSLATION STAGES

Explanation

Programming language theory-ல் translation-ஐ இரண்டு levels-ல் படிப்பார்கள். Compiler Internal Phases Lexical ……

Premium This card is part of the premium lesson. Unlock

SOURCE PROGRAM

Definition

Programmer high-level language-ல்……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

File: program.cpp இது source ……

Premium This card is part of the premium lesson. Unlock

STAGE 1 - PREPROCESSING

Explanation

C/C++ translation-ல் compiler proper work ஆரம……

Premium This card is part of the premium lesson. Unlock
Program
Preprocessor handles
Definition
#define

#ifdef #ifndef #if #endif…

Premium This card is part of the premium lesson. Unlock
Definition

1. #include PROCESSING…

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

Conceptually: Required header declaration……

Premium This card is part of the premium lesson. Unlock

MACRO EXPANSION

Explanation
Example

#define PI 3.14 Later:…

Premium This card is part of the premium lesson. Unlock
Explanation

Preprocessor conceptually rep……

Premium This card is part of the premium lesson. Unlock
Explanation

இதனை: Macro Expansion என்று அ……

Premium This card is part of the premium lesson. Unlock

CONDITIONAL COMPILATION

Program
Example
Explanation

Condition அடிப்படையில் source parts include/……

Premium This card is part of the premium lesson. Unlock

STAGE 2 - LEXICAL ANALYSIS

Definition

Source program characters-ஐ meaningful units ஆன tokens-ஆக……

Premium This card is part of the premium lesson. Unlock

LEXICAL ANALYSIS EXAMPLE

Characters: i n t t o t a l = 1 0 0 ; Lexical analyze……

Premium This card is part of the premium lesson. Unlock
Algorithm

1. TOKEN என்றால்?…

Premium This card is part of the premium lesson. Unlock

Programming language-ன் small……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

Tokens: x = a + 10 ;…

Premium This card is part of the premium lesson. Unlock

LEXEME vs TOKEN

Explanation

இந்த difference முக்கியமானது. Lexeme Source program-ல் ac……

Premium This card is part of the premium lesson. Unlock
Program
Another
List

1. LEXICAL ANALYZER என்ன செய்……

Premium This card is part of the premium lesson. Unlock
Explanation

Reads characters ↓ Groups characters ↓ Fo……

Premium This card is part of the premium lesson. Unlock

LEXICAL ERROR

Explanation
Example

Language rules allow செய்யாத invalid character sequence இருந்தால் lexical error ஏற……

Premium This card is part of the premium lesson. Unlock

STAGE 3 - SYNTAX ANALYSIS

Definition

Lexical analyzer கொடுத்த tokens programming language gr……

Premium This card is part of the premium lesson. Unlock

SYNTAX ANALYSIS EXAMPLE

Definition

Tokens: int x = 10 ; Parser checks rule: data_type identifier = expressio……

Premium This card is part of the premium lesson. Unlock

PARSER OUTPUT

Definition

Parser commonly program structure-ஐ: Pars……

Premium This card is part of the premium lesson. Unlock

PARSE TREE EXAMPLE

Definition

Expression: a + b * c Structure: + / ……

Premium This card is part of the premium lesson. Unlock
Definition

1. WHY SYNTAX ANALYSIS?…

Premium This card is part of the premium lesson. Unlock
Definition

Parser check செய்யும்: Parentheses correct-ஆ? Braces correct-ஆ?……

Premium This card is part of the premium lesson. Unlock

SYNTAX ERROR EXAMPLES

Definition

Wrong: if x > 10 { cout 10) {……

Premium This card is part of the premium lesson. Unlock

STAGE 4 - SEMANTIC ANALYSIS

Definition

Program syntax correct என்றாலும் அதன் meaning மற்றும் type-related rules valid-ஆ என்று check செய்வது: Sema……

Premium This card is part of the premium lesson. Unlock

SEMANTIC ANALYSIS EXAMPLE

Definition

int x = "Hello"; Structure: type identifier = value ; syntax-wise co……

Premium This card is part of the premium lesson. Unlock

SEMANTIC CHECKS

Definition

Compiler semantic analyzer check செய்யும்: Variable declared-ஆ? Type compatibility இருக்……

Premium This card is part of the premium lesson. Unlock

UNDECLARED IDENTIFIER

Program
Example
Explanation

If x previously declared இல்ல……

Premium This card is part of the premium lesson. Unlock

FUNCTION ARGUMENT CHECKING

Explanation

Function: int add(int a, int b); Wrong call: add();……

Premium This card is part of the premium lesson. Unlock

SYMBOL TABLE

Explanation

Semantic analysis-க்கு மிகவும……

Premium This card is part of the premium lesson. Unlock
Definition

Identifiers பற்றிய information store ச……

Premium This card is part of the premium lesson. Unlock

SYMBOL TABLE USE

Definition

Compiler encounters: int x; Symbol table: x → int……

Premium This card is part of the premium lesson. Unlock

STAGE 5 - INTERMEDIATE CODE GENERATION

Definition

Source language-க்கும் final machine language-க்கும் நடுவ……

Premium This card is part of the premium lesson. Unlock
Algorithm

1. WHY INTERMEDIATE CODE?…

Premium This card is part of the premium lesson. Unlock
Program
Suppose source

Compiler direct machine code g……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

t1, t2 temporary variables.…

Premium This card is part of the premium lesson. Unlock

THREE-ADDRESS CODE

Explanation

Common intermediate represent……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

Each statement maximum few op……

Premium This card is part of the premium lesson. Unlock

INTERMEDIATE REPRESENTATION ADVANTAGE

Explanation

Front End ↓ Common IR ↓ Back End for x86 Back End for ARM B……

Premium This card is part of the premium lesson. Unlock

FRONT END AND BACK END

Explanation

Compiler often conceptually: Compiler | +-- Front End | +-- Middle End | +-- Back End Front End Lexical A……

Premium This card is part of the premium lesson. Unlock

STAGE 6 - CODE OPTIMIZATION

Definition

Intermediate program-ன் meaning change செய்யாமல் performance / memory / code quali……

Premium This card is part of the premium lesson. Unlock

OPTIMIZATION EXAMPLE

Definition

Original: int x = 5 * 4; Compiler can calculate……

Premium This card is part of the premium lesson. Unlock

CONSTANT FOLDING

Definition

5 * 4 compile time-ல்: 20 ஆக ……

Premium This card is part of the premium lesson. Unlock

CONSTANT PROPAGATION

Explanation
Example

int x = 10; int y = x + 5; Co……

Premium This card is part of the premium lesson. Unlock
Program
therefore
Explanation

Certain situations-ல் optimiz……

Premium This card is part of the premium lesson. Unlock

DEAD CODE ELIMINATION

Explanation

Never execute ஆகாத அல்லது res……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

Compiler optimization அந்த un……

Premium This card is part of the premium lesson. Unlock

COMMON SUBEXPRESSION ELIMINATION

Explanation
Example

a * b + a * b Same calculatio……

Premium This card is part of the premium lesson. Unlock
Explanation

என்று optimize செய்யலாம்.…

Premium This card is part of the premium lesson. Unlock

LOOP OPTIMIZATION

Explanation

Loops repeated execute ஆகும். அதனால் loop optimization performance-க்கு important. Compiler te……

Premium This card is part of the premium lesson. Unlock

OPTIMIZATION IMPORTANT POINT

Explanation

Optimization: Program meaning cha……

Premium This card is part of the premium lesson. Unlock

STAGE 7 - TARGET CODE GENERATION

Definition

Intermediate representation-ஐ target machine instructions / assembly-oriented cod……

Premium This card is part of the premium lesson. Unlock

CODE GENERATOR DECIDES

Definition

Which machine instruction? Which registers? Where valu……

Premium This card is part of the premium lesson. Unlock

REGISTER ALLOCATION

Definition

CPU registers limited. Compiler decide செய்ய வேண்டும்: Which variable ……

Premium This card is part of the premium lesson. Unlock

MACHINE DEPENDENCE

Definition

Earlier stages: Lexical…

Premium This card is part of the premium lesson. Unlock
Explanation
Syntax

Semantic largely source-language dependent. Co……

Premium This card is part of the premium lesson. Unlock

STAGE 8 - ASSEMBLY

Explanation

Compiler assembly code produce செய்தால்: Assembly Code ↓ Ass……

Premium This card is part of the premium lesson. Unlock

OBJECT CODE

Definition

Assembler/compiler generate செய்யும் mach……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

main.cpp ↓ main.o Linux-like s……

Premium This card is part of the premium lesson. Unlock
List

1. OBJECT CODE EXECUTABLE ஆ?…

Premium This card is part of the premium lesson. Unlock
Explanation

Not always. Object file-ல் un……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

Required library implementatio……

Premium This card is part of the premium lesson. Unlock

STAGE 9 - LINKING

Definition

Different object files மற்றும் required lib……

Premium This card is part of the premium lesson. Unlock

LINKING EXAMPLE

Definition

Files: main.cpp math.cpp Compilation: main.cpp → ma……

Premium This card is part of the premium lesson. Unlock

EXTERNAL SYMBOL RESOLUTION

Definition

main.cpp: int add(int, int); int main() { return add(10,20); } math.cpp: int add(int a, int b) { r……

Premium This card is part of the premium lesson. Unlock

STATIC LINKING

Definition

Library code executable-க்குள் incorporate செய்யப்படும். Object Code + Librar……

Premium This card is part of the premium lesson. Unlock

DYNAMIC LINKING

Definition

Required shared library runtime/load time-ல் co……

Premium This card is part of the premium lesson. Unlock

STAGE 10 - LOADING

Definition

Executable program-ஐ storage-ல் இருந்து main memory-க்……

Premium This card is part of the premium lesson. Unlock

LOADING FLOW

Definition

Executable File ↓ Loader ↓ Pr……

Premium This card is part of the premium lesson. Unlock

LOADER RESPONSIBILITIES

Definition

Depending on system: Program memory mapping Address……

Premium This card is part of the premium lesson. Unlock

RELOCATION

Definition

Executable/object code memory-ல் act……

Premium This card is part of the premium lesson. Unlock
Concept

Relative Address ↓ Loader/Lin……

Premium This card is part of the premium lesson. Unlock

STAGE 11 - EXECUTION

Concept

Now program CPU மூலம் execute செய்யப்படும். General ……

Premium This card is part of the premium lesson. Unlock

COMPLETE EXAMPLE - ONE STATEMENT

Concept

Consider: int result = a + b ……

Premium This card is part of the premium lesson. Unlock
Output
result
Program
Structure

Checks: a declared? b declared? Types valid? result type compatible? Intermediate Code t1 = b * 2 t2 = a + t1……

Premium This card is part of the premium lesson. Unlock

COMPILER PHASES - CORE SIX

Traditional compiler theory-ல……

Premium This card is part of the premium lesson. Unlock
Algorithm

1. Lexical Analysis 2. Syntax Analysis 3. Semantic ……

Premium This card is part of the premium lesson. Unlock

இந்த six compulsory நினைவில் ……

Premium This card is part of the premium lesson. Unlock

SUPPORTING ACTIVITIES

Compiler phases முழுவதும் two important activities support செய்கின்றன: Symbol Table……

Premium This card is part of the premium lesson. Unlock

ERROR HANDLING

Different phases detect diffe……

Premium This card is part of the premium lesson. Unlock

LEXICAL ERROR vs SYNTAX ERROR

Lexical Error Token itself invalid. ……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

int, x, =, 10, ; recognizable……

Premium This card is part of the premium lesson. Unlock

SYNTAX ERROR vs SEMANTIC ERROR

Explanation

Syntax error: int x = structure incomplete. Seman……

Premium This card is part of the premium lesson. Unlock

SEMANTIC ERROR vs LOGIC ERROR

Explanation

This is important.…

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

Suppose intended addition. Compiles successfully Runs successfully ……

Premium This card is part of the premium lesson. Unlock

LINKER ERROR

Explanation

Example declaration exists: v……

Premium This card is part of the premium lesson. Unlock
Explanation

But no definition provided. Compilation may ……

Premium This card is part of the premium lesson. Unlock

RUNTIME ERROR

Explanation

Compilation/linking success. Program execution போது error/pro……

Premium This card is part of the premium lesson. Unlock

FRONT END

Explanation

Compiler front end source language understand செய்……

Premium This card is part of the premium lesson. Unlock

MIDDLE END

Focus: Optimization. IR ↓ Analysis ↓ Optimizati……

Premium This card is part of the premium lesson. Unlock

BACK END

Intermediate representation-ஐ target machine code-ஆக transform செய்கிற……

Premium This card is part of the premium lesson. Unlock
Algorithm

1. PASS என்றால் என்ன?…

Premium This card is part of the premium lesson. Unlock

Compiler source/IR-ஐ ஒரு complete traversal செய்து certain work செய்வதை: Pass என்று கூறு……

Premium This card is part of the premium lesson. Unlock

ONE-PASS COMPILER

Advantages: Fast compilation Less intermedi……

Premium This card is part of the premium lesson. Unlock

MULTI-PASS COMPILER

Explanation
Example

Pass 1 → Syntax / Symbols Pass 2 → Semantic Pass 3 → Optimizati……

Premium This card is part of the premium lesson. Unlock

PHASE vs PASS

Explanation

மிக முக்கியமான distinction. Phase Logical compilation task. Examples: Lexical analysis Syntax anal……

Premium This card is part of the premium lesson. Unlock

TRANSLATOR TYPES

Explanation

Programming language translat……

Premium This card is part of the premium lesson. Unlock

COMPILER

Explanation

High-level language source-ஐ target code-……

Premium This card is part of the premium lesson. Unlock

INTERPRETER

Explanation

Program representation-ஐ runtime-ல் directly exec……

Premium This card is part of the premium lesson. Unlock

ASSEMBLER

Explanation

Assembly Language ↓ Assembler……

Premium This card is part of the premium lesson. Unlock

C++ COMPLETE PIPELINE

Explanation

C++ program: hello.cpp ↓ Preprocessor ↓ Compiler Front End ↓ Intermediate Representation……

Premium This card is part of the premium lesson. Unlock
Comparison
Preprocessor vs Compiler
Comparison
Compiler vs Assembler vs Linker vs Loader
Comparison
Lexical vs Syntax vs Semantic Analysis
Important

Compiler core phases: Lexical Analysis ↓ Syntax Analysis ↓ Semantic Analysis ↓ Intermediate Code Generatio……

Premium This card is part of the premium lesson. Unlock
Memory Trick

Compiler six phases: L S S I O C L → Lexical S → Syntax S → Semantic I → Intermediate Code O → Optimization C……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Common error

Do not confuse: Lexical Analyzer ≠ Parser Parser ≠ Semantic Analyzer Compiler ≠ Linker Linker ≠ Loader Object……

Premium This card is part of the premium lesson. Unlock

First major compiler analysis phase:

TRB Point

Answer: Lexical Analysis…

Premium This card is part of the premium lesson. Unlock

Lexical analyzer is called:

TRB Point

Answer: Scanner…

Premium This card is part of the premium lesson. Unlock

Syntax analyzer is called:

TRB Point

Answer: Parser…

Premium This card is part of the premium lesson. Unlock

Parser input:

TRB Point

Answer: Tokens…

Premium This card is part of the premium lesson. Unlock

Type checking occurs mainly during:

TRB Point

Answer: Semantic Analysis…

Premium This card is part of the premium lesson. Unlock

Symbol table contains:

TRB Point

Answer: Information about ide……

Premium This card is part of the premium lesson. Unlock

Three-address code is:

TRB Point

Answer: Intermediate Code…

Premium This card is part of the premium lesson. Unlock

Meaning-preserving code improvement:

TRB Point

Answer: Optimization…

Premium This card is part of the premium lesson. Unlock

Assembly language is translated by:

TRB Point

Answer: Assembler…

Premium This card is part of the premium lesson. Unlock

Object modules are combined by:

TRB Point

Answer: Linker…

Premium This card is part of the premium lesson. Unlock

Executable is placed in memory by:

TRB Point

Answer: Loader…

Premium This card is part of the premium lesson. Unlock
TRB Point

1. Undefined external functio……

Premium This card is part of the premium lesson. Unlock
TRB Point

Answer: Linking…

Premium This card is part of the premium lesson. Unlock
MCQ

Which compiler phase converts……

Premium This card is part of the premium lesson. Unlock
MCQ

The output of lexical analysi……

Premium This card is part of the premium lesson. Unlock
MCQ

Which phase checks grammatica……

Premium This card is part of the premium lesson. Unlock
MCQ

Parser is another name for:…

Premium This card is part of the premium lesson. Unlock
MCQ

Type mismatch is normally det……

Premium This card is part of the premium lesson. Unlock
MCQ

Which data structure stores i……

Premium This card is part of the premium lesson. Unlock
MCQ

Which is an intermediate repr……

Premium This card is part of the premium lesson. Unlock
MCQ

Constant folding is a form of:…

Premium This card is part of the premium lesson. Unlock
MCQ

Which tool combines object fi……

Premium This card is part of the premium lesson. Unlock
MCQ

Which tool loads an executabl……

Premium This card is part of the premium lesson. Unlock
TRB Point
Exam point

2 Marks - Define Translation Translation is the process of converting a source program written in ……

Premium This card is part of the premium lesson. Unlock
TRB Point

1. Lexical Analysis 2. Syntax Analysis 3. Semantic Ana……

Premium This card is part of the premium lesson. Unlock
TRB Point

Add: Symbol Table Management Error Handling as supporting activities. If quest……

Premium This card is part of the premium lesson. Unlock
Summary

Complete picture: C++ Source Program ↓ Preprocessor ↓ Lexical Analyzer Characters → Tokens ↓ Parser Tokens → ……

Premium This card is part of the premium lesson. Unlock
Text size
17px
Theme
Contents
Print / PDF
Program