Outline. Compiler and Language Processing Tools. Language processing tools (2) Language processing tools. Language processing tools (3)



Similar documents
Compiler and Language Processing Tools

Programming Languages and Compilers

1/20/2016 INTRODUCTION

CSCI 3136 Principles of Programming Languages

Programming Languages

02 B The Java Virtual Machine

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

Programming Languages

Chapter 1. Dr. Chris Irwin Davis Phone: (972) Office: ECSS CS-4337 Organization of Programming Languages

How to make the computer understand? Lecture 15: Putting it all together. Example (Output assembly code) Example (input program) Anatomy of a Computer

Language Processing Systems

Simple C Programs. Goals for this Lecture. Help you learn about:

Language Evaluation Criteria. Evaluation Criteria: Readability. Evaluation Criteria: Writability. ICOM 4036 Programming Languages

n Introduction n Art of programming language design n Programming language spectrum n Why study programming languages? n Overview of compilation

Compiler I: Syntax Analysis Human Thought

Introduction to programming

The Java Virtual Machine and Mobile Devices. John Buford, Ph.D. Oct 2003 Presented to Gordon College CS 311

Semantic Analysis: Types and Type Checking

Chapter 1 Fundamentals of Java Programming

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Introduction. Compiler Design CSE 504. Overview. Programming problems are easier to solve in high-level languages

CSE 307: Principles of Programming Languages

Programming Language Pragmatics

1. Overview of the Java Language

General Introduction

Semester Review. CSC 301, Fall 2015

CSE 373: Data Structure & Algorithms Lecture 25: Programming Languages. Nicki Dell Spring 2014

Programming Language Concepts for Software Developers

CSE 130 Programming Language Principles & Paradigms

Lesson 06: Basics of Software Development (W02D2

The programming language C. sws1 1

Principles of Programming Languages Topic: Introduction Professor Louis Steinberg

What is a programming language?

Image credits:

Programming Languages

Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z)

Compilers. Introduction to Compilers. Lecture 1. Spring term. Mick O Donnell: michael.odonnell@uam.es Alfonso Ortega: alfonso.ortega@uam.

Interpreters and virtual machines. Interpreters. Interpreters. Why interpreters? Tree-based interpreters. Text-based interpreters

INTRODUCTION TO JAVA PROGRAMMING LANGUAGE

Compiler Construction

CSCI E 98: Managed Environments for the Execution of Programs

System Structures. Services Interface Structure

Computer Science. Master of Science

CS:APP Chapter 4 Computer Architecture Instruction Set Architecture. CS:APP2e

Compiler Construction

Chapter 3: Operating-System Structures. Common System Components

Habanero Extreme Scale Software Research Project

Lecture 27 C and Assembly

Lecture 1: Introduction

Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz

Briki: a Flexible Java Compiler

DIABLO VALLEY COLLEGE CATALOG

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

Computer Programming. Course Details An Introduction to Computational Tools. Prof. Mauro Gaspari:

Chapter 7D The Java Virtual Machine

COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing

Assembly Language: Function Calls" Jennifer Rexford!

Implementing Programming Languages. Aarne Ranta

C# and Other Languages

Habanero Extreme Scale Software Research Project

Intel Assembler. Project administration. Non-standard project. Project administration: Repository

picojava TM : A Hardware Implementation of the Java Virtual Machine

Can You Trust Your JVM Diagnostic Tools?

C Compiler Targeting the Java Virtual Machine

Instruction Set Architecture

COS 301 Programming Languages

Object-Oriented Software Specification in Programming Language Design and Implementation

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08

- Applet java appaiono di frequente nelle pagine web - Come funziona l'interprete contenuto in ogni browser di un certo livello? - Per approfondire

Artificial Intelligence. Class: 3 rd

CS 51 Intro to CS. Art Lee. September 2, 2014

Course Structure of Three Year Degree B.A Programme in Computer Application under Semester System of Dibrugarh University (General Programme)

CS61: Systems Programing and Machine Organization

1001ICT Introduction To Programming Lecture Notes

Textual Modeling Languages

Decomposition into Parts. Software Engineering, Lecture 4. Data and Function Cohesion. Allocation of Functions and Data. Component Interfaces

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

CSC Software II: Principles of Programming Languages

Rakudo Perl 6 on the JVM. Jonathan Worthington

Structure of Presentation. The Role of Programming in Informatics Curricula. Concepts of Informatics 2. Concepts of Informatics 1

Assessment for Master s Degree Program Fall Spring 2011 Computer Science Dept. Texas A&M University - Commerce

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

Programming the Android Platform. Logistics

MieruCompiler: Integrated Visualization Tool with Horizontal Slicing for Educational Compilers

