Ti1220 Lecture 1: Programming Linguistics
-
Upload
eelco-visser -
Category
Documents
-
view
2.205 -
download
3
description
Transcript of Ti1220 Lecture 1: Programming Linguistics
TI1220 2012-2013Concepts of Programming Languages
Eelco Visser / TU Delft
Lecture 1: Programming Linguistics
Outline
Course Organization
Code of Conduct
Exams & Grades
Course Staff
Literature
Programming Linguistics
Why study PLs?
Syntax
Semantics
I will not use electronic devices such as laptops, phones, or tablets during lectures.
Experimental exception: laptop for taking notes at last row
My answers to assignments and exams will be my own work (except for assignments that explicitly permit collaboration).
http://en.wikipedia.org/wiki/File:Plagiarism_vs_Copyright_Infringement.png
I will not make solutions to assignments and exams available to anyone else. This includes both solutions written by me, as well as any official solutions provided by the course staff.
http://ucblibraries.colorado.edu/about/images/Xerox5135.jpg
I will not engage in any other activities that will dishonestly improve my results or dishonestly improve/hurt the results of others.
Course Grade
Your final grade G for the course will be computed as follows:
G = (E * 0.6) + (GA * 0.4)
where E is your grade for the exam an GA is your grade for the graded assignments.
Graded Assignments
There will be four Graded Assignments.
For each you need to get at least a 4.0 to pass.
GA is the average of the four grades.
Exams
You can pass the exam in two ways:
Pass the midterm Q3 exam on April 9 with at least a 6.0 and then pass the Q4 exam on June 26 also with a 6.0. E is the average of two exams.
Pass the Q3+Q4 exam on June 26 with at least a 6.0
Pass the August resit with at least a 6.0
All assignments for this course are provided via WebLab and should be submitted via
WebLab, including the exams.
Exam/Lab Grades from 2011-2012
Partial result from 2011-2012?
Discuss with me offline(but not today)
Warning!This course moves from first year to
second year in new curriculum
TI1220 will not be taught in 2013-2014
Lab & exams will be repeated, no lectures
My advice: pass the course this year!
Course Staff
http://eelcovisser.org/wiki/about/officehours
Assistants• Jeff Smits• Victor Spiridon• Tim de Jong• Bastiaan Reijm
Instructors • Eelco Visser• Vlad Vergu
Turing Machines
Corollary: All (Turing Complete) programming languages can express all effective computations
Turing/Church Thesis: Every effective computation can be carried out by a Turing
machine (IN2505)
Why bother with new programming languages?
History of Programming Languages
1986 1990 1990 1991 1991 1993 1994 1995 1996 1996 1997 1997 2000 2001 2001 2003 2003 2004
History of Programming Languages
©2004 O’Reilly Media, Inc. O’Reilly logo is a registered trademark of O’Reilly Media, Inc. All other trademarks are property of their respective owners. part#30417
19601954 1965 1970 1975 1980 1985 1990 1995 2000 20022001 2003 2004
For more than half of the fifty years computer programmers have beenwriting code, O’Reilly has provided developers with comprehensive,in-depth technical information. We’ve kept pace with rapidly changingtechnologies as new languages have emerged, developed, andmatured. Whether you want to learn something new or needanswers to tough technical questions, you’ll find what you need in O’Reilly books and on the O’Reilly Network.
This timeline includes fifty of the more than 2500 documented programming languages. It is based on an original diagram createdby Éric Lévénez (www.levenez.com), augmented with suggestionsfrom O’Reilly authors, friends, and conference attendees.
For information and discussion on this poster, go to www.oreilly.com/go/languageposter.
www.oreilly.com
This timeline includes 50 of the more than 2500 documented programming languages.
Programming Languages in TI @ TUD
TI1200: Object-Oriented Programming
• Java
TI1400: Computer Systems
• Assembly
TI1500: Web- and Database Technology
• HTML, PHP, SQL, JavaScript
TI1600: Multi-Agent Systems
• Prolog, GOAL
“A programming language is low level when its programs require attention to the irrelevant”
Alan J. Perlis. Epigrams on Programming. SIGPLAN Notices, 17(9):7-13, 1982.
mov &a, &cadd &b, &cmov &a, &t1sub &b, &t1and &t1,&c
Source: http://sites.google.com/site/arch1utep/home/course_outline/translating-complex-expressions-into-assembly-language-using-expression-trees
c = ac += bt1 = at1 -= bc &= t1
c = (a + b) & (a - b)
From Instructions to Expressions
From Calling Conventions to Procedures
f(e1)
calc: push eBP ; save old frame pointer mov eBP,eSP ; get new frame pointer sub eSP,localsize ; reserve place for locals . . ; perform calculations, leave result in AX . mov eSP,eBP ; free space for locals pop eBP ; restore old frame pointer ret paramsize ; free parameter space and return
push eAX ; pass some register resultpush byte[eBP+20] ; pass some memory variable (FASM/TASM syntax)push 3 ; pass some constantcall calc ; the returned result is now in eAX
def f(x)={ ... }
http://en.wikipedia.org/wiki/Calling_convention
function definition and call in Scala
From Malloc to Garbage Collection
/* Allocate space for an array with ten elements of type int. */int *ptr = (int*)malloc(10 * sizeof (int));if (ptr == NULL) { /* Memory could not be allocated, the program should handle the error here as appropriate. */} else { /* Allocation succeeded. Do something. */ free(ptr); /* We are done with the int objects, and free the associated pointer. */ ptr = NULL; /* The pointer must not be used again, unless re-assigned to using malloc again. */}
http://en.wikipedia.org/wiki/Malloc
int [] = new int[10];/* use it; gc will clean up (hopefully) */
Domains of Computation
Application domains
Systems programming
Embedded software
Web programming
Enterprise software
Database programming
...
Why So Many Programming Languages?
Linguistic abstraction: better understanding of the general domain of computation
Specialization to domain: different requirements from different application domains
Why Study Programming Languages?
Language shapes thought: understand the languages that you are using
Choosing the right language for the job
Learning to learn new languages
Understanding implementation: what’s under the hood?
Topics in this Course
Syntax and SemanticsNames, Bindings, and Scopes Storage Data TypesFunctional ProgrammingType Systems 1: PolymorphismType Systems 2: Type Parameterization
Parsing and InterpretationControl AbstractionData Abstraction / Modular ProgrammingFunctional Programming ReduxConcurrencyConcurrent ProgrammingDomain-Specific Languages
Syntax
syntax |ˈsinˌtaks|nounthe arrangement of words and phrases to create well-formed sentences in a language: the syntax of English.• a set of rules for or an analysis of this: generative syntax.• the branch of linguistics that deals with this.
ORIGIN late 16th cent.: from French syntaxe, or via late Latin from Greek suntaxis, from sun- ‘together’ + tassein ‘arrange.’
Syntax
“The syntax of a programming language is the form of its expressions, statements,
and program units.”Sebesta Ch3
Lexical vs Context-free Syntax
lexical syntax
• words made from letters
• structure not relevant
• regular expressions
context-free syntax
• sentences made from words
• structure relevant
• context-free grammars
• Backus-Naur Form
• Extended Backus-Naur Form
Lexemes & Tokens
index = 2 * count + 17;
Lexeme Token
index Identifier
= EqualSign
2 IntegerLiteral
* MultOp
count Identifier
+ PlusOp
17 IntegerLiteral
; Semicolon
Describing Lexemes with Regular Expressions
Identifier: [A-Za-z][A-Za-z0-9]* IntegerLiteral: [0-9]+PlusOp: ‘+’Semicolon: ‘;’
Regular Expressions
basics
• strings: "nil"
• character classes: [a-zA-Z]
combinators
• concatenation: E1 E2
• optional: E?
• zero or more: E*
• one or more: E+
• alternative: E1 | E2
Chomsky Hierarchy
http://www.cs.nott.ac.uk/~txa/g51mal.2001/notes/img4.png
BNF: Backus-Naur Form
Ambiguous Grammar
<assign> -> <id> = <expr><id> -> A | B | C<expr> -> <expr> + <expr> | <expr> * <expr> | ( <expr> ) | <id>
Unambiguous Grammar
<assign> -> <id> = <expr><id> -> A | B | C<expr> -> <expr> + <term> | <term><term> -> <term> * <factor> | <factor><factor> -> ( <expr> ) | <id>
Syntax in this Course
You should be able to determine whether a program is syntactically correct according to a context-free grammar (BNF, railroad diagram)
(There will be exercises on WebLab)
Semantics
semantics |səәˈmantiks|pluralnoun [ usu. treated as sing. ]the branch of linguistics and logic concerned with meaning. There are a number of branches and subbranches of semantics, including formal semantics, which studies the logical aspects of meaning, such as sense, reference, implication, and logical form, lexical semantics, which studies word meanings and word relations, and conceptual semantics, which studies the cognitive structure of meaning.• the meaning of a word, phrase, sentence, or text: such quibbling over semantics may seem petty stuff.
DERIVATIVESsemantician |ˌsēmanˈtiSHəәn|noun,semanticist noun
Semantics
“The semantics of a programming language is the meaning of its expressions,
statements, and program units.”Sebesta Ch3
Static vs Dynamic Semantics
Static Semantics: (context-senstive) restriction of the set of valid programs
Dynamic Semantics: run-time behaviour of a program
Operational Semantics
Operational semantics: describe the meaning of a statement or program by specifying the effects of running it on a
machine
In second part of course (Q4): write interpreter for small functional language
Denotational Semantics
a denotational semantics defines a mapping from the syntactic domain to a semantic
domain of mathematical objects
M(‘0’) = 0M(‘1’) = 1M(<bin> ‘0’) = 2 * M(<bin>)M(<bin> ‘1’) = 2 * M(<bin>) + 1
<bin> -> ‘0’ | ‘1’ | <bin> ‘0’ | <bin> ‘1’
Axiomatic Semantics
axiomatic semantics specifies what can be proven about a program
{x > 3} x = x - 3 {x > 0}
Semantics in this Course
Informal operational semantics: Reasoning about the operational behavior of
programs
Comparative/translational semantics: Explaining the semantics of construct/concept
by translating it to another language