69
Course Introduction Lecture 1 Kevin Leach January 4, 2018

Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Course IntroductionLecture 1

Kevin Leach

January 4, 2018

Page 2: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Course IntroductionLecture 1

Compilers, what a concept

Kevin Leach

January 4, 2018

Page 3: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Cunning Plan

É AdministriviaÉ Compilers overviewÉ Compilation exampleÉ Course motivationÉ Course overview

Compiler Construction 2/40

Page 4: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Course Information

É Instructor: Kevin Leach ⟨[email protected]⟩É Please put EECS483 in the subject (or just use Piazza)

É Office Hours: TBA (see Piazza, prefer Thursday)É Meeting Time: MW 2:00–3:30, EECS 1311

É Bonus Discussion: F: 12:00–1:00, FXB 1012É Books (optional)

É Programming Language Pragmaticsby Michael Scott

É Compilers: Principles, Techniques, and Toolsby Alred Aho et al., a.k.a. the Dragon Book

Compiler Construction 3/40

Page 5: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É
Page 6: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

What is a compiler?

The thing Eclipse runs when you hit ‘Play’?

Compiler Construction 5/40

Page 7: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

What is a compiler?

...then you add try/catch to make the red go away?

Compiler Construction 6/40

Page 8: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

What is a compiler?

A tool that turns your C code into segfaults?

Compiler Construction 7/40

Page 9: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

What is a compiler?

A tool that turns your C code into segfaults?

Compiler Construction 7/40

Page 10: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

What is a compiler?

A tool that turns your C code into segfaults?

Compiler Construction 7/40

Page 11: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

What is a compiler?

A program that produces incomprehensible warnings?

Compiler Construction 8/40

Page 12: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

What is a compiler?

É A language processing toolÉ Input in one language is transformed to an equivalent output

in another language

Structured Input Structured Output

Source Code

firefox.c firefox.exegcc -o firefox.exe firefox.c

Compiler Program

Compiler Construction 9/40

Page 13: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compiler Workflow

É Goal Developer can access language featuresÉ Object-oriented paradigms (classes)

É Polymorphism (Cat inherits Animal)É Variables (human-readable naming)É Functional paradigms (functions and immutable state)É Data types (int/string/char)É Control flow (if/then/else)

É Constraint fast execution on native platform (e.g., x86 CPU)

É Need to “remove” features so that a CPU circuit can understand

Compiler Construction 10/40

Page 14: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compiler Workflow

É Goal Developer can access language featuresÉ Object-oriented paradigms (classes)É Polymorphism (Cat inherits Animal)

É Variables (human-readable naming)É Functional paradigms (functions and immutable state)É Data types (int/string/char)É Control flow (if/then/else)

É Constraint fast execution on native platform (e.g., x86 CPU)

É Need to “remove” features so that a CPU circuit can understand

Compiler Construction 10/40

Page 15: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compiler Workflow

É Goal Developer can access language featuresÉ Object-oriented paradigms (classes)É Polymorphism (Cat inherits Animal)É Variables (human-readable naming)

É Functional paradigms (functions and immutable state)É Data types (int/string/char)É Control flow (if/then/else)

É Constraint fast execution on native platform (e.g., x86 CPU)

É Need to “remove” features so that a CPU circuit can understand

Compiler Construction 10/40

Page 16: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compiler Workflow

É Goal Developer can access language featuresÉ Object-oriented paradigms (classes)É Polymorphism (Cat inherits Animal)É Variables (human-readable naming)É Functional paradigms (functions and immutable state)

É Data types (int/string/char)É Control flow (if/then/else)

É Constraint fast execution on native platform (e.g., x86 CPU)

É Need to “remove” features so that a CPU circuit can understand

Compiler Construction 10/40

Page 17: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compiler Workflow

É Goal Developer can access language featuresÉ Object-oriented paradigms (classes)É Polymorphism (Cat inherits Animal)É Variables (human-readable naming)É Functional paradigms (functions and immutable state)É Data types (int/string/char)

É Control flow (if/then/else)

É Constraint fast execution on native platform (e.g., x86 CPU)

É Need to “remove” features so that a CPU circuit can understand

Compiler Construction 10/40

Page 18: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compiler Workflow

É Goal Developer can access language featuresÉ Object-oriented paradigms (classes)É Polymorphism (Cat inherits Animal)É Variables (human-readable naming)É Functional paradigms (functions and immutable state)É Data types (int/string/char)É Control flow (if/then/else)

É Constraint fast execution on native platform (e.g., x86 CPU)

É Need to “remove” features so that a CPU circuit can understand

Compiler Construction 10/40

Page 19: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compiler Workflow

