際際滷

際際滷Share a Scribd company logo
Lecture 1: Programming Linguistics




                      TI1220 2012-2013
              Concepts of Programming Languages

                      Eelco Visser / TU Delft
Outline



Course Organization      Programming Linguistics
  Code of Conduct             Why study PLs?
  Exams & Grades              Syntax
  Course Staff                Semantics
  Literature
Code of Conduct
Inspired by Coursera Honor Code
I will not use electronic devices such as
laptops, phones, or tablets during lectures.


Experimental exception: laptop for taking notes at last row
I will not enter the lecture hall
once the lecture has started.
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.
Exams & Grades
Course Grade




 Your 鍖nal 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 of鍖ine
           (but not today)
Warning!
This course moves from 鍖rst 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
Course Staff


Instructors
 Eelco Visser               Assistants
                              Jeff Smits
 Vlad Vergu
                              Victor Spiridon
                              Tim de Jong
                              Bastiaan Reijm


  http://eelcovisser.org/wiki/about/of鍖cehours
Literature
Ti1220 Lecture 1: Programming Linguistics
Course Notes on WebLab
Programming Linguistics
Why do we have so many
programming languages?
Computers Process Data




data     computer      data
Programmable Computers




data      computer     data




          program
Programming Language




data     computer     data




            L
         program
Turing Machines


    Turing/Church Thesis: Every effective
  computation can be carried out by a Turing
             machine (IN2505)



 Corollary: All (Turing Complete) programming
languages can express all effective computations




Why bother with new programming languages?
History of Programming Languages


History of Programming Languages
  1954                         1960                                                1965                                               1970                           1975             1980             1985                 1990                 1995             2000   2001                          2002                                             2003                                               2004




                                                                                                                                                              1986      1990   1990   1991   1991   1993      1994   1995          1996   1996      1997   1997   2000      2001                        2001                                    2003                                     2003                                    2004
                  For more than half of the fifty years computer programmers have been    This timeline includes fifty of the more than 2500 documented
                  writing code, OReilly has provided developers with comprehensive,      programming languages. It is based on an original diagram created


www.oreilly.com
                  in-depth technical information. Weve kept pace with rapidly changing   by ric L辿v辿nez (www.levenez.com), augmented with suggestions
                  technologies as new languages have emerged, developed, and              from OReilly authors, friends, and conference attendees.
                  matured. Whether you want to learn something new or need
                                                                                          For information and discussion on this poster,
                  answers to tough technical questions, youll find what you need
                                                                                          go to www.oreilly.com/go/languageposter.
                  in OReilly books and on the OReilly Network.
                                                                                                                                                                                                                                                                                   息2004 OReilly Media, Inc. OReilly logo is a registered trademark of OReilly Media, Inc. All other trademarks are property of their respective owners. part#30417




         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.
From Instructions to Expressions




mov          &a, &c                       c   = a
add          &b, &c                       c += b
mov          &a, &t1                      t1 = a                          c = (a + b) & (a - b)
sub          &b, &t1                      t1 -= b
and          &t1,&c                       c &= t1




Source: http://sites.google.com/site/arch1utep/home/course_outline/translating-complex-expressions-into-assembly-language-using-expression-trees
From Calling Conventions to Procedures

  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 result
  push   byte[eBP+20]   ;    pass some memory variable (FASM/TASM syntax)
  push   3              ;    pass some constant
  call   calc           ;    the returned result is now in eAX

                            http://en.wikipedia.org/wiki/Calling_convention




           def f(x)={ ... }                                                   f(e1)
                        function de鍖nition 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) */
Linguistic Abstraction


                         design abstraction
          language A                          language B



                        use new abstraction


identify pattern
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: whats
      under the hood?
Topics in this Course

Syntax and Semantics
Names, Bindings, and Scopes
Storage
Data Types
Functional Programming
Type Systems 1: Polymorphism
Type Systems 2: Type Parameterization
                          Parsing and Interpretation
                          Control Abstraction
                          Data Abstraction / Modular Programming
                          Functional Programming Redux
                          Concurrency
                          Concurrent Programming
                          Domain-Speci鍖c Languages
