1 / 31

Front End vs Back End of a Compilers

Front End vs Back End of a Compilers. The phases of a compiler are collected into front end and back end.

hopkinsm
Download Presentation

Front End vs Back End of a Compilers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Front End vs Back End of a Compilers • The phases of a compiler are collected into front end and back end. • The front end consists of those phases that depend primarily on the source program.These normally include Lexical and Syntactic analysis,Semantic analysis ,and the generation of intermediate code

  2. Front End vs Back End of a Compilers(Cont’d) • A certain amount of code optimization can be done by front end as well.

  3. Front End vs Back End of a Compilers(Cont’d) • The BACK END includes the code optimization phase and final code generation phase,along with the necessary error handling and symbol table operations.

  4. Front End vs Back End of a Compilers(Cont’d) • The front end analyzes the source program and produces intermediate code while the back end synthesizes the target program from the intermediate code. • A naive approach (front force) to that front end might run the phases serially

  5. Front End vs Back End of a Compilers(Cont’d) • It is also tempting to compile several different languages into the same intermediate language and use a common back end for the different front ends, thereby obtaining several compilers for one machine. • However, because of subtledifference in the view points of different language, there has been only limited success in this direction.

  6. Passes • In an implementation of a complier, portion of one or more phases are combined into a module called a pass

  7. Passes(cont’d) • Several phases of complier are usually implemented in a single pass consisting of reading an input file and writing as output file. • It is common for several phases to be grouped into one pass and for the activity of these phases to be interleaved during the pass

  8. Passes(cont’d) • For example lexical analysis ,syntax analysis, semantic analysis and intermediate code generation might be grouped into one pass. • If so, the token stream after lexical analysis may be translated directly into intermediate code.

  9. Passes(cont’d) • A pass reads the source program or out put of the previous pass make the transformation specified by its phases and writes output into an intermediate file , which may then be read by a subsequent pass.

  10. Multi Pass Compiler • A multi pass compiler can be made a useless space than a single pass compiler. • Since the space occupied by the compiler program for one pass can be reused by the following pass.

  11. Multi Pass Compiler(cont’d) • A multi pass complier is of the course slower than a single pass compiler, because each pass reads and writes an intermediate file .

  12. Multi Pass Compiler(cont’d) • Thus compiler running in computers with small memory would normally use several passes while on a computer with a large random memory , a compiler with fewer passes would be possible.

  13. Compiler Construction Tools • A number of tools have been developed specifically to held construct compilers.These tools variously called compiler-compilers,compiler-generators, or translator-writing systems,which produce a compiler from some form of specification of a source language and target m/c language.

  14. Compiler Construction Tools(cont’d) • Largely ,they are oriented around a particular model of languages and they are most suitable for generating compilers of languages similar to the model.

  15. Compiler Construction Tools(cont’d) • For example , it is tempting to assume that lexical analyzers for all languages are essentially the same,except for the particular key words and signs recognized.

  16. Compiler Construction Tools(cont’d) • Many compiler-compilers do in fact produce fixed lexical analysis routines for use in the generated compiler.

  17. Compiler Construction Tools(cont’d) • These routines differ only in the list of key words recognized ,and this list is all that needs to be supplied by the user.The approach is valid, but may be unworkable if it is required to recognize nonstandard tokens,such as identifiers that may include certain character other than letters and digits.

  18. Compiler Construction Tools(cont’d) • Some general tools have been created for the automatic design of specific compiler components. • These tools use specialized languages for specifying and implementing the component ,and many use algorithms that are quite sophisticated.

  19. Compiler Construction Tools(cont’d) • The most successful tools are those that hide the details of the generation algorithm and produce components that can be easily integrated into the remainder of a compiler

  20. Compiler Construction Tools(cont’d) The following is a list of some useful compiler construction tools. • Parser Generators • Scanner Generators • Syntax-directed translation Engines • Automatic Code Generators • Data Flow Engines

  21. Parser Generators • These produce syntax analyzers ,normally from input that is based on a context free grammar.In early compilers,syntax analysis consumed not only a large fraction of the running time of a compiler but a large fraction of the intellectual effort of writing a compiler.

  22. Parser Generators(cont’d) • This phase is now considered one of the easiest to implement. • Many parser generators utilize powerful parsing algorithms that are too complex to be carried out by hand.

  23. Scanner Generators • These automatically generate lexical analyzer normally from a specification based on regular expressions.

  24. Syntax Directed Translation Engine • These produce collections of routines that walk the parse tree ,generating intermediate cods.

  25. Automatic Code Generators • Such a tool takes a collection of rules that defines the translation of each operation of the intermediate language into the m/c for the target machine.

  26. Automatic Code Generators(cont’d) • The rules must include sufficient detail that we can handle the different possible access methods for data e.g. variables may be in registers or a fixed (static)location in memory or may be allocated a position on a stack.

  27. Data Flow Engines. • Much of the information needed to perform good code optimization involves “data flow analysis “ the gathering of information about how values are transmitted from one part of the programme to each part.

  28. The Phases Of Compiler

  29. Lexical Analyzer Syntax Analyzer Source Program Symbol Table Error Handler Manager Target Program Semantic Analyzer Intermediate Code Generator Code Optimizer Code Generator

  30. A Compiler operates in phases ,each of which transforms the source programme from one representation to another. • In practice,some of the phases may be grouped together. • The first three phases ,forming the bulk of the analysis portion of a compiler

  31. Two other activities , symbol table management and error handling,are shown interacting with the six phases of lexical analysis, syntax analysis,semantic analysis,intermediate code generation,code optimization,and code generation. • Informally,we shall also call the symbol table manager and error handler Phases.

More Related