É Goal Developer can access language featuresÉ Object-oriented paradigms (classes)É Polymorphism (Cat inherits Animal)É Variables (human-readable naming)É Functional paradigms (functions and immutable state)É Data types (int/string/char)É Control flow (if/then/else)

É Constraint fast execution on native platform (e.g., x86 CPU)

É Need to “remove” features so that a CPU circuit can understand

Compiler Construction 10/40

Page 20: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compiler Workflow

É Goal Developer can access language featuresÉ Object-oriented paradigms (classes)É Polymorphism (Cat inherits Animal)É Variables (human-readable naming)É Functional paradigms (functions and immutable state)É Data types (int/string/char)É Control flow (if/then/else)

É Constraint fast execution on native platform (e.g., x86 CPU)É Need to “remove” features so that a CPU circuit can understand

Compiler Construction 10/40

Page 21: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compiler Input

É Input is structuredÉ Amenable to automated analysis and processingÉ Developer can write a specification for program behavior

É This class: Use COOL programming language

Compiler Construction 11/40

Page 22: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compiler Input

É The compiler gives a promise to developer:If you supply a valid program according to the language’s rules,the compiler provides a valid assembly output

É Implication: Developer promises to provide valid programÉ If they don’t, compiler gets to complain!

Compiler Construction 12/40

Page 23: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compiler Input

É The compiler gives a promise to developer:If you supply a valid program according to the language’s rules,the compiler provides a valid assembly outputÉ Implication: Developer promises to provide valid program

É If they don’t, compiler gets to complain!

Compiler Construction 12/40

Page 24: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compiler Input

É The compiler gives a promise to developer:If you supply a valid program according to the language’s rules,the compiler provides a valid assembly outputÉ Implication: Developer promises to provide valid programÉ If they don’t, compiler gets to complain!

Compiler Construction 12/40

Page 25: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compiler Output

É Output is also structuredÉ Windows PE, Linux ELF, etc...É Usually a lowered format

É This class: Produce assembly (either RISC or x86)

Compiler Construction 13/40

Page 26: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compiler Output

Compiler performssemantics preserving

transformations

Compiler Construction 14/40

Page 27: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Issues Guiding Compiler Design

É CorrectnessÉ Compiler performs semantics-preserving transformations

É SpeedÉ Run timeÉ Compilation time

É SpaceÉ How large is the output?

É Feedback to userÉ On a scale of LaTex to Python, how good is your feedback?

ÉDebuggingÉ Can your output help the developer identify problems with

their desired program?

Compiler Construction 15/40

Page 28: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Issues Guiding Compiler Design

É CorrectnessÉ Compiler performs semantics-preserving transformations

É SpeedÉ Run timeÉ Compilation time

É SpaceÉ How large is the output?

É Feedback to userÉ On a scale of LaTex to Python, how good is your feedback?

ÉDebuggingÉ Can your output help the developer identify problems with

their desired program?

Compiler Construction 15/40

Page 29: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Issues Guiding Compiler Design

É CorrectnessÉ Compiler performs semantics-preserving transformations

É SpeedÉ Run timeÉ Compilation time

É SpaceÉ How large is the output?

É Feedback to userÉ On a scale of LaTex to Python, how good is your feedback?

ÉDebuggingÉ Can your output help the developer identify problems with

their desired program?

Compiler Construction 15/40

Page 30: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Issues Guiding Compiler Design

É CorrectnessÉ Compiler performs semantics-preserving transformations

É SpeedÉ Run timeÉ Compilation time

É SpaceÉ How large is the output?

É Feedback to userÉ On a scale of LaTex to Python, how good is your feedback?

ÉDebuggingÉ Can your output help the developer identify problems with

their desired program?

Compiler Construction 15/40

Page 31: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Issues Guiding Compiler Design

É CorrectnessÉ Compiler performs semantics-preserving transformations

É SpeedÉ Run timeÉ Compilation time

É SpaceÉ How large is the output?

É Feedback to userÉ On a scale of LaTex to Python, how good is your feedback?

ÉDebuggingÉ Can your output help the developer identify problems with

their desired program?

Compiler Construction 15/40

Page 32: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compilers vs. Interpreters

É Compilers lower code to assemblyÉ A compiler produces a program that runs later (e.g., after

compilation)

É Interpreters directly execute the code providedÉ Common in scripting languages

É Just-in-time compilation?É Secretly, languages like Python, Lua, and Java are all compiled at

runtime!

É Why would you compile vs. interpret?

Compiler Construction 16/40

Page 33: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compilers vs. Interpreters

É Compilers lower code to assemblyÉ A compiler produces a program that runs later (e.g., after

compilation)É Interpreters directly execute the code provided

É Common in scripting languages

É Just-in-time compilation?É Secretly, languages like Python, Lua, and Java are all compiled at

