Presentation is loading. Please wait.

Presentation is loading. Please wait.

Objective of the course Understanding the fundamentals of the compilation technique Assist you in writing you own compiler (or any part of compiler)

Similar presentations


Presentation on theme: "Objective of the course Understanding the fundamentals of the compilation technique Assist you in writing you own compiler (or any part of compiler)"— Presentation transcript:

1

2 Objective of the course Understanding the fundamentals of the compilation technique Assist you in writing you own compiler (or any part of compiler)

3 Programming Language A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create program that control the behavior of a machine and/or to express algorithms precisely. First programming language  ADA  1950

4 Program A set of rules to tell computer what to do A set of rule for communicating with the system A set of instructions to make computer understand

5 Levels of Programming Language High Level Middle Level Low Level

6 Generation of Programming Languages First Generation Machine language (0 1) Second Generation Assemble language Third Generation Procedural languages (C/C++, Java, VB etc) Forth Generation Structural Languages (SQL) Fifth Generation A.I languages (LISP, Prolog etc)

7 Translation A program written in any language must be translated to machine understandable form Translator is used to translate one form of program into another form Types Assembler Compiler Interpreter

8 Compiler It is a translator Compiler is a program (written in a high-level language) that converts / translates / compiles source program written in a high level language into an equivalent machine code. It takes a program written in source language and translates it into an equivalent target program A program that carries out translation activities

9 COMPILER inputOutput Source code machine code Error listing may or may not Design of a Compiler

10 Phases of a Compiler Source Program Lexical Analyzer 1 Syntax Analyzer 2 Semantic Analyzer 3 Intermediate Code Generator 4 Code Optimizer 5 Code Generator 6 Target Program Symbol-table ManagerError Handler

11 Phases of Compiler Lexical Analysis Deals with words/ tokens Syntax Analysis Deals with structure/ syntax/ grammar Semantic Analysis Deals with meaning/ logic Intermediate Code Generation Deals with a third form (mediator form) Intermediate Code Optimization Deals with Compression Target Code Generation Machine understandable for m Machine Code Optimization

12 The Analysis-Synthesis Model of Compilation Analysis Understanding the source program properly In this part intermediate representation is created from the source code This part breaks up the source code into meaningful pieces, while storing information into symbol table Then imposes a grammatical structure on these pieces Synthesis Generating the target code In this part the target program is created from the representation Constructs the target code from the information stored in the symbol table

13 The Analysis-Synthesis Model of Compilation Analysis-Phases involved Lexical Analysis Syntax Analysis Semantic Analysis Synthesis-Phases involved Intermediate code generation Intermediate Code optimization Machine code generation Machine code optimization

14 Front End Back End Intermediate code Error listing input output Internal Structure of Compiler Front-Back

15 Front-End Independent of target machine for which the machine code is to be generated. Depends on source language. Varies from language to language. Can be used for different platforms. Does all error checking for the source code. Produces error list, if any errors are encountered. Converts source program into Intermediate code.

16 Back-End Depends on the target machine / hardware. Reads the intermediate code and converts it into machine code. For each machine, we need a different back-end. Independent of source language.

17 Phases involved in Front-Back Ends Front-end and back-end have further components called phases of compilation process. Front-end: Lexical Analysis Syntax Analysis Semantic Analysis Intermediate Code Generation Intermediate Code Optimization Back-end: Machine code Generation Machine Code Optimization

18 Inside a Compiler Lexical Analyzer Intermediate code Source code Machine code Syntax Analyzer Semantic Analyzer Intermediate code Generator Intermediate code Optimizer Machine code Optimizer Machine code Generator Error listing

19 Symbol Table One of the essential function of the compiler is to record the identifiers used in the source program and collect information about the attributes of the identifiers A symbol table is data structure containing a record for each identifier with its attributes Attributes could be Storage information Type Scope etc

20 Error Handling Process Error is any unknown thing to the compiler. Each and every phase may encounter error, so this is the job of error handler to deal with it Error handler performs overall management regarding the errors Function of error handler Rectification of error at own level Error message generating Management

21 Types of errors Mostly three types of errors are encountered in the compilation process Lexical errors Words/ tokens related  When a specific token is not formed Example  20a Syntax errors Structure/ grammar related Examples  int a : OR if {a>b} Semantic errors Meaning related Example  int a, b, c; b=10, c[2]={1,2}; a=b+c;


Download ppt "Objective of the course Understanding the fundamentals of the compilation technique Assist you in writing you own compiler (or any part of compiler)"

Similar presentations


Ads by Google