Compilation I. Hwansoo Han

Similar documents
Why are there so many programming languages? Why do we have programming languages? What is a language for? What makes a language successful?

Early computers (1940s) cost millions of dollars and were programmed in machine language. less error-prone method needed

Why are there so many programming languages?

Programming Languages

Introduction to Programming Languages. CSE 307 Principles of Programming Languages Stony Brook University

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

LECTURE 2. Compilers and Interpreters

8/27/17. CS-3304 Introduction. What will you learn? Semester Outline. Websites INTRODUCTION TO PROGRAMMING LANGUAGES

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

General Concepts. Abstraction Computational Paradigms Implementation Application Domains Influence on Success Influences on Design

SKILL AREA 304: Review Programming Language Concept. Computer Programming (YPG)

CS 3304 Comparative Languages. Lecture 1: Introduction

Concepts of Programming Languages

Chapter 1. Preliminaries

Design & Implementation Overview

Chapter 1 Preliminaries

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Chapter 1. Preview. Reason for Studying OPL. Language Evaluation Criteria. Programming Domains

Chapter 1. Preliminaries

COMPILER DESIGN LECTURE NOTES

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILING

Principles of Programming Languages. Lecture Outline

CMPT 379 Compilers. Anoop Sarkar.

Why study Programming Language Concepts? Chapter One. Language Evaluation Criteria. Programming Domains. Readability Writability Reliability Cost

CST-402(T): Language Processors

COP 3402 Systems Software. Lecture 4: Compilers. Interpreters

LECTURE 1. Overview and History

Compilers. Prerequisites


Organization of Programming Languages (CSE452) Why are there so many programming languages? What makes a language successful?

Crafting a Compiler with C (II) Compiler V. S. Interpreter

Language Translation, History. CS152. Chris Pollett. Sep. 3, 2008.

What is a programming language?

Programming Languages, Summary CSC419; Odelia Schwartz

Discovering Computers Chapter 13 Programming Languages and Program Development

Programmiersprachen (Programming Languages)

Introduction to Compiler Construction

Introduction to Engineering Using Robotics Experiments. Dr. Yinong Chen

1/14/2014. Introduction to CSE 1325 Object Oriented Programming (Using Java) Introduction (Cont.) Introduction

History of Compilers The term

CS558 Programming Languages

Lecture 09. Ada to Software Engineering. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

CSCI 3136 Principles of Programming Languages

Introduction. Compilers and Interpreters

Low-Level Languages. Computer Programs and Programming Languages

New Programming Paradigms

Introduction to Compiler Construction

Computers in Engineering COMP 208. Computer Structure. Computer Architecture. Computer Structure Michael A. Hawker

PROGRAMMAZIONE I A.A. 2017/2018

Introduction to Java Programming

Discovering Computers 2008

A Tour of Language Implementation

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS

Com S 541. Programming Languages I

C++ Programming Language Lecture 1 Introduction

CS321 Languages and Compiler Design I. Winter 2012 Lecture 1

Software II: Principles of Programming Languages

Högnivåspråk och översättning

CSc 372. Comparative Programming Languages. 2 : Functional Programming. Department of Computer Science University of Arizona

Software Development. Integrated Software Environment

What is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done

1) What is the first step of the system development life cycle (SDLC)? A) Design B) Analysis C) Problem and Opportunity Identification D) Development

Programming. Loriano Storchi.

Introduction. A. Bellaachia Page: 1

SYSTEMS PROGRAMMING. Srimanta Pal. Associate Professor Indian Statistical Institute Kolkata OXFORD UNIVERSITY PRESS

Principles in Programming: Orientation & Lecture 1. SWE2004: Principles in Programming Spring 2014 Euiseong Seo

CS A331 Programming Language Concepts

Concepts in Programming Languages

INF 212 ANALYSIS OF PROG. LANGS PROCEDURES & FUNCTIONS. Instructors: Kaj Dreef Copyright Instructors.

Lecture 1: Course Introduction

0 Introduction: Computer systems and program development

CS 314 Principles of Programming Languages

Informatica 3 Syntax and Semantics

What are some common categories of system calls? What are common ways of structuring an OS? What are the principles behind OS design and

What is a compiler? Xiaokang Qiu Purdue University. August 21, 2017 ECE 573

Technology in Action. Chapter Topics (cont.) Chapter Topics. Reasons for Software Programming. Information Systems 10/29/2010

Chapter 1 Introduction to Computers and C++ Programming

Programming Languages 2nd edition Tucker and Noonan"

Topic I. Introduction and motivation References: Chapter 1 of Concepts in programming languages by J. C. Mitchell. CUP, 2003.

Chapter 5. Names, Bindings, and Scopes

Chapter 3:: Names, Scopes, and Bindings (cont.)

Comp 333: Concepts of Programming Languages Fall 2016

CS101 Introduction to Programming Languages and Compilers

CS558 Programming Languages

Pioneering Compiler Design

Objective: To learn meaning and concepts of programming. Outcome: By the end of this students should be able to describe the meaning of programming

Lecture 1: Course Introduction


Life Cycle of Source Program - Compiler Design

Introduction. CS 2210 Compiler Design Wonsun Ahn

Chapter 6 Control Flow. June 9, 2015

Chapter 11 Introduction to Programming in C