How can we describe a
programming language?
Syntax
Syntax




syntax |sintaks|
noun
the 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




Lexemes are the words that make a sentences



    Tokens are the categories of lexemes
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
Describing Structure with Railroad Diagrams
Chomsky Hierarchy




                                  BNF: Backus-Naur Form




http://www.cs.nott.ac.uk/~txa/g51mal.2001/notes/img4.png
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)


 Millionaire's Corner
Ti1220 Lecture 1: Programming Linguistics
Demonstration of
Declarative Syntax De鍖nition in the
  Spoofax Language Workbench
Semantics
Semantics


semantics |smantiks|
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.

DERIVATIVES
semantician |smantiSHn|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 de鍖nes a mapping
 from the syntactic domain to a semantic
       domain of mathematical objects

<bin> -> 0 | 1 | <bin> 0 | <bin> 1


      M(0) = 0
      M(1) = 1
      M(<bin> 0) = 2 * M(<bin>)
      M(<bin> 1) = 2 * M(<bin>) + 1
Axiomatic Semantics




axiomatic semantics speci鍖es 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
Reading & Programming in Week 1

Reading: Sebesta

  Chapter 1: Preliminaries

  Chapter 2: Evolution of the major
  programming languages (read)

  Chapter 3: Describing Syntax and
  Semantics


     WebLab: Scala Tutorial


     Week 2: Names, Bindings, and Scope (Chapter 5)

More Related Content

Similar to Ti1220 Lecture 1: Programming Linguistics (20)

