Structure & Types of Compiler

780 views
737 views

Published on

If this content is helpful to you then don't forget to like, share and comment.

Facebook: www.facebook.com/pran93

Published in: Engineering
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
780
On SlideShare
0
From Embeds
0
Number of Embeds
15
Actions
Shares
0
Downloads
59
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Structure & Types of Compiler

  1. 1. Structure & Types of Compiler
  2. 2. Structure of a Compiler Any large software is easier to understand and implement if it is divided into well-defined modules.
  3. 3. The structure of a compiler
  4. 4.  In a compiler, o Linear analysis  Is called LEXICAL ANALYSIS or SCANNING and  Is performed by the LEXICAL ANALYZER or LEXER, o Hierarchical analysis  Is called SYNTAX ANALYSIS or PARSING and  Is performed by the SYNTAX ANALYZER or PARSER.  During the analysis, the compiler manages a SYMBOL TABLE by o Recording the identifiers of the source program o Collecting information (called ATTRIBUTES) about them: storage allocation, type, scope, and (for functions) signature.
  5. 5.  When the identifier x is found by the lexical analyzer o Generates the token id o Enters the lexeme x in the symbol-table (if it is not already there) o Associates to the generated token a pointer to the symbol-table entry x. This pointer is called the LEXICAL VALUE of the token.  During the analysis or synthesis, the compiler may DETECT ERRORS and report on them. o However, after detecting an error, the compilation should precede allowing further errors to be detected. o The syntax and semantic phases usually handle a large fraction of the errors detectable by the compiler.
  6. 6. Types of Compiler 1. One-pass compiler : In computer programming, a one-pass compiler is a compiler that passes through the parts of each compilation unit only once, immediately translating each part into its final machine code. This is in contrast to a multi-pass compiler which converts the program into one or more intermediate representations steps in between source code and machine code, and which reprocesses the entire compilation unit in each sequential pass.
  7. 7. 2. Multi-pass compiler : A multi-pass compiler is a type of compiler that processes the source code or abstract syntax tree of a program several times. This is in contrast to a one-pass compiler, which traverses the program only once. Each pass takes the result of the previous pass as the input, and creates an intermediate output. In this way, the (intermediate) code is improved pass by pass, until the final pass emits the final code. Multi-pass compilers are sometimes called wide compilers referring to the greater scope of the passes: they can "see" the entire program being compiled, instead of just a small portion of it. The wider scope thus available to these compilers allows better code generation (e.g. smaller code size, faster code) compared to the output of one-pass compilers, at the cost of higher compiler time and memory consumption. In addition, some languages cannot be compiled in a single pass, as a result of their design.
  8. 8. 3. Cross compiler : A cross compiler is a compiler capable of creating executable code for a platform other than the one on which the compiler is running. Cross compiler tools are used to generate executable for embedded system or multiple platforms. It is used to compile for a platform upon which it is not feasible to do the compiling, like microcontrollers that don't support an operating system. It has become more common to use this tool for paravirtualization where a system may have one or more platforms in use. 4. Stage compiler : Stage compiler that compiles to assembly language of a theoretical machine, like some Prolog implementations. This Prolog machine is also known as the Warren abstract machine (or WAM). Byte-code compilers for Java, Python (and many more) are also a subtype of this.
  9. 9. 5. Source-to-source compiler : A source-to-source compiler, transcompiler, or transpiler is a type of compiler that takes the source code of a programming language as its input and outputs the source code into another programming language. A source-to-source compiler translates between programming languages that operate at approximately the same level of abstraction, while a traditional compiler translates from a higher level programming language to a lower level programming language. For example, a source-to-source compiler may perform a translation of a program from Pascal to C. An automatic parallelizing compiler will frequently take in a high level language program as an input and then transform the code and annotate it with parallel code annotations (e.g. OpenMP) or language constructs (e.g. Fortran's for all statements).
  10. 10. 6. Just-In-Time compiler : In computing, just-in-time compilation (JIT), also known as dynamic translation, is compilation done during execution of a program – at run time – rather than prior to execution. Most often this refers to translation to machine code, which is then executed directly, but can also refer to translation to another format. JIT compilation is a combination of the two traditional approaches to translation to machine code – ahead of time compilation (AOT), and interpretation – and combines some advantages and drawbacks of both. Roughly, JIT compilation combines the speed of compiled code with the flexibility of interpretation, with the overhead of an interpreter and the additional overhead of compiling (not just interpreting). JIT compilation is a form of dynamic compilation, and allows adaptive optimization such as dynamic recompilation – thus in principle JIT compilation can yield faster execution than static compilation. Interpretation and JIT compilation are particularly suited for dynamic programming languages, as the runtime system can handle late-bound data types and enforce security guarantees.

×