what is a programming language? · 2010-04-21 · natural languages formal languages programming...
TRANSCRIPT
What Is a Programming Language?©Andrey Kruglyak, 2010
1Wednesday, April 21, 2010
What is a programming language?
?
2Wednesday, April 21, 2010
Naturallanguages
Formallanguages
Programminglanguages
Alphabet
Words
Sentences
Texts
Lexical rules & dictionary
Syntax
Seman
tics
???
lexical rules determine which sequences of letters form words of the language
syntactical rules determine which sequences of words form correct sentences of the language
3Wednesday, April 21, 2010
Naturallanguages
Formallanguages
Programminglanguages
Alphabet
Words
Sentences
Texts
Lexical rules & dictionary
Syntax
Seman
tics
???
Semantics is ambiguous(and not all
sentences are meaningful)
4Wednesday, April 21, 2010
Naturallanguages
Formallanguages
Programminglanguages
Alphabet
Words
Sentences
Texts
Lexical rules & dictionary
Syntax
Seman
tics
Alphabet
Words
Terms
Lexical rules
Syntax
Seman
tics
???
Semantics is ambiguous(and not all
sentences are meaningful)
5Wednesday, April 21, 2010
Naturallanguages
Formallanguages
Programminglanguages
Alphabet
Words
Sentences
Texts
Lexical rules & dictionary
Syntax
Seman
tics
Semantics must be unambiguous = formally specified
• Operational semantics: evaluation or reduction rules
• Denotational semantics: a function from terms to meanings
Alphabet
Words
Terms
Lexical rules
Syntax
Seman
tics
???
Semantics is ambiguous(and not all
sentences are meaningful)
6Wednesday, April 21, 2010
Naturallanguages
Formallanguages
Programminglanguages
Alphabet
Words
Sentences
Texts
Lexical rules & dictionary
Syntax
Seman
tics
Semantics is ambiguous(and not all
sentences are meaningful)
Semantics must be unambiguous = formally specified
• Operational semantics: evaluation or reduction rules
• Denotational semantics: a function from terms to meanings
Alphabet
Words
Terms
Lexical rules
Syntax
Seman
tics
Alphabet
Keywords &identifiers
Terms
Programs
Lexical rules
Syntax
Seman
tics
??? Syntax
7Wednesday, April 21, 2010
Naturallanguages
Formallanguages
Programminglanguages
Alphabet
Words
Sentences
Texts
Lexical rules & dictionary
Syntax
Seman
tics
Semantics is ambiguous(and not all
sentences are meaningful)
Semantics must be unambiguous = formally specified
• Operational semantics: evaluation or reduction rules
• Denotational semantics: a function from terms to meanings
Alphabet
Words
Terms
Texts
Lexical rules
Syntax
Seman
tics
Alphabet
Keywords &identifiers
Well-typedterms
Well-typedprograms
Lexical rules
Syntax &type rules
Seman
tics
??? Syntax Syntax &type rules
8Wednesday, April 21, 2010
Naturallanguages
Formallanguages
Programminglanguages
Alphabet
Words
Sentences
Texts
Lexical rules & dictionary
Syntax
Seman
tics
Semantics must be unambiguous = formally specified
• Operational semantics: evaluation or reduction rules
• Denotational semantics: a function from terms to meanings
Alphabet
Words
Terms
Texts
Lexical rules
Syntax
Seman
tics
Alphabet
Keywords &identifiers
Lexical rules
Seman
tics
Semantics ???• given by a compiler (but then
each program may have more than one meaning)
• formal semantics• language specification (text
in a natural language)
??? Syntax
Semantics is ambiguous(and not all
sentences are meaningful)
Well-typedterms
Well-typedprograms
Syntax &type rules
Syntax &type rules
9Wednesday, April 21, 2010
syntactically correct programs
well-typed programs
meaningful (terminating, useful, etc.) programs
Programs:
“texts”
10Wednesday, April 21, 2010
For a programming language we need:
An alphabet
Lexical rules for identifiers + a list of keywords & special symbols
Syntactical rules to make terms & programs
Typing rules to eliminate some meaningless programs (optional)
Semantics, e.g. small-step operational semantics: rules for evaluation of terms into other terms and ultimately into values
11Wednesday, April 21, 2010
How do languages differ?
We will be dealing with this question throughout the course, but here are some examples:
Evaluation strategies (deterministic vs. non-deterministic order of evaluation, with and without backtracking, call-by-value vs. call-by-name, etc.)
How restrictive are the syntactic and typing rules (compile-time vs. run-time checks)
Expressive power
Fancy language features
12Wednesday, April 21, 2010
Do we need different programming languages?
?
13Wednesday, April 21, 2010
Do we need different programming languages?
Different languages to address different classes of problems (domain-specific languages have been quite successful, e.g. ColdFusion Markup Language, Erlang)
Different languages for different hardware (e.g. for massively parallel computations)
Languages with different levels of abstraction
Different kinds of solutions (imperative, functional, logic - we will discuss that later)
14Wednesday, April 21, 2010
Something to think about...
The same functionality can be offered as:
a language feature - can be used directly by programmers, implementation is the responsibility of the compiler constructor(e.g. concurrent objects)
a library - reusable code that provides services to different programs (e.g. POSIX thread library, with mutex locks)
a design pattern - a general reusable solution to a commonly occurring problem, implementation is the responsibility of the programmers (e.g. a certain use of mutex locks to guarantee state consistency)
15Wednesday, April 21, 2010
Something to think about...
Language designers need to make their choice, different choices give us different languages.
In the end, this is very much a matter of taste.
16Wednesday, April 21, 2010