The Ring programming language version 1.8 book - Part 93 of 202
The Ring programming language version 1.8 book - Part 93 of 202The Ring programming language version 1.8 book - Part 93 of 202
The Ring programming language version 1.8 book - Part 93 of 202
Mahmoud Samir Fayed
PL Lecture 01 - preliminaries
PL Lecture 01 - preliminariesPL Lecture 01 - preliminaries
PL Lecture 01 - preliminaries
Schwannden Kuo
The Ring programming language version 1.5.2 book - Part 174 of 181
The Ring programming language version 1.5.2 book - Part 174 of 181The Ring programming language version 1.5.2 book - Part 174 of 181
The Ring programming language version 1.5.2 book - Part 174 of 181
Mahmoud Samir Fayed
Java basics
Java basicsJava basics
Java basics
Hoang Nguyen
C++programing
C++programingC++programing
C++programing
amol kanvate
C++programing
C++programingC++programing
C++programing
rmvvr143
Plc part 1
Plc part 1Plc part 1
Plc part 1
Taymoor Nazmy
The Ring programming language version 1.5.4 book - Part 178 of 185
The Ring programming language version 1.5.4 book - Part 178 of 185The Ring programming language version 1.5.4 book - Part 178 of 185
The Ring programming language version 1.5.4 book - Part 178 of 185
Mahmoud Samir Fayed
Bay NET Aug 19 2009 presentation ppt
Bay  NET Aug 19 2009 presentation pptBay  NET Aug 19 2009 presentation ppt
Bay NET Aug 19 2009 presentation ppt
Art Scott
Introduction to course
Introduction to courseIntroduction to course
Introduction to course
nikit meshram
Lecture#1-Fundamental bt nch xhhs (1).ppt
Lecture#1-Fundamental bt nch xhhs (1).pptLecture#1-Fundamental bt nch xhhs (1).ppt
Lecture#1-Fundamental bt nch xhhs (1).ppt
SamanArshad11
About programming languages
About programming languagesAbout programming languages
About programming languages
Ganesh Samarthyam
C++ l 1
C++ l 1C++ l 1
C++ l 1
vineet_singh
Intro to openFrameworks
Intro to openFrameworksIntro to openFrameworks
Intro to openFrameworks
Kyle McDonald
Mastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loopsMastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loops
Ruth Marvin
Intro1
Intro1Intro1
Intro1
phanleson
vod do programov叩n鱈 3 (to be continued)
vod do programov叩n鱈 3 (to be continued)vod do programov叩n鱈 3 (to be continued)
vod do programov叩n鱈 3 (to be continued)
Karel Minarik
Introduction To Computer Programming
Introduction To Computer ProgrammingIntroduction To Computer Programming
Introduction To Computer Programming
Hussain Buksh
IN4308 1
IN4308 1IN4308 1
IN4308 1
Eelco Visser
A Brief History of Programming Languages.pdf
A Brief History of Programming Languages.pdfA Brief History of Programming Languages.pdf
A Brief History of Programming Languages.pdf
EdFeranil
The Ring programming language version 1.8 book - Part 93 of 202
The Ring programming language version 1.8 book - Part 93 of 202The Ring programming language version 1.8 book - Part 93 of 202
The Ring programming language version 1.8 book - Part 93 of 202
Mahmoud Samir Fayed
PL Lecture 01 - preliminaries
PL Lecture 01 - preliminariesPL Lecture 01 - preliminaries
PL Lecture 01 - preliminaries
Schwannden Kuo
The Ring programming language version 1.5.2 book - Part 174 of 181
The Ring programming language version 1.5.2 book - Part 174 of 181The Ring programming language version 1.5.2 book - Part 174 of 181
The Ring programming language version 1.5.2 book - Part 174 of 181
Mahmoud Samir Fayed
C++programing
C++programingC++programing
C++programing
rmvvr143
The Ring programming language version 1.5.4 book - Part 178 of 185
The Ring programming language version 1.5.4 book - Part 178 of 185The Ring programming language version 1.5.4 book - Part 178 of 185
The Ring programming language version 1.5.4 book - Part 178 of 185
Mahmoud Samir Fayed
Bay NET Aug 19 2009 presentation ppt
Bay  NET Aug 19 2009 presentation pptBay  NET Aug 19 2009 presentation ppt
Bay NET Aug 19 2009 presentation ppt
Art Scott
Introduction to course
Introduction to courseIntroduction to course
Introduction to course
nikit meshram
Lecture#1-Fundamental bt nch xhhs (1).ppt
Lecture#1-Fundamental bt nch xhhs (1).pptLecture#1-Fundamental bt nch xhhs (1).ppt
Lecture#1-Fundamental bt nch xhhs (1).ppt
SamanArshad11
About programming languages
About programming languagesAbout programming languages
About programming languages
Ganesh Samarthyam
Intro to openFrameworks
Intro to openFrameworksIntro to openFrameworks
Intro to openFrameworks
Kyle McDonald
Mastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loopsMastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loops
Ruth Marvin
vod do programov叩n鱈 3 (to be continued)
vod do programov叩n鱈 3 (to be continued)vod do programov叩n鱈 3 (to be continued)
vod do programov叩n鱈 3 (to be continued)
Karel Minarik
Introduction To Computer Programming
Introduction To Computer ProgrammingIntroduction To Computer Programming
Introduction To Computer Programming
Hussain Buksh
A Brief History of Programming Languages.pdf
A Brief History of Programming Languages.pdfA Brief History of Programming Languages.pdf
A Brief History of Programming Languages.pdf
EdFeranil

More from Eelco Visser (20)

CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingCS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
Eelco Visser
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic Services
Eelco Visser
CS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingCS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | Parsing
Eelco Visser
CS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionCS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definition
Eelco Visser
CS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionCS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: Introduction
Eelco Visser
A Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation RulesA Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation Rules
Eelco Visser
Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with Statix
Eelco Visser
Compiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler ConstructionCompiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler Construction
Eelco Visser
Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Eelco Visser
Compiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory ManagementCompiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory Management
Eelco Visser
Compiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | InterpretersCompiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | Interpreters
Eelco Visser
Compiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code GenerationCompiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code Generation
Eelco Visser
Compiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual MachinesCompiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual Machines
Eelco Visser
Compiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksCompiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone Frameworks
Eelco Visser
Compiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisCompiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow Analysis
Eelco Visser
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint Resolution
Eelco Visser
Compiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type ConstraintsCompiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type Constraints
Eelco Visser
Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type Checking
Eelco Visser
Compiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static AnalysisCompiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static Analysis
Eelco Visser
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingCompiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Eelco Visser
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingCS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
Eelco Visser
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic Services
Eelco Visser
CS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingCS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | Parsing
Eelco Visser
CS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionCS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definition
Eelco Visser
CS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionCS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: Introduction
Eelco Visser
A Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation RulesA Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation Rules
Eelco Visser
Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with Statix
Eelco Visser
Compiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler ConstructionCompiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler Construction
Eelco Visser
Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Eelco Visser
Compiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory ManagementCompiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory Management
Eelco Visser
Compiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | InterpretersCompiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | Interpreters
Eelco Visser
Compiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code GenerationCompiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code Generation
Eelco Visser
Compiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual MachinesCompiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual Machines
Eelco Visser
Compiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksCompiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone Frameworks
Eelco Visser
Compiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisCompiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow Analysis
Eelco Visser
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint Resolution
Eelco Visser
Compiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type ConstraintsCompiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type Constraints
Eelco Visser
Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type Checking
Eelco Visser
Compiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static AnalysisCompiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static Analysis
Eelco Visser
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingCompiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Eelco Visser

