 Chapter 2 Language Processors Fall 2013. Chart 2  Translators and Compilers  Interpreters  Real and Abstract Machines  Interpretive Compilers 

Slides:



Advertisements
Similar presentations
CS1Q Computer Systems Lecture 14
Advertisements

GCSE Computing Lesson 5.
compilers and interpreters
1 CIS 461 Compiler Design and Construction Fall 2014 Instructor: Hugh McGuire slides derived from Tevfik Bultan, Keith Cooper, and Linda Torczon Lecture-Module.
Systems Software.
CSI 3125, Preliminaries, page 1 Programming languages and the process of programming –Programming means more than coding. –Why study programming languages?
Object Oriented Programming in Java George Mason University Fall 2011
PLLab, NTHU Cs2403 Programming Languages Implementation Issues Cs2403 Programming Language Spring 2005 Kun-Yuan Hsieh.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 531 Compiler Construction Ch.2: Language Processors Spring 2010 Marco.
T-diagrams “Mommy, where do compilers come from?” Adapted from:
Introduction to Computers and Programming. Some definitions Algorithm: –A procedure for solving a problem –A sequence of discrete steps that defines such.
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
Chapter 1 Introduction to C Programming. 1.1 INTRODUCTION This book is about problem solving with the use of computers and the C programming language.
1 Programming Languages Translation  Lecture Objectives:  Be able to list and explain five features of the Java programming language.  Be able to explain.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 531 Compiler Construction Ch.2 Spring 2007 Marco Valtorta
Lecture 2: Do you speak Java?. From Problem to Program Last Lecture we looked at modeling with objects! Steps to solving a business problem –Investigate.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 1, Lab.
CS 104 Introduction to Computer Science and Graphics Problems Software and Programming Language (2) Programming Languages 09/26/2008 Yang Song (Prepared.
Introduction to Computers and Programming. Some definitions Algorithm: Algorithm: A procedure for solving a problem A procedure for solving a problem.
3/24/2004COSC4301 assignment 31 Compiler, Interpreter, and Bootstrapping Motivation: When we are asked to write a  Compiler for a complex source language.
3-1 3 Compilers and interpreters  Compilers and other translators  Interpreters  Tombstone diagrams  Real vs virtual machines  Interpretive compilers.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Principles of Programming Chapter 1: Introduction  In this chapter you will learn about:  Overview of Computer Component  Overview of Programming 
Programming Languages Lecture 12. What is Programming?  The process of telling the computer what to do  Also known as coding.
CCSA 221 Programming in C CHAPTER 2 SOME FUNDAMENTALS 1 ALHANOUF ALAMR.
PROGRAMMING LANGUAGES The Study of Programming Languages.
P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Compilers, Interpreters and Debuggers Ruibin Bai (Room AB326) Division of Computer Science.
CS 355 – Programming Languages
High level & Low level language High level programming languages are more structured, are closer to spoken language and are more intuitive than low level.
CS1Q Computer Systems Lecture 14 Simon Gay. Lecture 14CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed.
Java Programming Introduction & Concepts. Introduction to Java Developed at Sun Microsystems by James Gosling in 1991 Object Oriented Free Compiled and.
Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions.
Language processors (Chapter 2) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
Introduction to C++ Programming Language
Copyright © 2007 Addison-Wesley. All rights reserved.1-1 Reasons for Studying Concepts of Programming Languages Increased ability to express ideas Improved.
IXA 1234 : C++ PROGRAMMING CHAPTER 1. PROGRAMMING LANGUAGE Programming language is a computer program that can solve certain problem / task Keyword: Computer.
INTRODUCTION TO COMPUTING CHAPTER NO. 04. Programming Languages Program Algorithms and Pseudo Code Properties and Advantages of Algorithms Flowchart (Symbols.
Introduction to Language Processing Technology Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.
CS 614: Theory and Construction of Compilers Lecture 8 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Intermediate 2 Computing Unit 2 - Software Development Topic 2 - Software Development Languages and Environments.
A compiler is a computer program that translate written code (source code) into another computer language Associated with high level languages A well.
Language Implementation Methods David Woolbright.
 Computer Languages Computer Languages  Machine Language Machine Language  Assembly Language Assembly Language  High Level Language High Level Language.
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm Hutchinson.
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm Hutchinson.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
Presented by : A best website designer company. Chapter 1 Introduction Prof Chung. 1.
Programming Languages Concepts Chapter 1: Programming Languages Concepts Lecture # 4.
Programming 2 Intro to Java Machine code Assembly languages Fortran Basic Pascal Scheme CC++ Java LISP Smalltalk Smalltalk-80.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Software Engineering Algorithms, Compilers, & Lifecycle.
Objective of the course Understanding the fundamentals of the compilation technique Assist you in writing you own compiler (or any part of compiler)
Introduction to computer software. Programming the computer Program, is a sequence of instructions, written to perform a specified task on a computer.
CHAPTER 1 INTRODUCTION TO COMPILER SUNG-DONG KIM, DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
Why don’t programmers have to program in machine code?
Overview of Compilers and Language Translation
Compiler, Interpreter, and Bootstrapping
Chapter 1 Introduction.
Introduction to programming
Programming Language Hierarchy, Phases of a Java Program
Compiler Construction (CS-636)
Chapter 1 Introduction.
Want to Write a Compiler?
Developing Applications
CSCE 531 Compiler Construction Ch.2
Reasons To Study Programming Languages
Programming language translators
Presentation transcript:

 Chapter 2 Language Processors Fall 2013

Chart 2  Translators and Compilers  Interpreters  Real and Abstract Machines  Interpretive Compilers  Portable Compilers  Bootstrapping  Case Study: The Triangle Language Processor

Chart 3  Translator: a program that accepts any text expressed in one language (the translator’s source language), and generates a semantically-equivalent text expressed in another language (its target language) o Chinese-into-English o Java-into-C o Java-into-x86 o X86 assembler

Chart 4  Assembler: translates from an assembly language into the corresponding machine code o Generates one machine code instruction per source instruction  Compiler: translates from a high-level language into a low- level language o Generates several machine-code instructions per source command.

Chart 5  Disassembler: translates a machine code into the corresponding assembly language  Decompiler: translates a low-level language into a high-level language Question: Why would you want a disassembler or decompiler?

Chart 6  Source Program: the source language text  Object Program: the target language text Compiler Object Program Syntax Check Context Constraints Generate Object Code Semantic Analysis Source Program Object program semantically equivalent to source program  If source program is well-formed

Chart 7  Why would you want to do: o Java-into-C translator o C-into-Java translator o Assembly-language-into-Pascal decompiler

Chart 8 M P L P L M P = Program Name L = Implementation Language M = Target Machine For this to work, L must equal M, that is, the implementation language must be the same as the machine language ST L S = Source Language T = Target Language L = Translator’s Implementation Language S-into-T Translator is itself a program that runs on machine L

Chart 9 Translating a source program P Expressed in language T, Using an S-into-T translator Running on machine M P S M ST M P T

Chart 10 Translating a source program sort Expressed in language Java, Using a Java-into-x86 translator Running on an x86 machine sort Java x86 Javax86 sort x86 The object program is running on the same machine as the compiler sort x86

Chart 11 sort Java x86 JavaPPC x86 sort PPC Cross Compiler: The object program is running on a different machine than the compiler sort PPC download Translating a source program sort Expressed in language Java, Using a Java-into-PPC translator Running on an x86 machine Downloaded to a PPC machine

Chart 12 sort Java x86 JavaC x86 sort C Two-stage Compiler: The source program is translated to another language before being translated into the object program sort x86 Translating a source program sort Expressed in language Java, Using a Java-into-C translator Running on an x86 machine x86 sort x86 C Then translating the C program Using an C-into x86 compiler Running on an x86 machine Into x86 object program

Chart 13  Translator Rules o Can run on machine M only if it is expressed in machine code M o Source program must be expressed in translator’s source language S o Object program is expressed in the translator’s target language T o Object program is semantically equivalent to the source program

Chart 14  Accepts any program (source program) expressed in a particular language (source language) and runs that source program immediately o Does not translate the source program into object code prior to execution

Chart 15 Interpreter Program Complete Fetch Instruction Analyze Instruction Execute Instruction Source Program Source program starts to run as soon as the first instruction is analyzed

Chart 16  When to Use Interpretation o Interactive mode – want to see results of instruction before entering next instruction o Only use program once o Each instruction expected to be executed only once o Instructions have simple formats  Disadvantages o Slow: up to 100 times slower than in machine code

Chart 17  Examples o Basic o Lisp o Unix Command Language (shell) o SQL

Chart 18 S L S interpreter expressed in language L S M P S M Program P expressed in language S, using Interpreter S, running on machine M Basic x86 graph Basic x86 Program graph written in Basic running on a Basic interpreter executed on an x86 machine

Chart 19  Hardware emulation: Using software to execute one set of machine code on another machine o Can measure everything about the new machine except its speed o Abstract machine: emulator o Real machine: actual hardware An abstract machine is functionally equivalent to a real machine if they both implement the same language L

Chart 20 nmi C M CM M New Machine Instruction (nmi) interpreter written in C nmi C M The nmi interpreter is translated into machine code M using the C compiler Compiler to translate C program into M machine code nmi interpreter written in C nmi interpreter expressed in machine code M nmi M P M P

Chart 21  Combination of compiler and interpreter o Translate source program into an intermediate language o It is intermediate in level between the source language and ordinary machine code o Its instructions have simple formats, and therefore can be analyzed easily and quickly o Translation from the source language into the intermediate language is easy and fast An interpretive compiler combines fast compilation with tolerable running speed

Chart 22 JavaJVM M M Java into JVM translator running on machine M JVM code interpreter running on machine M JavaJVM M P Java P JVM M P M M A Java program P is first translated into JVM-code, and then the JVM-code object program is interpreted

Chart 23  A program is portable if it can be compiled and run on any machine, without change o A portable program is more valuable than an unportable one, because its development cost can be spread over more copies o Portability is measured by the proportion of code that remains unchanged when it is moved to a dissimilar machine Language affects portability Assembly language: 0% portable High level language: approaches 100% portability

Chart 24  Language Processors o Valuable and widely used programs o Typically written in high-level language Pascal, C, Java o Part of language processor is machine dependent Code generation part Language processor is only about 50% portable o Compiler that generates intermediate code is more portable than a compiler that generates machine code

Chart 25 JavaJVM Java JVM Java JVM P Java P JVM M P M M C JavaJVM 2. Rewrite interpreter in C CM M M JVM C M M Note: C M Compiler exists; rewrite JVM interpreter from Java to C 1. Start with the following 3. Compile the compiler 4. Java program P is translated into JVM program P and run using ghe JVM intrepreter

Chart 26  The language processor is used to process itself o Implementation language is the source language  Bootstrapping a portable compiler o A portable compiler can be bootstrapped to make a true compiler – one that generates machine code – by writing an intermediate- language-into-machine-code translator  Full bootstrap o Writing the compiler in itself o Using the latest version to upgrade the next version  Half bootstrap o Compiler expressed in itself but targeted for another machine  Bootstrapping to improve efficiency o Upgrade the compiler to optimize code generation as well as to improve compile efficiency

Chart 27 Bootstrap an interpretive compiler to generate machine code JVMM Java M JVM M M Java JVM M M M M M M M M JavaJVM M M JavaJVM M JavaJVM M M M M M P Java P JVM P M 1, First, write a JVM-coded-into- M translator in Java 2. Next, compile translator using existing interpreter 3. Use translator to translate itself 4. Translate Java- into-JVM-code translator into machine code 5. Two stage Java-into-M compiler

Chart 28 Full bootstrap Ada-SM C v1 Ada-SM C CM M M M M v1 Ada-SM v2 Ada-SM M M M M M v2 v1 AdaM Ada-S M M AdaM M M v3 v2 AdaM Ada-S v3 5. Extend Ada-S compiler to (full) Ada compiler 3. Convert the C version of Ada-S into Ada-S version of Ada-S 1. Write Ada-S compiler in C 2. Compile v1 using the C compiler 4. Use v1 to compile v2 6. Compile full version of Ada using Ada-S compiler

Chart 29 Half bootstrap AdaHM Ada HM AdaTM Ada TM Ada HM AdaTM HM P Ada TM HM P TM P AdaTM Ada TM HM AdaTM 2. Ada compiler that generates machine code for machine H expressed in HM 1. Ada compiler that generates machine code for machine H expressed in Ada 3.Rewrite Ada compiler that generates HM code to Ada compiler that generates machine code for machine TM 5. Make sure the compiler works properly 6. Use the compiler to compile itself. Now have an Ada compiler that generates TM code that runs on machine TM 4. Use existing Ada compiler fro HM to compile the Ada compiler that run on HM but generates code for TM

Chart 30 Bootstrap to improve efficiency AdaMsMs MsMs v1 AdaMsMs v1 AdaMfMf v2 AdaMfMf v2 AdaMsMs MsMs v1 AdaMfMf MsMs v2 M AdaMfMf MsMs v2 P Ada 1. Start with v1 targeted to M-slow written in Ada and compiled to run on M-slow 2. Rewrite v1 to run on M-fast in Ada 3. Use v1 to compile v2 P MfMf P MfMf M 4. Compile a program using v2; it will compile slow but run fast AdaMfMf v2 AdaMsMs MsMs v2 AdaMfMf MfMf v3 M 5. Use v2 to compile v2 to produce v3 which will be the fast compiler.