what is a programming language? · 2010-04-21 · natural languages formal languages programming...

16
What Is a Programming Language? ©Andrey Kruglyak, 2010 1 Wednesday, April 21, 2010

Upload: hoangnhi

Post on 30-Jun-2018

232 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: What Is a Programming Language? · 2010-04-21 · Natural languages Formal languages Programming languages Alphabet Words Sentences Texts Lexical rules & dictionary Syntax s??? lexical

What Is a Programming Language?©Andrey Kruglyak, 2010

1Wednesday, April 21, 2010

Page 2: What Is a Programming Language? · 2010-04-21 · Natural languages Formal languages Programming languages Alphabet Words Sentences Texts Lexical rules & dictionary Syntax s??? lexical

What is a programming language?

?

2Wednesday, April 21, 2010

Page 3: What Is a Programming Language? · 2010-04-21 · Natural languages Formal languages Programming languages Alphabet Words Sentences Texts Lexical rules & dictionary Syntax s??? lexical

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

Page 4: What Is a Programming Language? · 2010-04-21 · Natural languages Formal languages Programming languages Alphabet Words Sentences Texts Lexical rules & dictionary Syntax s??? lexical

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

Page 5: What Is a Programming Language? · 2010-04-21 · Natural languages Formal languages Programming languages Alphabet Words Sentences Texts Lexical rules & dictionary Syntax s??? lexical

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

Page 6: What Is a Programming Language? · 2010-04-21 · Natural languages Formal languages Programming languages Alphabet Words Sentences Texts Lexical rules & dictionary Syntax s??? lexical

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

Page 7: What Is a Programming Language? · 2010-04-21 · Natural languages Formal languages Programming languages Alphabet Words Sentences Texts Lexical rules & dictionary Syntax s??? lexical

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

Page 8: What Is a Programming Language? · 2010-04-21 · Natural languages Formal languages Programming languages Alphabet Words Sentences Texts Lexical rules & dictionary Syntax s??? lexical

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

Page 9: What Is a Programming Language? · 2010-04-21 · Natural languages Formal languages Programming languages Alphabet Words Sentences Texts Lexical rules & dictionary Syntax s??? lexical

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

Page 10: What Is a Programming Language? · 2010-04-21 · Natural languages Formal languages Programming languages Alphabet Words Sentences Texts Lexical rules & dictionary Syntax s??? lexical

syntactically correct programs

well-typed programs

meaningful (terminating, useful, etc.) programs

Programs:

“texts”

10Wednesday, April 21, 2010

Page 11: What Is a Programming Language? · 2010-04-21 · Natural languages Formal languages Programming languages Alphabet Words Sentences Texts Lexical rules & dictionary Syntax s??? lexical

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

Page 12: What Is a Programming Language? · 2010-04-21 · Natural languages Formal languages Programming languages Alphabet Words Sentences Texts Lexical rules & dictionary Syntax s??? lexical

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

Page 13: What Is a Programming Language? · 2010-04-21 · Natural languages Formal languages Programming languages Alphabet Words Sentences Texts Lexical rules & dictionary Syntax s??? lexical

Do we need different programming languages?

?

13Wednesday, April 21, 2010

Page 14: What Is a Programming Language? · 2010-04-21 · Natural languages Formal languages Programming languages Alphabet Words Sentences Texts Lexical rules & dictionary Syntax s??? lexical

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

Page 15: What Is a Programming Language? · 2010-04-21 · Natural languages Formal languages Programming languages Alphabet Words Sentences Texts Lexical rules & dictionary Syntax s??? lexical

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

Page 16: What Is a Programming Language? · 2010-04-21 · Natural languages Formal languages Programming languages Alphabet Words Sentences Texts Lexical rules & dictionary Syntax s??? lexical

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