CST320 - Lec 11 Why study compilers? n n Ties lots of things you know together: –Theory (finite automata, grammars) –Data structures –Modularization –Utilization.

Slides:



Advertisements
Similar presentations
Compilers Course 379K, TTH 9:30-11:00 Instructor: Dr. Doron A. Peled Office Hours: Mon 11:00-12:00.
Advertisements

Introduction to Compiler Construction
CPSC Compiler Tutorial 9 Review of Compiler.
Compilers Book: Crafting a Compiler with C
Chapter 1: Introduction to Compiling
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
Compiler Chang Chi-Chung Textbook Compilers: Principles, Techniques, and Tools, 2/E.  Alfred V. Aho, Columbia University  Monica S. Lam,
Compiler Construction1 A Compulsory Module for Students in Computer Science Department Faculty of IT / Al – Al Bayt University First Semester 2009/2010.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Lecture 2 Phases of Compiler. Preprocessors, Compilers, Assemblers, and Linkers Preprocessor Compiler Assembler Linker Skeletal Source Program Source.
1 CST 320 COMPILER METHODS. 2 Week 1 Introduction Go over syllabus Grammar Review Compiler Overview Preprocessor Symbol Table Preprocessor Directives.
C Chuen-Liang Chen, NTUCS&IE / 1 COMPILER Chuen-Liang Chen Department of Computer Science and Information Engineering National Taiwan University Taipei,
September 7, September 7, 2015September 7, 2015September 7, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University.
Course Revision Contents  Compilers  Compilers Vs Interpreters  Structure of Compiler  Compilation Phases  Compiler Construction Tools  A Simple.
410/510 1 of 20 Week 1 – Lecture 1 Introduction The Textbook Assessment Programming & Tools A v. small compiler Compiler Construction.
ICS611 Introduction to Compilers Set 1. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
COP4020 Programming Languages
Chapter 1. Introduction.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
1 Programming Languages Tevfik Koşar Lecture - II January 19 th, 2006.
Introduction to Compiler Construction Robert van Engelen COP5621 Compiler Construction Copyright Robert.
Compiler course 1. Introduction. Outline Scope of the course Disciplines involved in it Abstract view for a compiler Front-end and back-end tasks Modules.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
RIT 08/11/47Chapter 11 Chapter 1: Introduction to Compiling Dr. Winai Wichaipanitch Rajamangala Institute of Technology Klong 6 Thanyaburi Pathumthani.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
1.  10% Assignments/ class participation  10% Pop Quizzes  05% Attendance  25% Mid Term  50% Final Term 2.
1 Chapter 1 Introduction. 2 Outlines 1.1 Overview and History 1.2 What Do Compilers Do? 1.3 The Structure of a Compiler 1.4 The Syntax and Semantics of.
Compiler design Lecture 1: Compiler Overview Sulaimany University 2 Oct
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
1. 2 Preface In the time since the 1986 edition of this book, the world of compiler design has changed significantly 3.
CS 460/660 Compiler Construction. Class 01 2 Why Study Compilers? Compilers are important – –Responsible for many aspects of system performance Compilers.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
Overview of Previous Lesson(s) Over View  A program must be translated into a form in which it can be executed by a computer.  The software systems.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
Chapter 1 Introduction Study Goals: Master: the phases of a compiler Understand: what is a compiler Know: interpreter,compiler structure.
INTRODUCTION TO COMPILERS(cond….) Prepared By: Mayank Varshney(04CS3019)
Compiler Introduction 1 Kavita Patel. Outlines 2  1.1 What Do Compilers Do?  1.2 The Structure of a Compiler  1.3 Compilation Process  1.4 Phases.
Chapter 1: Introduction 1 Compiler Designs and Constructions Chapter 1: Introduction Objectives: Course Objectives Introduction Dr. Mohsen Chitsaz.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
What is a compiler? –A program that reads a program written in one language (source language) and translates it into an equivalent program in another language.
CH1.1 CSE244 Chapter 1: Introduction to Compiling Prof. Steven A. Demurjian, Sr. Computer Science & Engineering Department The University of Connecticut.
Dr. Mohamed Ramadan Saady 314ALL CH1.1 Chapter 1: Introduction to Compiling.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
COP4020 Programming Languages Introduction Prof. Robert van Engelen (modified by Prof. Em. Chris Lacher)
Presented by : A best website designer company. Chapter 1 Introduction Prof Chung. 1.
Chapter 1. Introduction.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Advanced Computer Systems
Compiler Design (40-414) Main Text Book:
PRINCIPLES OF COMPILER DESIGN
Chapter 1 Introduction.
Introduction to Compiler Construction
Language Translation Compilation vs. interpretation.
Chapter 1 Introduction.
课程名 编译原理 Compiling Techniques
Chapter 1: Introduction to Compiling (Cont.)
Compiler Lecture 1 CS510.
Introduction to Compiler Construction
Compiler Construction
Compiler 薛智文 TH 6 7 8, DTH Spring.
COP4020 Programming Languages
Compiler 薛智文 TH 6 7 8, DTH Spring.
Introduction to Compiler Construction
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Compiler 薛智文 M 2 3 4, DTH Spring.
System Programming By Prof.Naveed Zishan.
Introduction to Compiler Construction
Presentation transcript:

CST320 - Lec 11 Why study compilers? n n Ties lots of things you know together: –Theory (finite automata, grammars) –Data structures –Modularization –Utilization of software tools n n You might build a parser. n n The theory of computation/formal language still applies today. – –As long as we still program with 1-D text. n n Helps you to be a better programmer

2 One-dimensional Text int x; cin >> x; if(x>5) cout << “Hello”; else cout << “BOO”; int x;cin >> x;if(x>5) cout << “Hello”; else … The formatting has no impact on the meaning of program

3 What is a translator? n Takes input (SOURCE) and produces output (TARGET) SOURCETARGET ERROR

4 Types of Target Code: n “Pure” machine code »No operating system required. »No library routines. »Good for developing software for new hardware. n “Augmented” code »More common »Executable code relies on o/s provided support and library routines loaded as program is prepared to execute.

5 Conventional Translator skeletal source program preprocessor source program library, relocatable object files compiler assembler target assembly program loader / linker relocatable machine code absolute machine code

6 Types of Target Code (cont.) n Virtual code »Code consists entirely of “virtual” instructions. »Used by “Re-Targetable” compilers n Transporting to a new platform only requires implementing a virtual machine on the new hardware. »Similar to interpreters

7 Translator for Java Java source code Java compiler Java bytecode absolute machine code Java interpreter Bytecode compiler Java bytecode

8 Types of Translators n Compilers –Conventional (textual source code) »Imperative, ALGOL-like languages »Other paradigms n Interpreters n Macro processors n Text formatters n Silicon compilers

9 Types of Translators (cont.) n Visual programming language n Interface –Database –User interface –Operating System

10 Conventional Translator skeletal source program preprocessor source program library, relocatable object files compiler assembler target assembly program loader / linker relocatable machine code absolute machine code

11 Structure of Compilers Lexical Analyzer (scanner) Source Program Syntax Analysis (Parser) Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator Intermediate Representation Target machine code Symbol Table

12 Structure of Compilers Lexical Analyzer (scanner) Source Program Tokens int x; cin >> x; if(x>5) cout << “Hello”; else cout << “BOO”; int x ; cin >> x ; if ( x > 5 ) cout << “Hello” ; else cout << “BOO” ; What about white spaces? Do they matter?

13 Tokenize First or as needed? int x; cin >> x; if(x>5) cout << “Hello”; else cout << “BOO”; int datatype x ID ; symbol cin >> Tokens = Meaningful units in a program Value/Type pairs

14 Tokenize First or as needed? Array > someArray; Array< int > Array > someArray; Array< int> >>

15 Structure of Compilers Lexical Analyzer (scanner) Source Program Syntax Analysis (Parser) Tokens Syntactic Structure Parse Tree

16 Parse Tree (Parser) intx ;cin >> datatypeID Data Declaration Program

17 Who is responsible for errors? n int x$y; n int 32xy; n 45b n 45ab n x = y; Lexical Errors / Token Errors?

18 Who is responsible for errors? n X = ; n Y = x +; n Z = [; Syntax errors

19 Who is responsible for errors? n 45ab –One wrong token? –Two tokens (45 & ab)? Are whitespaces needed? n Either way is okay. –Lexical analyzer can catch the illegal token (45ab) –Parser can catch the syntax error. Most likely 45 followed by ab will not be syntactically correct.

20 Structure of Compilers Lexical Analyzer (scanner) Source Program Syntax Analysis (Parser) Tokens Semantic Analysis Syntactic Structure Symbol Table int x; cin >> x; if(x>5) x = “SHERRY”; else cout << “BOO”;

21 Structure of Compilers Lexical Analyzer (scanner) Source Program Syntax Analysis (Parser) Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator Intermediate Representation Target machine code Symbol Table

22 Structure of Compilers Lexical Analyzer (scanner) Source Program Syntax Analysis (Parser) Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator Intermediate Representation Target machine code Symbol Table

23 Translation Steps: n n Recognize when input is available. n n Break input into individual components. n n Merge individual pieces into meaningful structures. n n Process structures. n n Produce output.

24 Translation (Compilers) Steps: n n Break input into individual components. (lexical analysis) n n Merge individual pieces into meaningful structures. (parsing) n n Process structures. (semantic analysis) n n Produce output. (code generation)

25 Compilers n Two major tasks: –Analysis of source –Synthesis of target n Syntax-directed translation –Compilation process driven by syntactic structure of the source being translated

26 Interpreters n Executes source program without explicitly translating to target code. n Control and memory management reside in interpreter, not user program. n Allow: –Modification of program as it executes. –Dynamic typing of variables –Portability n Huge overhead (time & space)

27 Structure of Interpreters Interpreter Source Program Data Program Output

28 Misc. Compiler Discussions n History of Modern Compilers n Front and Back ends n One pass vs. Multiple passes n Compiler Construction Tools –Compiler-Compilers, Compiler-generators, Translator- writing Systems »Scanner generator »Parse generator »Syntax-directed engines »Automatic code generator »Dataflow engines