runtime!

É Why would you compile vs. interpret?

Compiler Construction 16/40

Page 34: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compilers vs. Interpreters

É Compilers lower code to assemblyÉ A compiler produces a program that runs later (e.g., after

compilation)É Interpreters directly execute the code provided

É Common in scripting languages

É Just-in-time compilation?É Secretly, languages like Python, Lua, and Java are all compiled at

runtime!

É Why would you compile vs. interpret?

Compiler Construction 16/40

Page 35: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compilers vs. Interpreters

É Compilers lower code to assemblyÉ A compiler produces a program that runs later (e.g., after

compilation)É Interpreters directly execute the code provided

É Common in scripting languages

É Just-in-time compilation?É Secretly, languages like Python, Lua, and Java are all compiled at

runtime!

É Why would you compile vs. interpret?

Compiler Construction 16/40

Page 36: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Stages of Compilation

É Compilers are well-established

Input Code (Cool Language)

Tokenization (Lexical Analysis)

Parser (Syntactic Analysis)

Semantic Analysis

Code Generation

Optimization

Output Code (assembly)

Compiler Construction 17/40

Page 37: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Front End vs. Back End

É Lexing, Parsing, and Type-checking are the front endÉ Code generation and optimization are the back end

É Modularity

Compiler Construction 18/40

Page 38: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Front End vs. Back End

É Lexing, Parsing, and Type-checking are the front endÉ Code generation and optimization are the back endÉ Modularity

Compiler Construction 18/40

Page 39: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compiling by Analogy

É We’re going to make an English compiler.É It will turn English into Spanish.

É Example InputI enjoy compilers.É Example Output

Yo disfruto compiladores.

É Compiling is a 5 step processÉ Each step takes an input and creates an intermediate

representation

Compiler Construction 19/40

Page 40: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compiling by Analogy

É We’re going to make an English compiler.É It will turn English into Spanish.

É Example InputI enjoy compilers.É Example Output

Yo disfruto compiladores.

É Compiling is a 5 step processÉ Each step takes an input and creates an intermediate

representation

Compiler Construction 19/40

Page 41: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

1: Tokenization or Lexical Analysis

É Break input into tokens and lexemes that are part of thelanguage’s lexicon

keywords (if, while) operators (+, -)variable names constants (“hello, world”, 1, 0x40)

É English tokens = words

Valid Inputs Invalid Input

I am handsome. 我很帅。He is pony. Èl es poni.

Output is a list of lexemes and tokens.“I am handsome.” → “I”, “am”, “handsome”, “.”

Compiler Construction 20/40

Page 42: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

1: Tokenization or Lexical Analysis

É Break input into tokens and lexemes that are part of thelanguage’s lexicon

keywords (if, while) operators (+, -)variable names constants (“hello, world”, 1, 0x40)

É English tokens = words

Valid Inputs Invalid Input

I am handsome. 我很帅。He is pony. Èl es poni.

Output is a list of lexemes and tokens.“I am handsome.” → “I”, “am”, “handsome”, “.”

Compiler Construction 20/40

Page 43: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

2: Parsing or Syntactic Analysis

É Ensure tokens follow the rules of a grammarÉ + operator should have expressions on both sides...

2 + 3; Ø 2 + ; 7

É English parsing = is it grammatically correct?

Valid Input Invalid Input

I am handsome. I handsome am:I be short. Is he correct!!

Output is a parse tree or abstract syntax tree (on board).

Compiler Construction 21/40

Page 44: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

3: Semantic Analysis (type checking)É Ensure input makes sense

É Does it make sense to add strings to integers?

É English = Does it make sense?Valid Input Invalid Input

I am handsome. I am short.College is expensive. I am rich.

Output is an annotated abstract syntax tree (AST, on board)

Compiler Construction 22/40

Page 45: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

4: Code Generation

É Create code that exhibits the required behaviorÉ let x <- 2 + 3 becomes add t0 <- 2, 3

É English/Spanish example: Start generating Spanish

Input Output

I am handsome. Yo soy guapo.

Output is straight-line assembly code

Compiler Construction 23/40

Page 46: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

5: Optimization

É Analyze generated code, change it to execute fasterÉ let x <- 2 + 3 becomes li t0 <- 5

É English/Spanish example: Remove superfluous words

Input Output

Yo soy guapo. Soy guapo.Output is optimized straight-line assembly code

Compiler Construction 24/40

Page 47: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compilers Today

É Early on: Lexing, Parsing most complex and expensive

É Today: optimization dominates everything many times over,both in execution time and community interestÉ Scientific programsÉ Advanced processors (DSP, speculative execution)É Small devices (speed =more time idle = longer battery)

