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 செய்யக்கூடிய…
Translation என்பது programmer high-level programming language-ல் எழுதும் source program-ஐ computer execute செ……
Computer இதை direct-ஆக understand செய்யாது. இதன……
COMPLETE TRANSLATION FLOW
C/C++ program-ன் overall translation flow: Source Program ↓ Preprocessing ↓ Lexical Analysis ↓ Syntax Analysi……
TWO WAYS TO UNDERSTAND TRANSLATION STAGES
Programming language theory-ல் translation-ஐ இரண்டு levels-ல் படிப்பார்கள். Compiler Internal Phases Lexical ……
SOURCE PROGRAM
Programmer high-level language-ல்……
File: program.cpp இது source ……
STAGE 1 - PREPROCESSING
C/C++ translation-ல் compiler proper work ஆரம……
#ifdef #ifndef #if #endif…
1. #include PROCESSING…
Conceptually: Required header declaration……
MACRO EXPANSION
#define PI 3.14 Later:…
Preprocessor conceptually rep……
இதனை: Macro Expansion என்று அ……
CONDITIONAL COMPILATION
Condition அடிப்படையில் source parts include/……
STAGE 2 - LEXICAL ANALYSIS
Source program characters-ஐ meaningful units ஆன tokens-ஆக……
LEXICAL ANALYSIS EXAMPLE
Characters: i n t t o t a l = 1 0 0 ; Lexical analyze……
1. TOKEN என்றால்?…
Programming language-ன் small……
Tokens: x = a + 10 ;…
LEXEME vs TOKEN
இந்த difference முக்கியமானது. Lexeme Source program-ல் ac……
1. LEXICAL ANALYZER என்ன செய்……
Reads characters ↓ Groups characters ↓ Fo……
LEXICAL ERROR
Language rules allow செய்யாத invalid character sequence இருந்தால் lexical error ஏற……
STAGE 3 - SYNTAX ANALYSIS
Lexical analyzer கொடுத்த tokens programming language gr……
SYNTAX ANALYSIS EXAMPLE
Tokens: int x = 10 ; Parser checks rule: data_type identifier = expressio……
PARSER OUTPUT
Parser commonly program structure-ஐ: Pars……
PARSE TREE EXAMPLE
Expression: a + b * c Structure: + / ……
1. WHY SYNTAX ANALYSIS?…
Parser check செய்யும்: Parentheses correct-ஆ? Braces correct-ஆ?……
SYNTAX ERROR EXAMPLES
Wrong: if x > 10 { cout 10) {……
STAGE 4 - SEMANTIC ANALYSIS
Program syntax correct என்றாலும் அதன் meaning மற்றும் type-related rules valid-ஆ என்று check செய்வது: Sema……
SEMANTIC ANALYSIS EXAMPLE
int x = "Hello"; Structure: type identifier = value ; syntax-wise co……
SEMANTIC CHECKS
Compiler semantic analyzer check செய்யும்: Variable declared-ஆ? Type compatibility இருக்……
UNDECLARED IDENTIFIER
If x previously declared இல்ல……
FUNCTION ARGUMENT CHECKING
Function: int add(int a, int b); Wrong call: add();……
SYMBOL TABLE
Semantic analysis-க்கு மிகவும……
Identifiers பற்றிய information store ச……
SYMBOL TABLE USE
Compiler encounters: int x; Symbol table: x → int……
STAGE 5 - INTERMEDIATE CODE GENERATION
Source language-க்கும் final machine language-க்கும் நடுவ……
1. WHY INTERMEDIATE CODE?…
Compiler direct machine code g……
t1, t2 temporary variables.…
THREE-ADDRESS CODE
Common intermediate represent……
Each statement maximum few op……
INTERMEDIATE REPRESENTATION ADVANTAGE
Front End ↓ Common IR ↓ Back End for x86 Back End for ARM B……
FRONT END AND BACK END
Compiler often conceptually: Compiler | +-- Front End | +-- Middle End | +-- Back End Front End Lexical A……
STAGE 6 - CODE OPTIMIZATION
Intermediate program-ன் meaning change செய்யாமல் performance / memory / code quali……
OPTIMIZATION EXAMPLE
Original: int x = 5 * 4; Compiler can calculate……
CONSTANT FOLDING
5 * 4 compile time-ல்: 20 ஆக ……
CONSTANT PROPAGATION
int x = 10; int y = x + 5; Co……
Certain situations-ல் optimiz……
DEAD CODE ELIMINATION
Never execute ஆகாத அல்லது res……
Compiler optimization அந்த un……
COMMON SUBEXPRESSION ELIMINATION
a * b + a * b Same calculatio……
என்று optimize செய்யலாம்.…
LOOP OPTIMIZATION
Loops repeated execute ஆகும். அதனால் loop optimization performance-க்கு important. Compiler te……
OPTIMIZATION IMPORTANT POINT
Optimization: Program meaning cha……
STAGE 7 - TARGET CODE GENERATION
Intermediate representation-ஐ target machine instructions / assembly-oriented cod……
CODE GENERATOR DECIDES
Which machine instruction? Which registers? Where valu……
REGISTER ALLOCATION
CPU registers limited. Compiler decide செய்ய வேண்டும்: Which variable ……
MACHINE DEPENDENCE
Earlier stages: Lexical…
Semantic largely source-language dependent. Co……
STAGE 8 - ASSEMBLY
Compiler assembly code produce செய்தால்: Assembly Code ↓ Ass……
OBJECT CODE
Assembler/compiler generate செய்யும் mach……
main.cpp ↓ main.o Linux-like s……
1. OBJECT CODE EXECUTABLE ஆ?…
Not always. Object file-ல் un……
Required library implementatio……
STAGE 9 - LINKING
Different object files மற்றும் required lib……
LINKING EXAMPLE
Files: main.cpp math.cpp Compilation: main.cpp → ma……
EXTERNAL SYMBOL RESOLUTION
main.cpp: int add(int, int); int main() { return add(10,20); } math.cpp: int add(int a, int b) { r……
STATIC LINKING
Library code executable-க்குள் incorporate செய்யப்படும். Object Code + Librar……
DYNAMIC LINKING
Required shared library runtime/load time-ல் co……
STAGE 10 - LOADING
Executable program-ஐ storage-ல் இருந்து main memory-க்……
LOADING FLOW
Executable File ↓ Loader ↓ Pr……
LOADER RESPONSIBILITIES
Depending on system: Program memory mapping Address……
RELOCATION
Executable/object code memory-ல் act……
Relative Address ↓ Loader/Lin……
STAGE 11 - EXECUTION
Now program CPU மூலம் execute செய்யப்படும். General ……
COMPLETE EXAMPLE - ONE STATEMENT
Consider: int result = a + b ……
Checks: a declared? b declared? Types valid? result type compatible? Intermediate Code t1 = b * 2 t2 = a + t1……
COMPILER PHASES - CORE SIX
Traditional compiler theory-ல……
1. Lexical Analysis 2. Syntax Analysis 3. Semantic ……
இந்த six compulsory நினைவில் ……
SUPPORTING ACTIVITIES
Compiler phases முழுவதும் two important activities support செய்கின்றன: Symbol Table……
ERROR HANDLING
Different phases detect diffe……
LEXICAL ERROR vs SYNTAX ERROR
Lexical Error Token itself invalid. ……
int, x, =, 10, ; recognizable……
SYNTAX ERROR vs SEMANTIC ERROR
Syntax error: int x = structure incomplete. Seman……
SEMANTIC ERROR vs LOGIC ERROR
This is important.…
Suppose intended addition. Compiles successfully Runs successfully ……
LINKER ERROR
Example declaration exists: v……
But no definition provided. Compilation may ……
RUNTIME ERROR
Compilation/linking success. Program execution போது error/pro……
FRONT END
Compiler front end source language understand செய்……
MIDDLE END
Focus: Optimization. IR ↓ Analysis ↓ Optimizati……
BACK END
Intermediate representation-ஐ target machine code-ஆக transform செய்கிற……
1. PASS என்றால் என்ன?…
Compiler source/IR-ஐ ஒரு complete traversal செய்து certain work செய்வதை: Pass என்று கூறு……
ONE-PASS COMPILER
Advantages: Fast compilation Less intermedi……
MULTI-PASS COMPILER
Pass 1 → Syntax / Symbols Pass 2 → Semantic Pass 3 → Optimizati……
PHASE vs PASS
மிக முக்கியமான distinction. Phase Logical compilation task. Examples: Lexical analysis Syntax anal……
TRANSLATOR TYPES
Programming language translat……
COMPILER
High-level language source-ஐ target code-……
INTERPRETER
Program representation-ஐ runtime-ல் directly exec……
ASSEMBLER
Assembly Language ↓ Assembler……
C++ COMPLETE PIPELINE
C++ program: hello.cpp ↓ Preprocessor ↓ Compiler Front End ↓ Intermediate Representation……
Compiler core phases: Lexical Analysis ↓ Syntax Analysis ↓ Semantic Analysis ↓ Intermediate Code Generatio……
Compiler six phases: L S S I O C L → Lexical S → Syntax S → Semantic I → Intermediate Code O → Optimization C……
Do not confuse: Lexical Analyzer ≠ Parser Parser ≠ Semantic Analyzer Compiler ≠ Linker Linker ≠ Loader Object……
First major compiler analysis phase:
Answer: Lexical Analysis…
Lexical analyzer is called:
Answer: Scanner…
Syntax analyzer is called:
Answer: Parser…
Parser input:
Answer: Tokens…
Type checking occurs mainly during:
Answer: Semantic Analysis…
Symbol table contains:
Answer: Information about ide……
Three-address code is:
Answer: Intermediate Code…
Meaning-preserving code improvement:
Answer: Optimization…
Assembly language is translated by:
Answer: Assembler…
Object modules are combined by:
Answer: Linker…
Executable is placed in memory by:
Answer: Loader…
1. Undefined external functio……
Answer: Linking…
Which compiler phase converts……
The output of lexical analysi……
Which phase checks grammatica……
Parser is another name for:…
Type mismatch is normally det……
Which data structure stores i……
Which is an intermediate repr……
Constant folding is a form of:…
Which tool combines object fi……
Which tool loads an executabl……
2 Marks - Define Translation Translation is the process of converting a source program written in ……
1. Lexical Analysis 2. Syntax Analysis 3. Semantic Ana……
Add: Symbol Table Management Error Handling as supporting activities. If quest……
Complete picture: C++ Source Program ↓ Preprocessor ↓ Lexical Analyzer Characters → Tokens ↓ Parser Tokens → ……