CSCI 3136 Principles of Programming Languages Summer 2013 Faculty - - PowerPoint PPT Presentation

csci 3136 principles of programming languages
SMART_READER_LITE
LIVE PREVIEW

CSCI 3136 Principles of Programming Languages Summer 2013 Faculty - - PowerPoint PPT Presentation

CSCI 3136 Principles of Programming Languages Summer 2013 Faculty of Computer Science Dalhousie University 1 / 62 Course Outline Introduction 2 / 62 Course Outline Introduction Programming language, History, Paradigms 3 / 62


slide-1
SLIDE 1

CSCI 3136 Principles of Programming Languages

Summer 2013

Faculty of Computer Science Dalhousie University

1 / 62

slide-2
SLIDE 2

Course Outline

  • Introduction

2 / 62

slide-3
SLIDE 3

Course Outline

  • Introduction
  • Programming language, History, Paradigms

3 / 62

slide-4
SLIDE 4

Course Outline

  • Introduction
  • Programming language, History, Paradigms
  • Implementation

4 / 62

slide-5
SLIDE 5

Course Outline

  • Introduction
  • Programming language, History, Paradigms
  • Implementation
  • Lexical analysis and automata theory
  • Syntactic Analysis and Context-Free Grammars
  • Semantic analysis
  • Names, scopes, and binding
  • Control flow
  • Data types and object-oriented programming
  • Specialized topics

5 / 62

slide-6
SLIDE 6

{calculate greatest common divisor} program gcd(input, output); var i, j : integer; begin read(i, j); while i <> j do if i > j then i := i - j else j := j - i; writeln(i); end.

slide-7
SLIDE 7

{calculate greatest common divisor} program gcd(input, output); var i, j : integer; begin read(i, j); while i <> j do if i > j then i := i - j else j := j - i; writeln(i); end.

slide-8
SLIDE 8

{calculate greatest common divisor} program gcd(input, output); var i, j : integer; begin read(i, j); while i <> j do if i > j then i := i - j else j := j - i; writeln(i); end.

slide-9
SLIDE 9

{calculate greatest common divisor} program gcd(input, output); var i, j : integer; begin read(i, j); while i <> j do if i > j then i := i - j else j := j - i; writeln(i); end.

slide-10
SLIDE 10

{calculate greatest common divisor} program gcd(input, output); var i, j : integer; begin read(i, j); while i <> j do if i > j then i := i - j else j := j - i; writeln(i); end.

slide-11
SLIDE 11

{calculate greatest common divisor} program gcd(input, output); var i, j : integer; begin read(i, j); while i <> j do if i > j then i := i - j else j := j - i; writeln(i); end.

slide-12
SLIDE 12

{calculate greatest common divisor} program gcd(input, output); var i, j : integer; begin read(i, j); while i <> j do if i > j then i := i - j else j := j - i; writeln(i); end.

Implementation

12 / 62

slide-13
SLIDE 13

Compiler/ Interpreter

{calculate greatest common divisor} program gcd(input, output); var i, j : integer; begin read(i, j); while i <> j do if i > j then i := i - j else j := j - i; writeln(i); end.

Implementation

13 / 62

slide-14
SLIDE 14
slide-15
SLIDE 15

Compilation

slide-16
SLIDE 16

Compiler Compilation

slide-17
SLIDE 17

Compiler Source Program Compilation

slide-18
SLIDE 18

Compiler Source Program Compilation Target Program

slide-19
SLIDE 19

Compiler Source Program Compilation Target Program Target Program

slide-20
SLIDE 20

Compiler Source Program Compilation Target Program Target Program Input

slide-21
SLIDE 21

Compiler Source Program Compilation Target Program Target Program Input Output

slide-22
SLIDE 22

Compiler Source Program Compilation Target Program Target Program Input Output Interpretation

slide-23
SLIDE 23

Compiler Source Program Compilation Target Program Target Program Input Output Interpreter Interpretation

slide-24
SLIDE 24

Compiler Source Program Compilation Target Program Target Program Input Output Interpreter Source Program Interpretation

slide-25
SLIDE 25

Compiler Source Program Compilation Target Program Target Program Input Output Interpreter Source Program Interpretation Input

slide-26
SLIDE 26

Compiler Source Program Compilation Target Program Target Program Input Output Interpreter Source Program Interpretation Input Output

26 / 62

slide-27
SLIDE 27

Implementation Strategies: Example

Virtual machine

slide-28
SLIDE 28

Implementation Strategies: Example

