Structure of Compiler: A compiler takes input as source program and produce as output an equivalence sequence of machine instructions.
The compilation process is divided into a series of sub process called phases. A phase is a logically cohesive operation that take as input one representation of source program and produce as output i.e; target program in other representation.
Phases of Compilation:
- First Phase: lexical analyzer or scanner seperate character of source language into a group of logically belong to each other. These group are called as tokens. The usual tokens are keywords such as do or if, identifiers such as a or b, operator symbol as = + < > and punctuation symbol as () and comma. The output is a stream of tokens pass to the rest of phases.
- Second Phase: the syntax analyzer or parser group tokens together into syntactic structure for example 3 tokens as A+B group together into syntactic structure as expression . expression might further be combined into statement. We form a tree who's leaf are tokens, an interior node represent string of token that logically belong together. for example : the statement - if(5 equ max) goto 100 has 8 tokens.
- Third Phase: intermediate code generator use the structure produced by syntax analyzer to create a stream of simple instructions. Different style we are using like MACROS.
- Fourth Phase: code optimization is an optional phase design to improve the intermediate code so that object prog run faster and take less space. Its output is also intermediate code but it saves time.
- Fifth Phase: the final phase at code generation produce the object code by deciding on memory location for data, selecting code and selecting register in which each computation done.
The table management or book keeping keep track of the name and record and all the essential information about each of the data type. The data structure which is used to record the information called the symbol table.
No comments:
Post a Comment