GAJJELASRAVANTHIGAJJ
25 views
40 slides
Aug 08, 2024
Slide 1 of 40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
About This Presentation
Compiler design ppt
Size: 5.53 MB
Language: en
Added: Aug 08, 2024
Slides: 40 pages
Slide Content
Programming Language • Notations describing computational concepts • It is a software running on computer • It requires translation to run on computers • This translation is done by the compilers • Compiler is the main software under language processor INTRODUCTION TO COMPILER
• Supporting/Interlinked software to do translation process is Language Processor • It is a software program that helps for the translation of the source code to the machine code Types of Language Processor Compiler • Converts complete source program to object program Interpreter • Converts source program to object program line by line Assembler Converts source program in assembly level instructions to object code LANGUAGE PROCESSOR
COMPILER • Compiler is a software/program that read the program in one language called source code and translates it into an object code Characteristics • Converts entire source program at a time • Detects all syntax errors at a time • Requires huge memory space for processing • Executes very fast INTERPRETER • Interpreter is a software that translates the source program in HLL to object code(machine level language) line by line Characteristics • It is the simplest form of translation • Line by Line translation • Detects only one error at a time • Requires less memory space • Slow in execution
ASSEMBLER • Assembler is a software that converts low level/assembly language to machine code • The object code is meant for specific hardware only, not easily transferable from one file to another file Characteristics • Instructions will be in mnemonics codes • Produces object code as output • Object code is hardware specific
ASSEMBLER COMPILER 1. Translates source code in assembly language to machine language Translates source code in High level language to machine language 2. Slow execution 2. Executes very fast 3. Less sophisticated program 3. More sophisticated program 4. Instructions will be in mnemonic codes 4. High level programming instructions 5. The object code need to be linked to run on a machine 5. Compilers produce machine executable code directly from HLL
Compiler Design
Compiler Design
Compiler Design
Compiler design
Context free grammar
Context free grammar
Lexical Analyzer
Lexical Analyzer
Lexical Analyzer
Lexical Analyzer
Lexical Analyzer
Lexical Analyzer
Lexical Analyzer
Lexical Analyzer
Compiler Passes One-pass Compiler If we combine or group all the phases of compiler design in a single module known as a single pass compiler. One-pass compiler is used to traverse the program only once. The one-pass compiler passes only once through the parts of each compilation unit. It translates each part into its final machine code. In the one pass compiler, when the line source is processed, it is scanned and the token is extracted. Then the syntax of each line is analyzed and the tree structure is build. After the semantic part, the code is generated. The same process is repeated for each line of code until the entire program is compiled. Pass is a complete traversal of the source program. Compiler has two passes to traverse the source program.
Compiler Passes Multi-pass Compiler Multi pass compiler is used to process the source code of a program several times. In the first pass, compiler can read the source program, scan it, extract the tokens and store the result in an output file. In the second pass, compiler can read the output file produced by first pass, build the syntactic tree and perform the syntactical analysis. The output of this phase is a file that contains the syntactical tree. In the third pass, compiler can read the output file produced by second pass and check that the tree follows the rules of language or not. The output of semantic analysis phase is the annotated tree syntax. This pass is going on, until the target output is produced.
One-pass Compiler
One-Pass Compiler Multi-Pass Compiler It reads the code only once and translates it at a similar time. It reads the code multiple times, each time changing it into numerous forms. They are faster. They are "slower." As more number of passes means more execution time. Less efficient code optimization and code generation. Better code optimization and code generation. It is also called a "Narrow compiler." It has limited scope. It is also called a "wide compiler." As they can scan every portion of the program. The compiler requires large memory. The memory occupied by one pass can be reused by a subsequent pass; therefore, small memory is needed by the compiler. Example − Pascal & C languages use one-pass compilation. Example − Modula -2 languages use multi-pass compilation.
One-pass Compiler One pass Two-pass It performs Translation in one pass It performs Translation in two pass It scans the entire file only once. It requires two passes to scan the source file. It generates Intermediate code It does not generate Intermediate code It is faster than two pass assemble r It is slower than two pass assembler A loader is not required A loader is required. No object program is written. A loader is required as the object code is generated. Perform some professing of assembler directives. Perform processing of assembler directives not done in pass-1 The data structure used are: The symbol table , literal table, pool table, and table of incomplete. The data structure used are: The symbol table, literal table, and pool table. These assemblers perform the whole conversion of assembly code to machine code in one go. These assemblers first process the assembly code and store values in the opcode table and symbol table and then in the second step they generate the machine code using these tables. Example: C and Pascal uses One Pass Compiler. Example: Modula-2 uses Multi Pass Compiler.