Explain the different phases of compiler with a neat diagram

Semantic Analysis Semantic analysis is the third phase of compilation process.

phases of compiler design pdf

The target language is the machine code. Usually, the code is made shorter and simpler by combining steps or removing unnecessary steps which lead to the generation of optimized code.

grouping of phases in compiler design

The parser has two functions: i Firstly, it checks if the tokens from lexical analyzer, occur in pattern that are permitted by the specification for the source language. The determination of the type of intermediate results and check to check for, if the type of the arguments is legal for the application of an operation is termed as semantic analysis.

Each phase takes source program in one representation and produces output in another representation. This aspect of code generation, called register allocation, is particularly difficult to do optimally, but some heuristic approaches can give reasonably good results.

Explain the different phases of compiler with a neat diagram

It is in between the high-level language and the machine language. Also, the semantic analyzer keeps track of identifiers, their types and expressions; whether identifiers are declared before use or not etc. Proceed Each token is a sub-string of the source program that is to be treated as a single unit. Usually, the code is made shorter and simpler by combining steps or removing unnecessary steps which lead to the generation of optimized code. The output is dependent on the type of assembler. It constructs the parse tree. It represents a program for some abstract machine. Syntax Analysis Syntax analysis is the second phase of compilation process. Each phase takes input from its previous stage, has its own representation of source program, and feeds its output to the next phase of the compiler. The different phases of the compiler are as follows: Phase 1: Lexical Analyzer or Scanner The first phase of the compiler, called Lexical Analyzer or Scanner reads the source program one character at a time, carving the source program into a sequence of atomic units called tokens. If the language permits some type conversions called type coercions, then the semantic analyzer does this job as well. It makes the entry of the corresponding token into the symbol table and passes on the tokens to the next phase, syntax analyzer. Each phase takes source program in one representation and produces output in another representation. It helps the compiler to function smoothly by finding the identifiers quickly. The intermediate code should be generated in such a way that you can easily translate it into the target machine code.

Code Generator This phase finally coverts the intermediate code or the optimized code into the target language. The output is dependent on the type of assembler.

Phases of compiler example

The symbol table makes it easier for the compiler to quickly search the identifier record and retrieve it. Summary Compiler operates in various phases each phase transforms the source program from one representation to another Six phases of compiler design are 1 Lexical analysis 2 Syntax analysis 3 Semantic analysis 4 Intermediate code generator 5 Code optimizer 6 Code Generator Lexical Analysis is the first phase when compiler scans the source code Syntax analysis is all about discovering structure in text Semantic analysis checks the semantic consistency of the code Once the semantic analysis phase is over the compiler, generate intermediate code for the target machine Code optimization phase removes unnecessary code line and arranges the sequence of statements Code generation phase gets inputs from code optimization phase and produces the page code or object code as a result A symbol table contains a record for each identifier with fields for the attributes of the identifier Error handling routine handles error and reports during many phases. Intermediate code is generated between the high-level language and the machine language. The basic purpose of generating this code is ease of translation to machine code and hence it resembles assembly language code greatly. Phase 4: Code Optimization The fourth phase of the compiler, called Code Optimization is an optional phase designed to improve the intermediate code so that the ultimate object program runs faster or takes less space. Code generator translates the intermediate code into the machine code of the specified computer. Lexical Analyzer The lexical analyzer phase reads the character stream from the source program and groups them into meaningful sequences by identifying the tokens. Error Handling One of the most important functions of a compiler is the detection and reporting of errors in the source program.

Whenever a phase of the compiler discovers an error, it must report the error to the dhandler, which issues an appropriate diagnostic message. Intermediate code is converted to machine language using the last two phases which are platform dependent.

phases of compiler ppt
Rated 8/10 based on 50 review
Download
Phases of Compiler