Virtual machine Translator Source Program Intermediate Program Virtual Machine Intermediate Program Input Output

28 / 62

slide-29
SLIDE 29

Implementation Strategies: Example

Linker

slide-30
SLIDE 30

Implementation Strategies: Example

Linker

Incomplete Machine Language Compiler Source Program Linker Incomplete Machine Language Library Routines Machine Language Program

30 / 62

slide-31
SLIDE 31

Implementation Strategies: Example

The Preprocessor

slide-32
SLIDE 32

Implementation Strategies: Example

The Preprocessor Preprocessor Source Program Modified Source Pro- gram Compiler Modified Source Program Assembly Language

32 / 62

slide-33
SLIDE 33

Implementation Strategies: Example

Source-to-Source Translation (C++)

slide-34
SLIDE 34

Implementation Strategies: Example

Source-to-Source Translation (C++) Preprocessor Source Program Modified Source Program C++ compiler Modified Source Program C code C compiler C code Assembly Language

34 / 62

slide-35
SLIDE 35

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Machine-independent Code Improvement (Optional) Target Code Generation Machine-specific Code Im- provement (Optional) Parser (syntactic analysis) Scanner (lexical analysis) Character Stream Token Stream Parse Tree Abstract Syntax Tree or Other Intermediate Form Modified Intermediate Form Target Language (e.g., assembly) Modified Target Language Symbol Table

35 / 62

slide-36
SLIDE 36

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Machine-independent Code Improvement (Optional) Target Code Generation Machine-specific Code Im- provement (Optional) Parser (syntactic analysis) Scanner (lexical analysis) Character Stream Token Stream Parse Tree Abstract Syntax Tree or Other Intermediate Form Modified Intermediate Form Target Language (e.g., assembly) Modified Target Language Symbol Table

36 / 62

slide-37
SLIDE 37

Phases of Compilation

slide-38
SLIDE 38

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Parser (syntactic analysis) Scanner (lexical analysis)

slide-39
SLIDE 39

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Parser (syntactic analysis) Scanner (lexical analysis) Character Stream

slide-40
SLIDE 40

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Parser (syntactic analysis) Scanner (lexical analysis) Character Stream Token Stream

slide-41
SLIDE 41

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Parser (syntactic analysis) Scanner (lexical analysis) {calculate greatest common divisor} program gcd(input, output); var i, j : integer; begin read(i, j); while i <> j do if i > j then i := i - j else j := j - i; writeln(i); end.

slide-42
SLIDE 42

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Parser (syntactic analysis) Scanner (lexical analysis) {calculate greatest common divisor} program gcd(input, output); var i, j : integer; begin read(i, j); while i <> j do if i > j then i := i - j else j := j - i; writeln(i); end.

slide-43
SLIDE 43

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Parser (syntactic analysis) Scanner (lexical analysis) {calculate greatest common divisor} program gcd(input, output); var i, j : integer; begin read(i, j); while i <> j do if i > j then i := i - j else j := j - i; writeln(i); end. {calculate greatest common divisor} program gcd ( input ,

  • utput

) ; var i , j : integer ; begin read ( i , j ) ; while i <> j do if i > j then i := i

  • j

else j := j

  • i

; writeln ( i ) ; end .

slide-44
SLIDE 44

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Parser (syntactic analysis) Scanner (lexical analysis) {calculate greatest common divisor} program gcd(input, output); var i, j : integer; begin read(i, j); while i <> j do if i > j then i := i - j else j := j - i; writeln(i); end. {calculate greatest common divisor} program gcd ( input ,

  • utput

) ; var i , j : integer ; begin read ( i , j ) ; while i <> j do if i > j then i := i

  • j

else j := j

  • i

; writeln ( i ) ; end .

  • Remove comments
slide-45
SLIDE 45

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Parser (syntactic analysis) Scanner (lexical analysis) {calculate greatest common divisor} program gcd(input, output); var i, j : integer; begin read(i, j); while i <> j do if i > j then i := i - j else j := j - i; writeln(i); end. {calculate greatest common divisor} program gcd ( input ,

  • utput

) ; var i , j : integer ; begin read ( i , j ) ; while i <> j do if i > j then i := i

  • j

else j := j

  • i

; writeln ( i ) ; end .

  • Remove comments
  • Remove extraneous

characters

slide-46
SLIDE 46

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Parser (syntactic analysis) Scanner (lexical analysis) {calculate greatest common divisor} program gcd(input, output); var i, j : integer; begin read(i, j); while i <> j do if i > j then i := i - j else j := j - i; writeln(i); end. {calculate greatest common divisor} program gcd ( input ,

  • utput

) ; var i , j : integer ; begin read ( i , j ) ; while i <> j do if i > j then i := i

  • j

