CS321 Languages and Compiler Design I. Winter 2012 Lecture 1

Similar documents
CS558 Programming Languages

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

CS558 Programming Languages

Compilers. Prerequisites

Compiler Construction

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

CMPT 379 Compilers. Anoop Sarkar.

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100

Introduction to Scientific Computing Languages

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

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

Principles of Programming Languages. Lecture Outline

Introduction to Scientific Computing Languages

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

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

Concepts of Programming Languages

CS558 Programming Languages. Winter 2013 Lecture 1

Intermediate Code Generation

Undergraduate Compilers in a Day

Compiler Construction

Outline. Lecture 17: Putting it all together. Example (input program) How to make the computer understand? Example (Output assembly code) Fall 2002

Why are there so many programming languages?

Principles of Compiler Design

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILING

Lecture 31: Building a Runnable Program

CS558 Programming Languages

Compiler Construction

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

Com S 541. Programming Languages I

Compiler Construction

Compiler Construction

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

Compiler Construction

CSCI B522 Lecture 11 Naming and Scope 8 Oct, 2009

CS558 Programming Languages. Winter 2013 Lecture 3

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

! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented

LECTURE NOTES ON COMPILER DESIGN P a g e 2

Languages and Compiler Design II IR Code Optimization

Compiler Construction

Programming Languages, Summary CSC419; Odelia Schwartz

Chapter 1. Preliminaries

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.

Chapter 1 Preliminaries

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

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking

Introduction. Compilers and Interpreters

Administration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator

Where We Are. Lexical Analysis. Syntax Analysis. IR Generation. IR Optimization. Code Generation. Machine Code. Optimization.

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

Compiler Construction

Program Abstractions, Language Paradigms. CS152. Chris Pollett. Aug. 27, 2008.

1 Lexical Considerations

Chapter 1: Why Program? Main Hardware Component Categories 8/23/2014. Main Hardware Component Categories: Why Program?

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

COMPILER DESIGN LECTURE NOTES

CS 415 Midterm Exam Spring SOLUTION

From High Level to Machine Code. Compilation Overview. Computer Programs

MidTerm Papers Solved MCQS with Reference (1 to 22 lectures)


COP 3402 Systems Software. Lecture 4: Compilers. Interpreters

Programming Languages

Lecture 1: Course Introduction

CS606- compiler instruction Solved MCQS From Midterm Papers

CS101 Introduction to Programming Languages and Compilers

Compilers and Interpreters

Structure of a compiler. More detailed overview of compiler front end. Today we ll take a quick look at typical parts of a compiler.

Parsing Scheme (+ (* 2 3) 1) * 1