Machine-Level Programming II: Arithmetic & Control

Chapter 4 Processor Architecture

Online Recruitment System 1. INTRODUCTION

Developing Web Services with Eclipse and Open Source. Claire Rogers Developer Resources and Partner Enablement, HP February, 2004

Effective Java Programming. efficient software development

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage

PHP vs. Java. In this paper, I am not discussing following two issues since each is currently hotly debated in various communities:

Division of Mathematical Sciences

The C Programming Language course syllabus associate level

Memory management basics (1) Requirements (1) Objectives. Operating Systems Part of E1.9 - Principles of Computers and Software Engineering

Course Goal CMSC 330: Organization of Programming Languages. Studying Programming Languages. All Languages Are (Kind of) Equivalent.

Introduction to Java

Transcription:

Outline Compiler and Tools Summer Term 2011 Prof. Dr. Arnd Poetzsch-Heffter Software Technology Group TU Kaiserslautern 1. Tools 2. 3. Prof. Dr. Arnd Poetzsch-Heffter Compilers 1 Prof. Dr. Arnd Poetzsch-Heffter Compilers 2 Language processing tools Tools Language processing tools (2) Tools Processing of source texts in (source) languages of (source) texts Translation to target languages Typical source languages Programming languages: C, C++, C#, Java, Scala, Haskell,, Smalltalk, Prolog Script languages: JavaScript, bash Languages for configuration management: make, ant Application and tool-specific languages: Excel, JFlex, CUPS Specification languages: Z, CA, Isabelle/HOL Formatting and data description languages: LaTeX, HT, X Design and architecture description languages: U, SDL, VHDL, Verilog Prof. Dr. Arnd Poetzsch-Heffter Compilers 3 Prof. Dr. Arnd Poetzsch-Heffter Compilers 4 Language processing tools (3) Tools Language processing tools (4) Tools Typical target languages Assembly, machine, and bytecode languages Programming language Data and layout description languages Languages for printer control Language implementation tasks Tool support for language processing Integration into existing systems Connection to other systems Prof. Dr. Arnd Poetzsch-Heffter Compilers 5 Prof. Dr. Arnd Poetzsch-Heffter Compilers 6 Application domains Application domains (2) Programming environments Context-sensitive editors, class browers Graphical programming tools Pre-processors Compilers Interpreters Debuggers Run-time environments (loading, linking, execution, memory management) Generation of programs from design documents (U) Program comprehension, re-engineering Design and implementation of domain-specific languages Robot control Simulation tools Spread sheets, active documents Web technology of Web sites Active Web sites (with integrated functionality) Abstract platforms, e.g. JVM,.NET of caching Prof. Dr. Arnd Poetzsch-Heffter Compilers 7 Prof. Dr. Arnd Poetzsch-Heffter Compilers 8

Related fields Formal languages, language specification and design Programming and specification languages Programming, software engineering, software generation, software architecture System software, computer architecture Code Code Analyser Translation Interpreter Results Code Code Output Data Input Data, translation and interpretation are often combined. Prof. Dr. Arnd Poetzsch-Heffter Compilers 9 Prof. Dr. Arnd Poetzsch-Heffter Compilers 10 (2) (3) 1. Translation Compiler implements analysis and translation OS and real machine implement interpretation Pros: Most efficient solution One interpreter for different programming languages Prerequisite for other solutions 2. Direct interpretation Interpreter implements all tasks. : JavaScript, command line languages (bash) Pros: No translation necessary (but analysis at run-time) Prof. Dr. Arnd Poetzsch-Heffter Compilers 11 Prof. Dr. Arnd Poetzsch-Heffter Compilers 12 (4) Example: Beispiel: (Analyse) 3. Abstract and virtual machines Compiler implements analysis and translation to abstract machine code Abstract machine works as interpreter : Java/JVM, C#,.NET Pros: Platform independent (portability, mobile code) Self-modifing programs possible 4. Other combinations package b1_1 ; class Weltklasse implement BesteBohnen {Qualifikation studieren ( Arbeit schweiss) { return new Qualifikation (); javac-analysator Superklasse.class BesteBohnen.class Qualifikation.class Arbeit.class b1_1/weltklasse.java:4: '{' expected. ^ 1 error Prof. Dr. Arnd Poetzsch-Heffter Compilers 13 Prof. Dr. Arnd Poetzsch-Heffter Compilers 14 Example: Translation package b1_1; Beispiel 1: (Übersetzung) class Weltklasse implements BesteBohnen { Qualifikation studieren ( Arbeit schweiss ) { return new Qualifikation(); javac 9 Prof. Dr. Arnd Poetzsch-Heffter Compilers 15 Superklasse.class BesteBohnen.class Qualifikation.class Compiled from Weltklasse.java class b1_1/weltklasse extends implements { b1_1/weltklasse(); b1_1.qualifikation studieren(); Method b1_1/weltklasse() Method b1_1.qualifikation studieren() Arbeit.class Example: Translation (2) Result of translation 10 17.04.2007 A. Poetzsch-Heffter, TU Kaiserslautern 8 Compiled from Weltklasse.java class b1_1/weltklasse extends b1_1.superklasse implements b1_1.bestebohnen { b1_1/weltklasse(); b1_1.qualifikation studieren(b1_1.arbeit); Method b1_1/weltklasse() 0 aload_0 1 invokespecial #6 <Method b1_1.superklasse()> 4 return Method b1_1.qualifikation studieren(b1_1.arbeit) 0 new #2 <Class b1_1.qualifikation> 3 dup 4 invokespecial #5 <Method b1_1.qualifikation()> 7 areturn Prof. Dr. Arnd Poetzsch-Heffter Compilers 16 Beispiel 1: (Fortsetzung)