É We will not focus on lexing/parsing optimizations

É Support for languages with new featuresÉ MIMD architectures

Compiler Construction 25/40

Page 48: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compilers Today

É Early on: Lexing, Parsing most complex and expensive

É Today: optimization dominates everything many times over,both in execution time and community interestÉ Scientific programsÉ Advanced processors (DSP, speculative execution)É Small devices (speed =more time idle = longer battery)

É We will not focus on lexing/parsing optimizations

É Support for languages with new featuresÉ MIMD architectures

Compiler Construction 25/40

Page 49: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Who cares?

Many upper-level electives correspond to a natural job choice

É Databases→OracleÉ Embedded Computing→ SamsungÉ E-commerce→ AmazonÉ Graphics→Nvidia

É What about compilers?

Compiler Construction 26/40

Page 50: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Who cares?Many upper-level electives correspond to a natural job choice

É Databases→OracleÉ Embedded Computing→ SamsungÉ E-commerce→ AmazonÉ Graphics→Nvidia

É What about compilers?

Compiler Construction 26/40

Page 51: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Microsoft

É Visual Studio!

Compiler Construction 27/40

Page 52: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Oracle

É Java!

Compiler Construction 28/40

Page 53: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Intel

É ICC!

Compiler Construction 29/40

Page 54: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Google

É Go, Dart, etc.

Compiler Construction 30/40

Page 55: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Wind River, Green Hills

É Embedded!

Mars rover, cell phones, satellites, engine controllers, jets, cameras,game consoles...

Compiler Construction 31/40

Page 56: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Adobe

É Photoshop contains interpreters...

Compiler Construction 32/40

Page 57: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

The list goes on

É Mozilla’s SpiderMonkey JS EngineÉ Unreal Engine Blueprints ScriptingÉ Cadence HSPICE Circuit simulation language

Compiler Construction 33/40

Page 58: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

What About This Class?

É You will turn in pieces of a compiler

É Compilers are large software systemsÉ This is a challenging project that will require significant

planning and developing multiple integrated components

É Former students contend it is very worthwhile

Compiler Construction 34/40

Page 59: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

What About This Class?

É You will turn in pieces of a compilerÉ Compilers are large software systems

É This is a challenging project that will require significantplanning and developing multiple integrated components

É Former students contend it is very worthwhile

Compiler Construction 34/40

Page 60: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

What About This Class?

É You will turn in pieces of a compilerÉ Compilers are large software systems

É This is a challenging project that will require significantplanning and developing multiple integrated components

É Former students contend it is very worthwhile

Compiler Construction 34/40

Page 61: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Course Expectations

É Short version: Students will deliver a compilerÉ There are 6 assignments to help you progress towards this end

1. PA1 Toposort implementation2. PA2 Lexical Analyzer3. PA3 Syntactic Analyzer4. PA4 Semantic Analyzer5. PA5 Compiler6. PA6 Optimizing compiler (extra credit)

É N.B. Assignments are time-consuming. Start Early

Compiler Construction 35/40

Page 62: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Course Expectations

É Short version: Students will deliver a compilerÉ There are 6 assignments to help you progress towards this end

1. PA1 Toposort implementation2. PA2 Lexical Analyzer3. PA3 Syntactic Analyzer4. PA4 Semantic Analyzer5. PA5 Compiler6. PA6 Optimizing compiler (extra credit)

É N.B. Assignments are time-consuming. Start Early

Compiler Construction 35/40

Page 63: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Late policy

É Assignments turned in will be penalized by 1% per hourÉ 48 hours late = 48% off that assignment

Compiler Construction 36/40

Page 64: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Exams

É Two midterms, one final examÉ 10% each, 15% for final

É You can have one page of notes, front and backÉ Closed test otherwise

É Let me know as early as possible about conflicts

Compiler Construction 37/40

Page 65: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Academic Honesty

É Please don’t cheatÉ We often use plagiarism detection software

É Ample resources available!

Compiler Construction 38/40

Page 66: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Academic Honesty

É Please don’t cheatÉ We often use plagiarism detection software

É Ample resources available!

Compiler Construction 38/40

Page 67: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Course Resources

É This course is based on Stanford’s Compilers course

Compiler Construction 39/40

Page 68: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Homework 1É Write a short (50-100) line program in two languages: Cool and

OCamlÉ First implementation in your favorite language (PA1c) due

1/10!É Both implementations in your language+Cool (PA1) due 1/17!

Compiler Construction 40/40

Page 69: Course Introduction - Lecture 1kjleach.eecs.umich.edu/c18/l1.pdflanguage’s lexicon keywords (if, while) operators (+, -) variable names constants (“hello, world”, 1, 0x40) É

Compiler Construction 40/40