Ti1220 Lecture 1: Programming Linguistics

  • 1. Lecture 1: Programming Linguistics TI1220 2012-2013 Concepts of Programming Languages Eelco Visser / TU Delft
  • 2. Outline Course Organization Programming Linguistics Code of Conduct Why study PLs? Exams & Grades Syntax Course Staff Semantics Literature
  • 4. Inspired by Coursera Honor Code
  • 5. I will not use electronic devices such as laptops, phones, or tablets during lectures. Experimental exception: laptop for taking notes at last row
  • 6. I will not enter the lecture hall once the lecture has started.
  • 7. 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
  • 8. 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
  • 9. I will not engage in any other activities that will dishonestly improve my results or dishonestly improve/hurt the results of others.
  • 11. Course Grade Your 鍖nal 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.
  • 12. 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.
  • 13. 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
  • 14. All assignments for this course are provided via WebLab and should be submitted via WebLab, including the exams.
  • 15. Exam/Lab Grades from 2011-2012 Partial result from 2011-2012? Discuss with me of鍖ine (but not today)
  • 16. Warning! This course moves from 鍖rst 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!
  • 18. Course Staff Instructors Eelco Visser Assistants Jeff Smits Vlad Vergu Victor Spiridon Tim de Jong Bastiaan Reijm http://eelcovisser.org/wiki/about/of鍖cehours
  • 21. Course Notes on WebLab
  • 23. Why do we have so many programming languages?
  • 25. Programmable Computers data computer data program
  • 26. Programming Language data computer data L program
  • 27. Turing Machines Turing/Church Thesis: Every effective computation can be carried out by a Turing machine (IN2505) Corollary: All (Turing Complete) programming languages can express all effective computations Why bother with new programming languages?
  • 28. History of Programming Languages History of Programming Languages 1954 1960 1965 1970 1975 1980 1985 1990 1995 2000 2001 2002 2003 2004 1986 1990 1990 1991 1991 1993 1994 1995 1996 1996 1997 1997 2000 2001 2001 2003 2003 2004 For more than half of the fifty years computer programmers have been This timeline includes fifty of the more than 2500 documented writing code, OReilly has provided developers with comprehensive, programming languages. It is based on an original diagram created www.oreilly.com in-depth technical information. Weve kept pace with rapidly changing by ric L辿v辿nez (www.levenez.com), augmented with suggestions technologies as new languages have emerged, developed, and from OReilly authors, friends, and conference attendees. matured. Whether you want to learn something new or need For information and discussion on this poster, answers to tough technical questions, youll find what you need go to www.oreilly.com/go/languageposter. in OReilly books and on the OReilly Network. 息2004 OReilly Media, Inc. OReilly logo is a registered trademark of OReilly Media, Inc. All other trademarks are property of their respective owners. part#30417 This timeline includes 50 of the more than 2500 documented programming languages.
  • 29. 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
  • 30. 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.
  • 31. From Instructions to Expressions mov &a, &c c = a add &b, &c c += b mov &a, &t1 t1 = a c = (a + b) & (a - b) sub &b, &t1 t1 -= b and &t1,&c c &= t1 Source: http://sites.google.com/site/arch1utep/home/course_outline/translating-complex-expressions-into-assembly-language-using-expression-trees
  • 32. From Calling Conventions to Procedures 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 result push byte[eBP+20] ; pass some memory variable (FASM/TASM syntax) push 3 ; pass some constant call calc ; the returned result is now in eAX http://en.wikipedia.org/wiki/Calling_convention def f(x)={ ... } f(e1) function de鍖nition and call in Scala
  • 33. 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) */
  • 34. Linguistic Abstraction design abstraction language A language B use new abstraction identify pattern
  • 35. Domains of Computation Application domains Systems programming Embedded software Web programming Enterprise software Database programming ...
  • 36. Why So Many Programming Languages? Linguistic abstraction: better understanding of the general domain of computation Specialization to domain: different requirements from different application domains
  • 37. 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: whats under the hood?
  • 38. Topics in this Course Syntax and Semantics Names, Bindings, and Scopes Storage Data Types Functional Programming Type Systems 1: Polymorphism Type Systems 2: Type Parameterization Parsing and Interpretation Control Abstraction Data Abstraction / Modular Programming Functional Programming Redux Concurrency Concurrent Programming Domain-Speci鍖c Languages
  • 39. How can we describe a programming language?
  • 41. Syntax syntax |sintaks| noun the 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.
  • 42. Syntax The syntax of a programming language is the form of its expressions, statements, and program units. Sebesta Ch3
  • 43. 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
  • 44. Lexemes & Tokens Lexemes are the words that make a sentences Tokens are the categories of lexemes
  • 45. Lexemes & Tokens index = 2 * count + 17; Lexeme Token index Identifier = EqualSign 2 IntegerLiteral * MultOp count Identifier + PlusOp 17 IntegerLiteral ; Semicolon
  • 46. Describing Lexemes with Regular Expressions Identifier: [A-Za-z][A-Za-z0-9]* IntegerLiteral: [0-9]+ PlusOp: + Semicolon: ;
  • 47. 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
  • 48. Describing Structure with Railroad Diagrams
  • 49. Chomsky Hierarchy BNF: Backus-Naur Form http://www.cs.nott.ac.uk/~txa/g51mal.2001/notes/img4.png
  • 50. Ambiguous Grammar <assign> -> <id> = <expr> <id> -> A | B | C <expr> -> <expr> + <expr> | <expr> * <expr> | ( <expr> ) | <id>
  • 51. Unambiguous Grammar <assign> -> <id> = <expr> <id> -> A | B | C <expr> -> <expr> + <term> | <term> <term> -> <term> * <factor> | <factor> <factor> -> ( <expr> ) | <id>
  • 52. 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)
  • 55. Demonstration of Declarative Syntax De鍖nition in the Spoofax Language Workbench
  • 57. Semantics semantics |smantiks| 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. DERIVATIVES semantician |smantiSHn|noun, semanticist noun
  • 58. Semantics The semantics of a programming language is the meaning of its expressions, statements, and program units. Sebesta Ch3
  • 59. Static vs Dynamic Semantics Static Semantics: (context-senstive) restriction of the set of valid programs Dynamic Semantics: run-time behaviour of a program
  • 60. 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
  • 61. Denotational Semantics a denotational semantics de鍖nes a mapping from the syntactic domain to a semantic domain of mathematical objects <bin> -> 0 | 1 | <bin> 0 | <bin> 1 M(0) = 0 M(1) = 1 M(<bin> 0) = 2 * M(<bin>) M(<bin> 1) = 2 * M(<bin>) + 1
  • 62. Axiomatic Semantics axiomatic semantics speci鍖es what can be proven about a program {x > 3} x = x - 3 {x > 0}
  • 63. 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
  • 64. Reading & Programming in Week 1 Reading: Sebesta Chapter 1: Preliminaries Chapter 2: Evolution of the major programming languages (read) Chapter 3: Describing Syntax and Semantics WebLab: Scala Tutorial Week 2: Names, Bindings, and Scope (Chapter 5)