preview

Explain the Different Phases of Compiler with a Neat Diagram.

Good Essays

A compiler takes as input a source program and produces as output an equivalent sequence of machine instructions. This process is so complex that it is divided into a series of sub-processes called phases. 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. The usual tokens are identifiers, keywords, constants, operators and punctuation symbols such as comma and parenthesis. Each token is a sub-string of the source program that is to be treated as a single unit. The Lexical analyzer examines successive …show more content…

This aspect of code generation, called register allocation, is particularly difficult to do optimally, but some heuristic approaches can give reasonably good results. Designing a code generator that produces truly efficient object programs is one of the most difficult parts of a compiler design. During all these phases of the compiler, they are being interacted upon by the following two important data structures: Table Management or Book-Keeping A compiler needs to collect information about all the data objects that appear in the source program. The information about data objects is collected by the early phases of the compiler – lexical and syntactic analyzers. The data structure used to record this information is called as symbol table. 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. It can be done during the syntactic analysis phase, the intermediate code generation phase or in the final code generation phase. Error Handling One of the most important functions of a compiler is the detection and reporting of errors in the source program. The error messages should allow the programmer to determine exactly where the errors have occurred. Errors may occur in all of the phases of a compiler. Whenever a phase of the compiler discovers an error, it must report the error to the dhandler, which

Get Access