Computer Components. Software{ User Programs. Operating System. Hardware

Chapter 1: Introduction to Computers and Programming

A simple syntax-directed

Chapter 1. Preliminaries

CS 565: Programming Languages. Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106

1DL321: Kompilatorteknik I (Compiler Design 1) Introduction to Programming Language Design and to Compilation

Compiler Design Spring 2018

1DL321: Kompilatorteknik I (Compiler Design 1)

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

Compilation I. Hwansoo Han

INF 212 ANALYSIS OF PROG. LANGS ELEMENTS OF IMPERATIVE PROGRAMMING STYLE. Instructors: Crista Lopes Copyright Instructors.

CS321 Languages and Compiler Design I. Winter 2012 Lecture 4

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS

Compiler Design 1. Introduction to Programming Language Design and to Compilation

CS321 Languages and Compiler Design I Winter 2012 Lecture 13

CS5363 Final Review. cs5363 1

NOTE: Answer ANY FOUR of the following 6 sections:

Software II: Principles of Programming Languages

Pioneering Compiler Design

CST-402(T): Language Processors

SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms

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

Compilers. Pierre Geurts

CS 242. Fundamentals. Reading: See last slide

Announcements. My office hours are today in Gates 160 from 1PM-3PM. Programming Project 3 checkpoint due tomorrow night at 11:59PM.

1DL321: Kompilatorteknik I (Compiler Design 1) Introduction to Programming Language Design and to Compilation

CS 415 Midterm Exam Spring 2002

Where we are. What makes a good IR? Intermediate Code. CS 4120 Introduction to Compilers

LECTURE 18. Control Flow

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

Question Bank. 10CS63:Compiler Design

Introduction to Compiler Design

Transcription:

CS321 Languages and Compiler Design I Winter 2012 Lecture 1 1

COURSE GOALS Improve understanding of languages and machines. Learn practicalities of translation. Learn anatomy of programming languages. Apply computer science theory to practical problems (using tools). Do large programming project. PSU CS321 W 12 LECTURE 1 c 1992 2012 ANDREW TOLMACH 2

COMPILERS A compiler is a translator from high-level language to assembly code/object language. Language L TRANSLATOR Language L Examples of translators: Pascal,C, etc. Compiler Machine Code Java Compiler Byte Code Ratfor Preprocessor Fortran Tex Text Formatter Postscript SQL DB Optimizer Query plan We study common features of translators, by building one. PSU CS321 W 12 LECTURE 1 c 1992 2012 ANDREW TOLMACH 3

LANGUAGE DESIGN We study languages mainly from an implementor s viewpoint. How do compilation feasibility and runtime efficiency affect language design? (There are more theoretical approaches to studying programming languages, and there are interesting and useful languages that don t compile easily...) PSU CS321 W 12 LECTURE 1 c 1992 2012 ANDREW TOLMACH 4

VON NEUMANN MACHINE load store arith/logic compare jump i/o Program counter (PC) Control Store instr instr instr instr operator Registers r1 r2 r3 r4 args Data Store 0 1 2 3 rn m-1 m PSU CS321 W 12 LECTURE 1 c 1992 2012 ANDREW TOLMACH 5

FEATURES OF LOW-LEVEL CODE Sequential control flow + labels + jumps Small set of built-in data types and operators (e.g., byte, integer, floating point) Flat linear address space. Memory hierarchy (registers faster than memory faster than disk). PSU CS321 W 12 LECTURE 1 c 1992 2012 ANDREW TOLMACH 6

HIGH-LEVEL LANGUAGES E.g., Fortran, Pascal, C, Cobol, Java, JavaScript, Python... Example func rev (a: @real, n:int) { var i := 0; var j := n - 1; while i < j do { var x := a[i]; a[i] := a[j]; a[j] := x; i := i + 1; j := j - 1 } } PSU CS321 W 12 LECTURE 1 c 1992 2012 ANDREW TOLMACH 7

FEATURES OF HIGH-LEVEL CODE Expressions (arithmetic, logical) Control structures (loops, conditionals, etc.) Type declarations and type checking Composite types (arrays, records, etc.) Procedures/Functions, with private scope Abstraction facilities! PSU CS321 W 12 LECTURE 1 c 1992 2012 ANDREW TOLMACH 8

MEETING IN THE MIDDLE How can we make high-level language run on a Von Neumann machine? Answer: Translate HLL into lower-level code (in traditional compiler, to machine code.) and/or Build a higher level virtual machine (in traditional interpreter, perhaps a stack machine.) In practice, we do some of both, even in a compiler, since generated machine code makes use of a runtime library and operating system. PSU CS321 W 12 LECTURE 1 c 1992 2012 ANDREW TOLMACH 9

COMPILER STRUCTURE: WANT SIMPLICITY AND FLEXIBILITY Symbol Management Error Handling Source Code Lexical Analysis Tokens "Front End" (Language dependent) Syntax Analysis (& "Semantic Analysis") "Parse Trees" Intermediate Code Generation CS321 CS322 Interpreter I. R. (Bytecode, Trees, etc.) "Back End" (Machine dependent) Code Optimization I.R. Code Generation Assembly/Object Code PSU CS321 W 12 LECTURE 1 c 1992 2012 ANDREW TOLMACH 10

FRONT-END EXAMPLE Source characters: if (a <= b[i]) a := 4.5 ; Lexical Analysis "linear" Theory: regular languages, FAs Tools: lex,jflex, etc. Token stream: IF ( (ID a) LE (ID b) [ (ID i) ] ) (ID a) ASSGN (FCONST 4.5) ; Syntax Analysis "hierarchical" Theory: context free languages, PDA s Tools: yacc, javacup, jacc, etc. Parse tree: (real or conceptual) statement IF THEN predicate statement <= ASSIGN expr expr var expr ID a array lookup ID a const var ID b expr ID i FCONST 4.5 PSU CS321 W 12 LECTURE 1 c 1992 2012 ANDREW TOLMACH 11

LANGUAGE DEFINITION Syntax is easy. Well-understood. Good theory: regular and context-free languages and automata. Good tools, even for complex cases. Semantics are hard. Inherently complex. Variety of choices: Informal Reference Manual Operational Definitional interpreter ( we will focus here) Axiomatic Logic Denotational Mathematical functions etc. Few tools. PSU CS321 W 12 LECTURE 1 c 1992 2012 ANDREW TOLMACH 12