abstract data types Day! Language - University of Calgary...

6
02/23/2010 CPSC 449 Computer Science Unless otherwise noted, all artwork and illustrations by either Rob Kremer or Jörg Denzinger (course instructors) Language 13 Semantics Parsing Grammar Syntax Compiler Interpreter ? λ-Calculus SLD-Resolution abstract data types loops Error handling 2016/01/05 CPSC 449 Human Languages 14 Babel, many years ago Good Day! Guten Tag! Bon Jour! 2016/01/05 CPSC 449 Language: definition Language: 1 a: the words, their pronunciation, and the methods of combining them used and understood by a large group of people b (1): audible, articulate, and meaningful sound as produced by the action of the vocal organs (2): a systematic means of communicating ideas by signs or marks with understood meanings (sign language) 15 2016/01/05 CPSC 449 Language: definition (cont.) 2 a: form or manner of verbal expression; esp. STYLE (forceful language) b: the words and expressions of a particular group or field (the language of medicine) 3: the study of language especially as a school subject (Old French, from langue "tongue, language:, from Latin lingua) Webster's New Encyclopedic Dictionary, 1996 Edition 16 2016/01/05 CPSC 449 How is language supposed to work? 17 ? Chair 2016/01/05 CPSC 449 How is language supposed to work? 18 ? Chair

Transcript of abstract data types Day! Language - University of Calgary...

Page 1: abstract data types Day! Language - University of Calgary ...kremer.cpsc.ucalgary.ca/courses/cpsc449/lectureNotes/Language.pdf · •Data and the structure of data •Many different

02/23/2010 CPSC 449

Computer Science

Unless otherwise noted, all artwork and illustrations by either Rob Kremer or Jörg Denzinger (course instructors)

Language

13

Semantics

Parsing

Grammar

Syntax

Compiler

Interpreter

?

λ-Calculus

SLD-Resolution

abstract data types

loops

Error handling

2016/01/05 CPSC 449

Human Languages

14

Babel, manyyears ago

GoodDay!

GutenTag!

BonJour!

2016/01/05 CPSC 449

Language: definition

Language: 1 a: the words, their pronunciation, and the methods of combining them used and understood by a large group of people b (1): audible, articulate, and meaningful sound as produced by the action of the vocal organs (2): a systematic means of communicating ideas by signs or marks with understood meanings (sign language)

15 2016/01/05 CPSC 449

Language: definition (cont.)

2 a: form or manner of verbal expression; esp. STYLE (forceful language) b: the words and expressions of a particular group or field (the language of medicine)3: the study of language especially as a school subject (Old French, from langue "tongue, language:, from Latin lingua)

Webster's New Encyclopedic Dictionary, 1996 Edition

16

2016/01/05 CPSC 449

How is language supposed to work?

17

?

Chair

2016/01/05 CPSC 449

How is language supposed to work?

18

?

Chair

Page 2: abstract data types Day! Language - University of Calgary ...kremer.cpsc.ucalgary.ca/courses/cpsc449/lectureNotes/Language.pdf · •Data and the structure of data •Many different

2016/01/05 CPSC 449

How is language supposed to work?

19

Chair?

2016/01/05 CPSC 449

How is language supposed to work?

20

Chair

2016/01/05 CPSC 449

But:

21 2016/01/05 CPSC 449

So:

22

Chair

Syntax Semantics

2016/01/05 CPSC 449

What do we want to communicate using a language?

• Things - visible/invisible - real/imaginary

• Concepts • Actions • Relationships

- Causal - Temporal

• …

23 2016/01/05 CPSC 449

Language is more than words!

• Letters are used to form words • Words are used to form phrases • Phrases form sentences • Sentences form paragraphs • Paragraphs form sections • Sections together form chapters • Chapters form books

24

Page 3: abstract data types Day! Language - University of Calgary ...kremer.cpsc.ucalgary.ca/courses/cpsc449/lectureNotes/Language.pdf · •Data and the structure of data •Many different

2016/01/05 CPSC 449

But:

• Not every sequence of letters is an "allowed" word • Not every combination of words is a phrase • Not every collection of phrases is a sentence

• ☞ Syntax defines what is allowed and what not!

• But: syntax must be communicated between humans!

• ☞ Grammarsare used to describe syntax (using rules, laws, etc.)

25 2016/01/05 CPSC 449

How do we go from syntax to semantics?

• Humans learn about the meaning of words from other humans and develop their own relations between syntactical constructs and semantical concepts

• There are then groups of human beings that have rather similar semantical concepts for the same syntactical construct

• ☞ A language is born

26

2016/01/05 CPSC 449

Problems with human languages

• Several different syntactical constructs can express the same semantic concepts: - Chair vs. object you sit on - This allows poets to exist!

• One syntactical construct can be associated with several semantical concepts

- Ambiguity: source for many jokes

27

Chair

2016/01/05 CPSC 449

Problems with human languagesHuman languages change CHATILLON Philip of France, in right and true behalf Of thy deceased brother Geffrey's son, Arthur Plantagenet, lays most lawful claim To this fair island and the territories, To Ireland, Poictiers, Anjou, Touraine, Maine, Desiring thee to lay aside the sword Which sways usurpingly these several titles, And put these same into young Arthur's hand, Thy nephew and right royal sovereign. The Life and Death of King John William Shakespeare

28

2016/01/05 CPSC 449

What about computer programming languages?

• Fortran • Prolog • Lisp • C / C++ • Java • Smalltalk • …

29 2016/01/05 CPSC 449

Why do we have the Babel syndrome here?• People want to combine certain features of other

languages into one language • People want to work on a higher abstraction level and

therefore produce a language with such higher concepts • People want to have a language that supports certain

types of tasks: - Self modifying programs - Real-time applications - Verification of programs - etc.

• There is a new idea of computability

30

Page 4: abstract data types Day! Language - University of Calgary ...kremer.cpsc.ucalgary.ca/courses/cpsc449/lectureNotes/Language.pdf · •Data and the structure of data •Many different

2016/01/05 CPSC 449

How is a programming language supposed to work?

31

?

2016/01/05 CPSC 449

How is a programming language supposed to work?

32

Sourcecodefile

Compiler

Inter-preter memory

CompilerExe-cutable

Processor ?

2016/01/05 CPSC 449

How is a programming language supposed to work?

Sourcecodefile

Compiler

Inter-preter memory

Processor

33

?

2016/01/05 CPSC 449

How is a programming language supposed to work?

!

Sourcecodefile

Compiler

Inter-preter memory

Processor

34

2016/01/05 CPSC 449

But still:

35 2016/01/05 CPSC 449

So, what defines semantics?

• Language report in natural language

• Operating system of underlying computer

• Understanding of designer & programmer of compiler/interpreter of language report and machine specifications

36

Page 5: abstract data types Day! Language - University of Calgary ...kremer.cpsc.ucalgary.ca/courses/cpsc449/lectureNotes/Language.pdf · •Data and the structure of data •Many different

2016/01/05 CPSC 449

What do we want to communicate using a programming language?

• Data and the structure of data

• Many different manipulations of data

• Sequences and more complex combinations of data manipulations

• Access to external devices, like sensors, files, printers

37 2016/01/05 CPSC 449

How do we define a programming language?

Syntax: • Formal grammars like

- Context-free grammars - Backus-Naur form - Attribute grammars

• Syntax diagrams

38

2016/01/05 CPSC 449

Semantics:

• Theoretically using: - Operational semantics - Axiomatic semantics - Denotational (or fixpoint) semantics

• Practically: - (in theory) by a language report - (in practice) by a compiler/interpreter

39

How do we define a programming language?

2016/01/05 CPSC 449

Problems with programming languages- Several different syntactical constructs can result in the

same computation result: j:= 0 j:= 0 for i:=1 to 5 do i:= 1 j := j+1; while i < 6 do begin j:= j+1; i:=i+1 end

40

2016/01/05 CPSC 449

Problems with programming languages

• Programming languages can change!Going from Java 1.1 to Java 1.2 was quite a fiasco

• But: the same syntactical construct should never have different meanings(now, we just have to tell the compiler guys this ☺)

41 2016/01/05 CPSC 449

Why learning to learn languages on our own?

• Babel “syndrome” will persist: - New languages keep getting invented to deal with new

developments (and the need to build in more knowledge) • Web applications • Embedded systems

- At least one problem of modern systems is not handled well by current languages:Distributed systems and dependencies between processes/threads/actors

42

Page 6: abstract data types Day! Language - University of Calgary ...kremer.cpsc.ucalgary.ca/courses/cpsc449/lectureNotes/Language.pdf · •Data and the structure of data •Many different

2016/01/05 CPSC 449

Programming Paradigms

43

Peter Van Roy (2009-05-12). "Programming Paradigms for Dummies: What Every Programmer Should Know" (PDF). info.ucl.ac.be. Retrieved 2014-01-27.

2016/01/05 CPSC 449

Programming Paradigms - Simpler View

Declarative

Programming Paradigms

LogicFunctional Object Oriented Procedural

Imperative

HaskellLisp

Erlang Scheme

R

PrologALF

GödelMercury

Oz

CFortran

BasicCOBOL

PL/1

JavaSimula

SmalltalkC++

Eiffel