tics - university of calgary in albertadenzinge/courses/... · cpsc 449 principles of programming...
TRANSCRIPT
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
1. IntroductionLanguage
Semantics
Parsing
Gramm
ar
Syn
tax
Co
mpiler
Interpreter
?
l-Ca
lcu
lus
SLD-Resolution
abstract data types
loo
ps
Error handling
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
Hum
an LanguagesBabel, m
anyyears ago
Good
Day!G
utenT
ag!
Bon
Jour!
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
Language: definition
Language:1 a: the w
ords, their pronunciation, and the methods
of combining them
used and understood by a largegroup of peopleb (1): audible, articulate, and m
eaningful sound asproduced by the action of the vocal organs(2): a system
atic means of com
municating ideas by
signs or marks w
ith understood meanings (sign
language)
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
Language: definition (cont.)
2 a: form or m
anner of verbal expression; esp. STYLE(forceful language)b: the w
ords and expressions of a particular group orfield (the language of m
edicine)3: the study of language especially as a school subject(O
ld French, from langue "tongue, language:, from
Latin lingua)
Webster's N
ew Encyclopedic D
ictionary, 1996 Edition
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
How
is language supposed to work?
Chair?
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
How
is language supposed to work?
Chair?
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
How
is language supposed to work?
Chair?
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
How
is language supposed to work?
Chair
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
But:
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
So:Chair SyntaxSem
antics
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
What do w
e want to com
municate
using a language?
nThingsl
visible/invisiblel
real/imaginary
nConcepts
nA
ctionsn
Relationshipsl
Causall
Temporal
n…
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
Language is more than w
ords!
nLetters are used to form
words
nW
ords are used to form phrases
nPhrases form
sentencesn
Sentences form paragraphs
nParagraphs form
sectionsn
Sections together form chapters
nChapters form
books
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
But:
nN
ot every sequence of letters is an "allowed" w
ordn
Not every com
bination of words is a phrase
nN
ot every collection of phrases is a sentence
F Syntax defines w
hat is allowed and w
hat not!But: syntax m
ust be comm
unicated between hum
ans!F
Gram
mars
are used to describe syntax (using rules, laws, etc.)
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
How
do we go from
syntax tosem
antics?
nH
umans learn about the m
eaning of words from
other humans and develop their ow
n relationsbetw
een syntactical constructs and semantical
conceptsn
There are then groups of human beings that have
rather similar sem
antical concepts for the same
syntactical constructF
A language is born
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
Problems w
ith human languages (I)
nSeveral different syntactical constructs can expressthe sam
e semantical concepts:
lChair vs. object you sit on
lThis allow
s poets to exist!n
One syntactical construct can be associated w
ithseveral sem
antical concepts
lA
mbiguity: source for m
any jokes
Chair
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
Problems w
ith human languages (II)
nH
uman languages change
CHA
TILLON
Philip of France, in right and true behalfO
f thy deceased brother Geffrey's son,
Arthur Plantagenet, lays m
ost lawful claim
To this fair island and the territories,To Ireland, Poictiers, A
njou, Touraine, Maine,
Desiring thee to lay aside the sw
ordW
hich sways usurpingly these several titles,
And put these sam
e into young Arthur's hand,
Thy nephew and right royal sovereign.
The Life and D
eath of King John
William
Shakespeare
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
What about com
puter programm
inglanguages?
nFortran
nProlog
nLisp
nC / C++
nJava
nSm
alltalkn
…
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
Why do w
e have the Babel syndrome
here?n
People want to com
bine certain features of otherlanguages into one language
nPeople w
ant to work on a higher abstraction level
and therefore produce a language with such higher
conceptsn
People want to have a language that supports certain
types of tasks:l
Self modifying program
sl
Real-time applications
lVerification of program
sl
etc.n
There is a new idea of com
putability
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
How
is a programm
ing languagesupposed to w
ork?
?
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
How
is a programm
ing languagesupposed to w
ork?
?Sourcecodefile
Compiler
Inter-preter
mem
ory
prozessor
Compiler
Exe-cutable
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
How
is a programm
ing languagesupposed to w
ork?
?Sourcecodefile
Compiler
Inter-preter
mem
ory
prozessorInter-preter
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
How
is a programm
ing languagesupposed to w
ork?
!Sourcecodefile
Compiler
Inter-preter
mem
ory
prozessorInter-preter
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
But still:
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
So, what defines sem
antics?
nLanguage report in natural language
nO
perating system of underlying com
putern
Understanding of designer &
programm
er ofcom
piler/interpreter of language report and machine
specifications
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
What do w
e want to com
municate
using a programm
ing language?
nD
ata and the structure of datan
Many different m
anipulations of datan
Sequences and more com
plex combinations of data
manipulations
nA
ccess to external devices, like sensors, files, printers
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
How
do we define a program
ming
language? (I)
Syntax:n
Formal gram
mars like
lContext-free gram
mars
lBackus-N
aur forml
Attribute gram
mars
nSyntax diagram
s
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
How
do we define a program
ming
language? (II)
Semantics:
nTheoretically using:l
Operational sem
anticsl
Axiom
atic semantics
lD
enotational (or fixpoint) semantics
nPractically:l
(in theory) by a language reportl
(in practice) by a compiler/interpreter
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
Problems w
ith programm
inglanguages (I)
nSeveral different syntactical constructs can result inthe sam
e computation result:
j:= 0
j:= 0
for i:=1 to 5 do
i:= 1
j := j+
1;w
hile i<>
6 dobeginj:=
j+1;
i:=i+
1end
CPSC 449 Principles of Programm
ing Languages Jörg D
enzinger
Problems w
ith programm
inglanguages (II)
nProgram
ming languages can change!
Remem
ber the Java 1.1 to Java 1.2 fiasco
But: the same syntactical construct should never have
different meanings
(now, w
e just have to tell the compiler guys this J
)