Example 2: Translation Beispiel 2: (Übersetzung) int main() { printf("willkommen zur Vorlesung!"); return 0; gcc.file "hello_world.c".version "01.01" gcc2_compiled.:.section.rodata.lc0:.string "Willkommen zur Vorlesung!".text.align 16.globl main.type main,@function main: pushl %ebp movl %esp,%ebp subl $8,%esp Example 2: Translation (2) Result of translation Beispiel 2: (Fortsetzung).file "hello_world.c".version "01.01" gcc2_compiled.:.section.rodata.lc0:.string "Willkommen zur Vorlesung!".text.align 16.globl main.type main,@function main: pushl %ebp movl %esp,%ebp subl $8,%esp addl $-12,%esp pushl $.LC0 call printf addl $16,%esp xorl %eax,%eax jmp.l2.p2align 4,,7.L2: movl %ebp,%esp popl %ebp ret.lfe1:.size main,.lfe1-main.ident "GCC: (GNU) 2.95.2 19991024 (release)" 12 11 Prof. Dr. Arnd Poetzsch-Heffter Compilers 17 Prof. Dr. Arnd Poetzsch-Heffter Compilers 18 Example 3: Translation Beispiel 3: (Übersetzung) groovy.tex (104 bytes) \documentclass{article \begin{document \vspace*{7cm \centerline{\huge\bf It s groovy \end{document Example: Interpretation Beispiel: (Interpretation).class File.class-Datei 14 iload_1 15 iload_2 16 idiv 17 istore_3 Eingabedaten Input Data latex groovy.dvi (207 bytes, binary) 14 iload_1 15 iload_2 16 idiv 17 istore_3 groovy.ps (7136 bytes) %!PS-Adobe-2.0 %%Creator: dvips(k) 5.86 %%Title: groovy.dvi Prof. Dr. Arnd Poetzsch-Heffter A. Poetzsch-Heffter, Compilers TU Kaiserslautern 19 17.04.2007 13 dvips Java Virtual Machine (JVM) Output Ausgabedaten Data Prof. Dr. Arnd Poetzsch-Heffter A. Poetzsch-Heffter, CompilersTU Kaiserslautern 20 17.04.2007 14 Example: Combined technique Beispiel: (Kombinierte Technik) Java implementation with just-in-time (JIT) compiler Kombinierte Implementierungstechnik: Java-Implementierung mit JIT-Übersetzer Language processing: The task of translation Java-Überset- zungseinheit Code Unit javac Analysator Analyzer Übersetzer.class-Datei file Java Byte Code JIT-Übersetzer (JIT=Just in time) Eingabedaten Input Data JVM Code Error Message or Code (in a broader sense):, optimization and translation code: Input (string) for translator in syntax of source language () Code: Output (string) of translator in syntax of target language (TL) Maschinencode Machine Code reale Real Machine Maschine/Hardware / Ausgabedaten Output Data 15 Prof. Dr. Arnd Poetzsch-Heffter Compilers 21 Prof. Dr. Arnd Poetzsch-Heffter Compilers 22 Phases of language processing Compile time vs. run-time of input: Program text Specification Diagrams Dependant on target of implementation Transformation (XT, refactoring) Pretty printing, formatting Semantic analysis (program comprehension) (Actual) translation Compile time: during run-time of compiler/translator Static: All information/aspects known at compile time, e.g.: Type checks Evaluation of constant expressions Relative addresses Run-time: during run-time of compiled program Dynamic: All information that are not statically known, e.g.: Allocation of dynamic arrays Bounds check of arrays Dynamic binding of methods Memory management of recursive procedures For dynamic aspects that cannot be handled at compile time, the compiler generates code that handles these aspects at run-time. Prof. Dr. Arnd Poetzsch-Heffter Compilers 23 Prof. Dr. Arnd Poetzsch-Heffter Compilers 24

Requirements for translators What is a good compiler? Error handling (static/dynamic) Efficient target code Choice: Fast translation with slow code vs. slow translation with fast code Semantically correct translation Prof. Dr. Arnd Poetzsch-Heffter Compilers 25 Prof. Dr. Arnd Poetzsch-Heffter Compilers 26 Semantically correct translation Intuitive definition: Compiled program behaves according to language definition of source language. Formal definition: sem: _Program _Data _Data semtl: TL_Program TL_Data TL_Data compile: _Program TL_Program code: _Data TL_Data decode: TL_Data _Data Semantic correctness: sem(p,d) = decode(semtl(compile(p), code(d))) Code as String Token Stream Syntax Tree Scanner Parser Name and Type Decorated Syntax Tree (Close to ) Intermediate Language Code Generator Code as String Synthesis Attribution & Attribution & Peep Hole Prof. Dr. Arnd Poetzsch-Heffter Compilers 27 Prof. Dr. Arnd Poetzsch-Heffter Compilers 28 Properties of compiler architectures Common intermediate language Phases are conceptual units of translation Phases can be interleaved Design of phases depends on source language, target language and design decisions Phase vs. pass (phase can comprise more than one pass.) Separate translation of pogram parts (Interface information must be accessible.) Combination with other architecture decisions: Common intermediate language Language 1 Language 1 Language 2 Language 2 Intermediate Language Language n Language m Prof. Dr. Arnd Poetzsch-Heffter Compilers 29 Prof. Dr. Arnd Poetzsch-Heffter Compilers 30 Dimensions of compiler construction Compiler construction techniques Programming languages Sequential procedural, imperative, OO-languages Functional, logical languages Parallel languages/language constructs languages/machines Code for abstract machines Assembler Machine languages (CISC, RISC, ) Multi-processor/multi-core architectures Memory hierarchy Translation tasks: analysis, optimization, synthesis Construction techniques and tools: bootstrapping, generators Portability, specification, correctness 1. Stepwise construction Construction with compiler for different language Construction with compiler for different machine Bootstrapping 2. Compiler-compiler: Tools for compiler generation Scanner generators (regular expressions) Parser generators (context-free grammars) Attribute evaluation generators (attribute grammar) Code generator generators (machine specification) Interpreter generators (semantics of language) Other phase-specific tools 3. Special programming techniques General technique: syntax-driven Special technique: recursive descend Prof. Dr. Arnd Poetzsch-Heffter Compilers 31 Prof. Dr. Arnd Poetzsch-Heffter Compilers 32

Stepwise construction Construction with compiler for different language Programming typically depends on an existing compiler for the implementation language. For compiler construction, this does not hold in general., target, and implementation languages of compilers can be denoted in T-diagrams. Given: C (machine language) compiler in Construct: compiler in Solution: Develop compiler in C, translate that compiler from C by using the existing C compiler to be developed by translation TL CL T-diagram denotes compiler from source language to target language TL ( TL compiler) written in language CL. C C existing Prof. Dr. Arnd Poetzsch-Heffter Compilers 33 Prof. Dr. Arnd Poetzsch-Heffter Compilers 34 Construction with compiler for different machine Construction with compiler for different machine (2) Construct: C 1 compiler in 1 Given 1. C 1 compiler in C 2. C 2 compiler in 2 Method: construct cross compiler First step cross compiler Second step resulting compiler C 1 C 1 C C 1 1 C 1 C 1 2 C C 2 2 cross compiler 2 Prof. Dr. Arnd Poetzsch-Heffter Compilers 35 Prof. Dr. Arnd Poetzsch-Heffter Compilers 36 Bootstrapping Bootstrapping (2) by extension Construct: compiler in Suppose: yet no compiler exists 2 2 2 Method: 1. Construct partial language i of such that 0 1 2... 2. Implement 0 compiler for in 3. Implement i+1 compiler for in i 4. Create i+1 compiler for in 1 0 1 1 0 by translation manually Prof. Dr. Arnd Poetzsch-Heffter Compilers 37 Prof. Dr. Arnd Poetzsch-Heffter Compilers 38 Recommended reading Wilhelm, Maurer: Chap. 1, (pp. 1 5) Chap. 6, Structure of Compilers (pp. 225 238) Appel Chap. 1, (pp. 3 14) Prof. Dr. Arnd Poetzsch-Heffter Compilers 39