Introduction. Introduction Traditional view of a compiler tool to translate high-level (imperative) code into optimized machine code large, complicated.

Slides:



Advertisements
Similar presentations
Introduction to Compiler Construction
Advertisements

Compiler Construction by Muhammad Bilal Zafar (AP)
Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education.
Lecture 01 - Introduction Eran Yahav 1. 2 Who? Eran Yahav Taub 734 Tel: Monday 13:30-14:30
Cpeg421-08S/final-review1 Course Review Tom St. John.
1 Semantic Processing. 2 Contents Introduction Introduction A Simple Compiler A Simple Compiler Scanning – Theory and Practice Scanning – Theory and Practice.
January 12, Compiler Design Hongwei Xi Comp. Sci. Dept. Boston University.
January 19, Compiler Design Hongwei Xi Comp. Sci. Dept. Boston University.
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
Compiler Construction
BİL744 Derleyici Gerçekleştirimi (Compiler Design)1.
CS 153: Concepts of Compiler Design August 25 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CPSC 388 – Compiler Design and Construction Lecture: MWF 11:00am-12:20pm, Room 106 Colton.
Compiling Principles & Compiler Construction
C Chuen-Liang Chen, NTUCS&IE / 1 COMPILER Chuen-Liang Chen Department of Computer Science and Information Engineering National Taiwan University Taipei,
Invitation to Computer Science 5th Edition
CS 153: Concepts of Compiler Design August 24 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
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.
Introduction to Compiler Construction Robert van Engelen COP5621 Compiler Construction Copyright Robert.
Compiler Construction1 COMP Compiler Construction Lecturer: Dr. Arthur Cater Teaching Assistant:
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.
PART I SISTEM UTILITIES Lecture 6 Compilers Ştefan Stăncescu 1.
CST 320 Compiler Methods Dr. Sherry Yang PV 171 (541)
Programming Languages & Translators (CE 359) Fall 2013 Prof. Dr: Ahmed El Nahass Lecture 1 1 FACULTY OF ENGINEERING COMPUTER ENGINEERING Prof.Dr Ahmed.
Joey Paquet, Lecture 12 Review. Joey Paquet, Course Review Compiler architecture –Lexical analysis, syntactic analysis, semantic.
Bernd Fischer RW713: Compiler and Software Language Engineering.
Compiler design Lecture 1: Compiler Overview Sulaimany University 2 Oct
Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
Introduction to Compiling
Compiler Construction (CS-636)
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.
Course Overview for Compilers J. H. Wang Sep. 14, 2015.
1 CS308 Compiler Theory. 2 Course Information Instructor : –Prof. Minyi Guo –Yao Shen Course.
Compilers: Prelim/0 1 Compiler Structures Objective – –to give some background on the course , Semester 1, Who I am: Andrew Davison.
Course Overview for Compilers J. H. Wang Sep. 20, 2011.
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.
©SoftMoore ConsultingSlide 1 Structure of Compilers.
©SoftMoore ConsultingSlide 1 Teaching Compiler Design.
CSC 8505 Compiler Construction
1 Compiler Construction Vana Doufexi office CS dept.
Presented by : A best website designer company. Chapter 1 Introduction Prof Chung. 1.
CS416 Compiler Design1. 2 Course Information Instructor : Dr. Ilyas Cicekli –Office: EA504, –Phone: , – Course Web.
CS510 Compiler Lecture 1. Sources Lecture Notes Book 1 : “Compiler construction principles and practice”, Kenneth C. Louden. Book 2 : “Compilers Principles,
Prologue Sung-Dong Kim, Dept. of Computer Engineering, Hansung University.
Review 1.Structure of the course Lexical Analysis Syntax Analysis Grammar & Language RG & DFA Top-down LL(1) Parsing Bottom-Up LR Layered Automation Semantic.
Lecture 12 Intermediate Code Generation Translating Expressions
2016/7/9Page 1 Lecture 11: Semester Review COMP3100 Dept. Computer Science and Technology United International College.
CHAPTER 1 INTRODUCTION TO COMPILER SUNG-DONG KIM, DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
System Software Theory (5KS03).
Compiler principles Compiler Jakub Yaghob.
Compiler Design (40-414) Main Text Book:
Chapter 1 Introduction.
Introduction to Compiler Construction
Chapter 1 Introduction.
课程名 编译原理 Compiling Techniques
Compiler Lecture 1 CS510.
CS416 Compiler Design lec00-outline September 19, 2018
Introduction to Compiler Construction
Course supervisor: Lubna Siddiqui
Introduction CI612 Compiler Design CI612 Compiler Design.
CPSC 388 – Compiler Design and Construction
CSE401 Introduction to Compiler Construction
Subject: Language Processor
Compiler Structures 0. Preliminaries
CS416 Compiler Design lec00-outline February 23, 2019
Introduction to Compiler Construction
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Introduction to Compiler Construction
Review for the Midterm. Overview (Chapter 1):
Presentation transcript:

Introduction

Traditional view of a compiler tool to translate high-level (imperative) code into optimized machine code large, complicated black box details for experts only focus on parsing (historically) optimization (recently) gcc, llvm, ...

Traditional reasons to study compilers application of theory regular expressions, context-free grammars, … graph-based optimization algorithms, ... type theory, ... interesting algorithms that are applicable elsewhere pattern matching, natural language understanding, … challenging software development project help understanding programming languages why does C not have nested functions? “It is good for you.”

Why really study compilers today? Many tools use “little” languages! digraph finite_state_machine { rankdir=LR; size="8,5” node [shape = doublecircle]; LR_0 LR_3 LR_4 LR_8; node [shape = circle]; LR_0 -> LR_2 [ label = "SS(B)" ]; LR_0 -> LR_1 [ label = "SS(S)" ]; LR_1 -> LR_3 [ label = "S($end)" ]; LR_2 -> LR_6 [ label = "SS(b)" ]; LR_2 -> LR_5 [ label = "SS(a)" ]; LR_2 -> LR_4 [ label = "S(A)" ]; LR_5 -> LR_7 [ label = "S(b)" ]; LR_5 -> LR_5 [ label = "S(a)" ]; LR_6 -> LR_6 [ label = "S(b)" ]; LR_6 -> LR_5 [ label = "S(a)" ]; LR_7 -> LR_8 [ label = "S(b)" ]; LR_7 -> LR_5 [ label = "S(a)" ]; LR_8 -> LR_6 [ label = "S(b)" ]; LR_8 -> LR_5 [ label = "S(a)" ]; } all: hello hello: main.o factorial.o hello.o g++ main.o factorial.o hello.o -o hello main.o: main.cpp g++ -c main.cpp factorial.o: factorial.cpp g++ -c factorial.cpp hello.o: hello.cpp g++ -c hello.cpp clean: rm -rf *o hello You might write a “little” compiler!

Why really study compilers today? Many tools use program analysis techniques! smell detection program verification software visualization You might write a program analysis!

Why really study compilers today? Many tools use program transformation! model-driven engineering program verification refactoring You might write a program transformation!

Compiler-like tools: programs can be executed in different ways. Source Program Interpreter Bytecode Compiler Compiler Bytecode Bytecode Interpreter Machine Language

Compiler-like tools: programs can be interpreted in different ways. Source Program Interpreter Analyzer Transpiler Note: transpiler: translates from one high-level language to another (source-to-source translator) cross-compiler: runs on one machine but generates code for another machine Target Program

Compilers are split into phases. Source Program lexical “scanning” Compiler analysis syntax “parsing” Front end “semantic analysis” contextual “middle end” intermediate code Back end Bad example of phase dependency: C variable declarations [need to check] synthesis object code Machine Language ⇒ Phases simplify compiler structure

Compilers are split into many phases. We will look at red phases in some detail. [Appel, 2002]

Phases interact via data structures. Source Program text lexical tokens Compiler analysis syntax Front end (abstract) syntax tree contextual decorated AST + symbol table intermediate code Back end synthesis intermediate code object code Machine Language object code

Compiler construction methods stepwise construction composition cross-compilation bootstrapping compiler compilers: tools for compiler generation scanner (regular expressions) parser (context-free grammars) attribute evaluation (attribute grammars) code generator (code templates, tree patterns) interpreter (formal semantics)

T-diagrams T-diagrams abstractly visualize compilers: T-diagrams compose: I S → T source language target language implementation language (must eventually be a machine language M) I S → T J S → T = M I → J

Composition Given T1 , an I → M compiler in M, construct T2 as an S → M compiler in M. Solution: construct T0 as an S → M compiler in I apply T1 to T0 I S → M M S → M = M I → M T0 T2 T1

Composition Given T1 , an I → M compiler in M, construct T2 as an S → M compiler in M. Solution: construct T0 as an S → M compiler in I apply T1 to T0 I S → M M S → M M I → M T0 T2 T1

Cross compilation Given T1 , an S → M compiler in S, and T2 , an S → N compiler in N, construct T3 as an S → M compiler in M. Solution: apply T2 to T1 (on N), which yields a cross-compiler apply the cross-compiler to T1 again (also on N) S S → M M S → M S S → M N S → M N S → N

Bootstrapping

Bootstrapping

Course Organization

Learning objectives knowledge of the basic terms and concepts understanding of commonly used methods experience with compiler construction tools ability to learn new techniques as they emerge understanding of relation between language design and implementation You should be able to implement a program analysis or transformation tool!

Lecture Schedule (I) Introduction Lexical Analysis Compiler structure and phases, bootstrapping Course organization Lexical Analysis regex -> nfa -> dfa -> minimal dfa lexing process grep, awk, lex/jflex, Antlr, quex (not table driven), vlex (visualization)

Lecture Schedule (II) Parsing I: LL methods Parsing II: LR methods left-factorization, left-recursion elimination JavaCC, Antlr Parsing II: LR methods LR(0), SLR(1), LALR(1), LR(1) yacc Parsing III: Other parsing methods parser combinators GLL, (S)GLR, CYK, Tomita, Early

Lecture Schedule (III) Abstract Syntax Trees Antlr tree building templates Pretty printing box language Symbol tables and name binding NaBL Attribute evaluation inherited vs. synthesized attributes yacc, Antlr Language embeddings and IDEs staging, meta-programming Spoofax, MPS

Lecture Schedule (IV) Runtime data organization Intermediate code representation and generation stack machines, three-address code, IR trees, code generation templates Machine code generation IR tree tiling, register allocation BURG-like tools Optimization

Course organization slides and other material posted on course web page yes, to be done... weekly lectures (1-3 hours) incl. discussions about papers, problems, solutions, ... reading assignments original research papers, background material “learning by doing” install and use tools

Evaluation: Continuous assessment no final exam regular assignments “every week” each assignment counts the same mostly practical

Textbooks (I) A. V. Aho, M. S. Lam, R. Sethi & J. D. Ullman, Compilers: Principles, Techniques, and Tools (2nd edition), Addison-Wesley, 2007. In-depth textbook. Andrew W. Appel, Modern Compiler Implementation in Java (2nd edition), Cambridge University Press, 2002. More practical approach. S. Muchnick. Advanced Compiler Design and Implementation, Morgan Kaufmann, 1997. Focus on optimization techniques.

Textbooks (II) N. Wirth. Compiler Construction, Addison Wesley, 1996. Classical approach to building compilers manually. Available at www.ethoberon.ethz.ch/WirthPubl/CBEAll.pdf R. Mak. Writing Compilers and Interpreters (3rd edition), Wiley, 2009. Object-oriented approach to building compilers manually.

Textbooks (III) M. Voelter. DSL Engineering, 2013. Modern view of software language engineering. Available at www.dslbook.org M. Fowler. Domain-Specific Languages, Addison-Wesley, 2010. UML-y approach to software language engineering. T. Parr, The Definitive ANTLR Reference: Building Domain-Specific Languages, The Pragmatic Bookshelf, 2007. Handbook for widely used tool.