Seminar in Programming Languages

Functional Programming. Big Picture. Design of Programming Languages

CS 415 Midterm Exam Spring 2002

Programming 1. Lecture 1 COP 3014 Fall August 28, 2017

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Compiling Regular Expressions COMP360

Transcription:

Compilation I Hwansoo Han

Language Groups Imperative von Neumann (Fortran, Pascal, Basic, C) Object-oriented (Smalltalk, Eiffel, C++) Scripting languages (Perl, Python, JavaScript, PHP) Declarative Functional Logic, constraint-based (Scheme, ML, pure Lisp, FP) (Prolog, VisiCalc, RPG) 2

Why so many programming languages? Evolution We've learned better ways of doing things over time Socio-economic factors Proprietary interests, commercial advantage Orientation toward special purposes Orientation toward special hardware Diverse ideas about what is pleasant to use 3

Pure Compilation Compiler translates the high-level source program into an equivalent target program (typically in a machine language) not used while running program Source program Compiler Input Target Program Output 4

Pure Interpretation Interpreter stays around for the execution of the program the center of control during execution Source program Interpreter Output Input 5

Compilation vs. Interpretation (1) Compilation vs. interpretation Not opposites Not a clear-cut distinction Interpretation: Greater flexibility Better diagnostics (error messages) Compilation Better performance 6

Compilation vs. Interpretation (2) Common case Compilation or simple pre-processing, followed by interpretation Most language implementations include a mixture of both compilation and interpretation Source program Translator Intermediate program Input Virtual Machine Output 7

Compilation vs. Interpretation (3) Note that compilation does NOT have to produce machine language for a hardware Compilation is translation from one language into another, with full analysis of the meaning of the input Compilation entails semantic understanding of what is being processed, but a pre-processing does not 8

Compilation vs. Interpretation (4) Many compiled languages have interpreted pieces, e.g., formats in C or Fortran Most use virtual instructions set operations in Pascal string manipulation in Basic Some compilers produce only virtual instructions e.g., Java bytecode, Microsoft CIL, Pascal P-code 9

Implementation Strategies (1) Preprocessor Removes comments and white spaces Groups characters into tokens e.g., keywords, identifiers, numbers, symbols Expands abbreviations in the style of a macro assembler Identifies higher-level syntactic structures e.g., loops, subroutines 10

Implementation Strategies (2) Library of Routines and Linking Compiler uses a linker program to merge the appropriate library of subroutines into the final program e.g., math functions such as sin, cos, log, etc Source program Compiler Incomplete machine language Library routines Linker 11 Machine language program

Implementation Strategies (3) Post-compilation Assembly Facilitates debugging assembly languages easier for human than machine binaries Isolates the compiler from changes in the format of machine language files only assembler must be changed, and shared by many compilers Source program Compiler Assembly language Assembler Machine language 12

Implementation Strategies (4) The C Preprocessor (conditional compilation) deletes portions of code, which allows several versions of a program to be built from the same source Source program Preprocessor Modified source program #if _X86_ A=... #elif _ARM_ B=... #else C=... #end Compiler Assembly language A=... -D _X86_ 13

Implementation Strategies (5) Source-to-Source Translation (C++) C++ implementations based on the early AT&T compiler generated an intermediate program in C, instead of an assembly language: Source program Preprocessor Modified source program C++ compiler C code C compiler Assembly language 14

Implementation Strategies (6) Bootstrapping Pascal to machine language compiler (in Pascal) Pascal to P-code compiler (in P-code) P-code interpreter Pascal to machine language compiler (in P-code) P-code interpreter Pascal to machine language compiler (in machine language) 15

Implementation Strategies (7) Compilation of Interpreted Languages Some features of IL are not finalized until runtime Late binding Generates code with assumptions on runtime decision If these assumptions are valid, the code runs very fast If not, a dynamic check will revert to the interpreter. 16

Implementation Strategies (8) Dynamic and Just-in-Time Compilation Deliberately delay compilation until the last possible moment Dynamic compilation Lisp or Prolog invoke the compiler on the fly, Translate newly created source into machine language, or Optimize the code for a particular input set Just-in-time (JIT) compilation Java defines a machine-independent intermediate form (bytecode) C# compiler produces Common Intermediate Language (CIL) Bytecode, CIL are translated into machine code immediately prior to execution 17

Implementation Strategies (9) Microcode (firmware) Assembly-level instruction set is not implemented in hardware, but runs on an interpreter Interpreter is written in low-level instructions (microcode or firmware), which are stored in read-only memory (ROM) and executed by the hardware Popular in machines before the mid 1980s 18

Compilation vs. Interpretation Compilers exist for some interpreted languages, but they aren't pure: Selective compilation of compilable pieces and extrasophisticated pre-processing of remaining source Interpretation of parts of code, at least, is still necessary for reasons above Unconventional compilers 19 Text formatters (TEX, troff) Query language processors Silicon compilers

Programming Environment Tools Tools Type Editors Pretty printers Pre-processors (esp. macros) Debuggers Style checkers Module management Version management Assemblers Link editors, loaders Perusal tools Program cross-reference Unix examples vi, emacs cb, indent cpp, m4, watfor adb, sdb, dbx, gdb lint, purify make sccs, rcs, cvs, subversion as ld, ld-so more, less, od, nm ctags 20