else j := j

  • i

; writeln ( i ) ; end .

  • Remove comments
  • Remove extraneous

characters

slide-47
SLIDE 47

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Parser (syntactic analysis) Scanner (lexical analysis) {calculate greatest common divisor} program gcd(input, output); var i, j : integer; begin read(i, j); while i <> j do if i > j then i := i - j else j := j - i; writeln(i); end. {calculate greatest common divisor} program gcd ( input ,

  • utput

) ; var i , j : integer ; begin read ( i , j ) ; while i <> j do if i > j then i := i

  • j

else j := j

  • i

; writeln ( i ) ; end .

  • Remove comments
  • Remove extraneous

characters

slide-48
SLIDE 48

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Parser (syntactic analysis) Scanner (lexical analysis) {calculate greatest common divisor} program gcd(input, output); var i, j : integer; begin read(i, j); while i <> j do if i > j then i := i - j else j := j - i; writeln(i); end. {calculate greatest common divisor} program gcd ( input ,

  • utput

) ; var i , j : integer ; begin read ( i , j ) ; while i <> j do if i > j then i := i

  • j

else j := j

  • i

; writeln ( i ) ; end .

  • Remove comments
  • Remove extraneous

characters

slide-49
SLIDE 49

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Parser (syntactic analysis) Scanner (lexical analysis) {calculate greatest common divisor} program gcd(input, output); var i, j : integer; begin read(i, j); while i <> j do if i > j then i := i - j else j := j - i; writeln(i); end. {calculate greatest common divisor} program gcd ( input ,

  • utput

) ; var i , j : integer ; begin read ( i , j ) ; while i <> j do if i > j then i := i

  • j

else j := j

  • i

; writeln ( i ) ; end .

  • Remove comments
  • Remove extraneous

characters

  • Group input

characters into tokens

49 / 62

slide-50
SLIDE 50

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Machine-independent Code Improvement (Optional) Target Code Generation Machine-specific Code Im- provement (Optional) Parser (syntactic analysis) Scanner (lexical analysis) Character Stream Token Stream Parse Tree Abstract Syntax Tree or Other Intermediate Form Modified Intermediate Form Target Language (e.g., assembly) Modified Target Language Symbol Table

50 / 62

slide-51
SLIDE 51

51 / 62

slide-52
SLIDE 52

Phases of Compilation

slide-53
SLIDE 53

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Parser (syntactic analysis) Parser (syntactic analysis)

slide-54
SLIDE 54

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Parser (syntactic analysis) Parser (syntactic analysis) Token Stream

slide-55
SLIDE 55

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Parser (syntactic analysis) Parser (syntactic analysis) Token Stream Parse Tree

slide-56
SLIDE 56

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Parser (syntactic analysis) Parser (syntactic analysis) {calculate greatest common divisor} program gcd ( input ,

  • utput

) ; var i , j : integer ; begin read ( i , j ) ; while i <> j do if i > j then i := i

  • j

else j := j

  • i

; writeln ( i ) ; end .

slide-57
SLIDE 57

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Parser (syntactic analysis) Parser (syntactic analysis) {calculate greatest common divisor} program gcd ( input ,

  • utput

) ; var i , j : integer ; begin read ( i , j ) ; while i <> j do if i > j then i := i

  • j

else j := j

  • i

; writeln ( i ) ; end .

slide-58
SLIDE 58

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Parser (syntactic analysis) Parser (syntactic analysis) {calculate greatest common divisor} program gcd ( input ,

  • utput

) ; var i , j : integer ; begin read ( i , j ) ; while i <> j do if i > j then i := i

  • j

else j := j

  • i

; writeln ( i ) ; end .

58 / 62

slide-59
SLIDE 59

59 / 62

slide-60
SLIDE 60

Phases of Compilation

Semantic Analysis and Inter- mediate Code Generation Machine-independent Code Improvement (Optional) Target Code Generation Machine-specific Code Im- provement (Optional) Parser (syntactic analysis) Scanner (lexical analysis) Character Stream Token Stream Parse Tree Abstract Syntax Tree or Other Intermediate Form Modified Intermediate Form Target Language (e.g., assembly) Modified Target Language Symbol Table

60 / 62

slide-61
SLIDE 61

61 / 62

slide-62
SLIDE 62

62 / 62