Compiler
Translators     A program which converts a user’s program     written in some language to another     language.     The la...
TranslatorsThere is an important difference betweentranslation and interpretation. In the former,the original program is f...
Translators translation comprises of two steps i.e    Generation of an equivalent program in    target language    Executi...
Translators5/1/2006   Computer System Software CS 012 BE 7th Semester   5
Translators5/1/2006   Computer System Software CS 012 BE 7th Semester   6
Translators5/1/2006   Computer System Software CS 012 BE 7th Semester   7
Phases in a compiler     Lexical analysis     Syntactic analysis     Semantic analysis     Intermediate code generation   ...
Compiler  Compiler (Front - End )  Largely dependent on the source language  Independent of the target machine Comprises t...
Compiler     Back-End     Dependent on the target machine     Independent of the source language     Includes the last two...
Lexical Analysis     Scans the source program into basic     elements called tokens     Prepares the symbol table which   ...
Lexical AnalysisEXAMPLE:IF ( x < 5.0 ) THEN x=x+2 ELSE x=x-3;TOKENS:Keywords : IF, THEN, ELSEIdentifier(s) : xConstants : ...
Syntax Analysis Syntax analysis is also known as parsing or   hierarchical analysis.   It basically involves grouping of t...
5/1/2006   Computer System Software CS 012 BE 7th Semester   14
Syntax Analysis     there are tools to generate parsers. For     e.g. in Unix systems, a tool called as     YACC (Yet Anot...
Semantic Analysis   Looks into the static meaning of the program   Gathers type information for the subsequent   code gene...
Intermediate Code Generation     Some compilers generate an explicit     intermediate representation of the source     pro...
Next Session Compilers -: Code optimization Code Generation5/1/2006   Computer System Software CS 012 BE 7th Semester   18
Upcoming SlideShare
Loading in...5
×

3ss

182

Published on

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

  • Be the first to like this

No Downloads
Views
Total Views
182
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

3ss

  1. 1. Compiler
  2. 2. Translators A program which converts a user’s program written in some language to another language. The language in which the user’s program is written is called the source language The language to which the source language is converted is called the target language5/1/2006 Computer System Software CS 012 BE 7th Semester 2
  3. 3. TranslatorsThere is an important difference betweentranslation and interpretation. In the former,the original program is first converted to anequivalent program called an object program.Then this object program is executed i.e. onlyafter the translation has been completed.Hence, the original program in the sourcelanguage is not directly executed.5/1/2006 Computer System Software CS 012 BE 7th Semester 3
  4. 4. Translators translation comprises of two steps i.e Generation of an equivalent program in target language Execution of the generated program Interpretation consists of only one step i.e. executing the original source program5/1/2006 Computer System Software CS 012 BE 7th Semester 4
  5. 5. Translators5/1/2006 Computer System Software CS 012 BE 7th Semester 5
  6. 6. Translators5/1/2006 Computer System Software CS 012 BE 7th Semester 6
  7. 7. Translators5/1/2006 Computer System Software CS 012 BE 7th Semester 7
  8. 8. Phases in a compiler Lexical analysis Syntactic analysis Semantic analysis Intermediate code generation Code optimization Code generation5/1/2006 Computer System Software CS 012 BE 7th Semester 8
  9. 9. Compiler Compiler (Front - End ) Largely dependent on the source language Independent of the target machine Comprises the first three phases viz., – Lexical Analysis – Syntactic Analysis – Semantic Analysis Sometimes the intermediate code generation phase is also included5/1/2006 Computer System Software CS 012 BE 7th Semester 9
  10. 10. Compiler Back-End Dependent on the target machine Independent of the source language Includes the last two phases viz., – Code Optimization – Code Generation5/1/2006 Computer System Software CS 012 BE 7th Semester 10
  11. 11. Lexical Analysis Scans the source program into basic elements called tokens Prepares the symbol table which maintains information about tokens Eliminates white space characters such as comments, blanks and tabs5/1/2006 Computer System Software CS 012 BE 7th Semester 11
  12. 12. Lexical AnalysisEXAMPLE:IF ( x < 5.0 ) THEN x=x+2 ELSE x=x-3;TOKENS:Keywords : IF, THEN, ELSEIdentifier(s) : xConstants : 2, 3, 5.0The blanks separating these tokens wouldnormally be eliminated during lexical analysis.Nowadays, there are tools to do this phaseefficiently. For e.g. in Unix systems, a standardtool called lex is available for this purpose. 5/1/2006 Computer System Software CS 012 BE 7th Semester 12
  13. 13. Syntax Analysis Syntax analysis is also known as parsing or hierarchical analysis. It basically involves grouping of the statements into grammatical phrases that are used by the compiler to generate the output finally. The grammatical phrases of the source program are usually represented by a parse tree( A parse tree is a structural representation of the input being parsed) as shown5/1/2006 Computer System Software CS 012 BE 7th Semester 13
  14. 14. 5/1/2006 Computer System Software CS 012 BE 7th Semester 14
  15. 15. Syntax Analysis there are tools to generate parsers. For e.g. in Unix systems, a tool called as YACC (Yet Another Compiler Compiler) is available for this purpose.5/1/2006 Computer System Software CS 012 BE 7th Semester 15
  16. 16. Semantic Analysis Looks into the static meaning of the program Gathers type information for the subsequent code generation phase Checks whether the type of variables used in the program is consistent with the type defined in the declaration. Example: If a variable is defined as type char, then it is not permitted to do arithmetic operations on that variable.5/1/2006 Computer System Software CS 012 BE 7th Semester 16
  17. 17. Intermediate Code Generation Some compilers generate an explicit intermediate representation of the source program after syntax and semantic analysis. This intermediate representation of the source program can be thought of as a program for an abstract machine and should have two main properties viz., It should be easy to produce It should be easy to translate into the target program5/1/2006 Computer System Software CS 012 BE 7th Semester 17
  18. 18. Next Session Compilers -: Code optimization Code Generation5/1/2006 Computer System Software CS 012 BE 7th Semester 18
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×