Principles of programming languages 1: Introduction (with a simple language) Isao Sasano Department of Information Science and Engineering.

Slides:



Advertisements
Similar presentations
Compilers Course 379K, TTH 9:30-11:00 Instructor: Dr. Doron A. Peled Office Hours: Mon 11:00-12:00.
Advertisements

Semantics Static semantics Dynamic semantics attribute grammars
Introduction to Programming Languages Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Principles of programming languages 4: Parameter passing, Scope rules Department of Information Science and Engineering Isao Sasano.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics Fall 2005.
Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.
Functional Design and Programming Lecture 1: Functional modeling, design and programming.
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
Programming Languages Structure
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
Summer 02-03Programming Language Concepts1 Programming Language Concepts (CS 360) Lecture 1: Overview, Grammars, and Little Languages Jeremy R. Johnson.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
Introduction and Chapter 8 of Programming Languages by Ravi Sethi Elements of Functional Programming.
CSE 425: Intro to Programming Languages and their Design A Few Key Ideas No particular language is a prerequisite for this course –However you should be.
Functional Programming Element of Functional Programming.
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
Syntax & Semantic Introduction Organization of Language Description Abstract Syntax Formal Syntax The Way of Writing Grammars Formal Semantic.
Imperative Programming
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Introduction to Computer Programming in c
LANGUAGE DESCRIPTION: SYNTACTIC STRUCTURE
Chapter Twenty-ThreeModern Programming Languages1 Formal Semantics.
Principles of programming languages 5: An operational semantics of a small subset of C Department of Information Science and Engineering Isao Sasano.
1 Programming Languages Fundamentals Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
Chapter 3 Part II Describing Syntax and Semantics.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.
Compiler Construction (CS-636)
LESSON 04.
1-1 An Introduction to Functional Programming Sept
Principles of programming languages 6: Types Isao Sasano Department of Information Science and Engineering.
Principles of programming languages 10: Object oriented languages Isao Sasano Department of Information Science and Engineering.
Principle of Programming Lanugages 3: Compilation of statements Statements in C Assertion Hoare logic Department of Information Science and Engineering.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Programming Languages and Design Lecture 2 Syntax Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Overview of Previous Lesson(s) Over View 3 Model of a Compiler Front End.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
Programming Languages Meeting 3 September 9/10, 2014.
Little Quilt Programming Language. 2 A Little language of expressions Little Quilt The little language ----Little Quilt: quilts: Constructs in Little.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Describing Syntax and Semantics
Advanced Computer Systems
Introduction Chapter : Introduction.
Basic 1960s It was designed to emphasize ease of use. Became widespread on microcomputers It is relatively simple. Will make it easier for people with.
Chapter 1 Introduction.
PROGRAMMING LANGUAGES
Principles of programming languages 8: Types
Information Science and Engineering
Representation, Syntax, Paradigms, Types
Principles of programming languages 4: Parameter passing, Scope rules
Chapter 1 Introduction.
Principles of programming languages Supplement
Representation, Syntax, Paradigms, Types
CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics
Programming Languages 2nd edition Tucker and Noonan
Representation, Syntax, Paradigms, Types
Principles of Programming Languages
Representation, Syntax, Paradigms, Types
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Chapter 10: Compilers and Language Translation
Introduction Chapter : Introduction.
Chapter 15 Functional Programming 6/1/2019.
Faculty of Computer Science and Information System
Presentation transcript:

Principles of programming languages 1: Introduction (with a simple language) Isao Sasano Department of Information Science and Engineering

Schedule 13 Lectures, Mid-term exam, Final exam Evaluation – Mid-term exam: M point / 40 point – Final exam: F point / 50 point – Small exam: S point / 10 point – The overall score: S+M+F*(100-(S+M))/50

Contact information Isao Sasano Office: Toyosu campus 14K32 on the 14 th floor web: it.ac.jp/~sasano/index.htmlhttp:// it.ac.jp/~sasano/index.html The lecture page is linked from the above web page.

Machine language Machine language is the native language of a computer, directory interpreted and executed by the computer. The term code originally referred to a program written in a machine language. von Neumann machine – designed in Princeton in 1946 – Turing machine + random access + IO

Machine language A program written in some machine language is a sequence of numbers. [A code fragment for the von Neumann machine] (This fragment adds the numbers of locations 10 and 11 and stores the result in location 12.) Modern computers are said to have a von Neumann architecture. In assembly language instructions are represented by symbols.

Programming languages Programming languages are expected not to depend on specific machines (i.e., expected to be high level). Properties that programming languages should have:  High level Logical structure of programs are concisely described.  Semantics of programs being strictly defined Semantics (behavior) of all the programs are completely specified.  Efficient Programs are transformed into efficient code in machine languages.

Benefits of high-level languages Higher-level languages have took the place of machine and assembly languages in virtually all areas of programming. Readable familiar notations machine indepenence (i.e., portability) Availability of program libraries Consistency checkings that detect syntax error and type (ex.) The language C UNIX kernel (originally written in assembly languages) was rewritten in the language C in It becomes much easier to modify codes and support new devices UNIX was made available on hardwares other than PDP-11 without modifying most of the codes.

Classification of programming languages Imperative languages (or procedural languages) Functional languages Object-oriented languages Logic programming languages Programming languages are roughly classified into the following four according to their computational models.

What languages provide (1) Computational model ( cf. previous page) Data types (and operations on them) – (ex.) The language C provides primitive data types such as int, char, double, etc. The language C also provides mechanisms to construct large objects using smaller objects, such as arrays, structures (records in general terminology), pointers, and unions. The language C also provides operators to access the components of compound data, such as dot operator (member access operator) for structures (records).

What languages provide (2) Abstraction – (ex. 1) Functions in the language C A function definition abstracts some computation. A function call (application) instantiates the function body by assigning the actual parameters to the corresponding formal parameters. – (ex. 2, advanced) Polymorphic types in languages like Standard ML Types are abstracted and instantiated. Checking mechanisms – (ex. ) Syntax checking (parsing), type checking In compile time syntax errors and type errors are detected.

Syntax of programming languages (ex) Syntax of the languages of sequence of numbers in BNF notation ::= 0|1|2|3|4|5|6|7|8|9 ::= | ::=. Usually the grammer of programming languages belong to context-free grammars. BNF notation is a concise way to describe context-free grammars.

Semantics of programming languages (ex.) Syntax of the language of dates ::= / / 01/02/2001 In US this represents January 2, In some other countries is represents February 1, A programming language is specified by defining its syntax and semantics.

Definitions and explanations of programming languages Tutorial – Tutorial of a programming language introduces its outline. Reference manual – Reference manual of a programming language describes its syntax and semantics in BNF and some natural language (typically English). Syntax is formally defined by BNF and semantics is informally described. Formal definition – Formal definition of a programming language is a description of syntax (in BNF) and semantics in some formal description such as operational semantics, denotational semantcs, and axiomatic semantics which suits formal arguments.

A simple language ---Little Quilt A quilt

Little Quil t language Little quilt is a language that makes a quilt that consists of two basic figures. a b

Expressions of Little Quilt ::= a | b | turn ( ) | sew (, ) turn (e) --- represents the quilt obtained by rotating 90 degrees to the right the quilt represented by the expression e. sew (e1, e2) --- represents the quilt obtained by sewing the two quilt e1 and e2 (e1 is in the left side and e2 is in the right side). The quilt e1 and e2 must have the same height.

Examples of expressions of Little Quilt expressionsquilts b turn (b) turn (turn (b)) a sew (turn (turn (b)), a)

Exercise 1 turn (sew (turn (b), turn (b))) Illustrate the quilt represented by the following expression.

Function declaration fun unturn (x) = turn (turn (turn (x))) This function represents the operation of left turn. fun pile (x,y) = unturn (sew (turn (y), turn (x))) This function sews the quilt x and y, where x is in the upper side and y is in the lower. The quilt x and y must have the same width. Syntax of function declaration: fun ( ) = ::= |, Later we add and function application to the definition of. Function declaration provides a way to name computation patterns that frequently occur.

Local declarations (let expressions) (ex.) let fun unturn (x) = turn (turn (turn (x))) fun pile (x,y) = unturn (sew (turn (y), turn (x))) in pile (unturn (b), turn (b)) end Syntax of let expressions let in end The scope of each of the names of the functions declared in is in the declarations after its declaration in and between in and end, where the scopes of the same name declared there are excluded. We define later.

Exercise 2 let fun f (x) = turn (turn (x)) in f (f (b)) end Illustrate the quilt represented by the following expression.

Syntax that names some value (i.e., quilt) (ex.) let val x = unturn (b) val y = turn (b) in sew (x,y) end Syntax for value declarations val = Scopes of names are defined in the same way as funtion declarations

A larger example let fun unturn (x) = turn (turn (turn (x))) fun pile (x,y) = unturn (sew (turn (y), turn (x))) val aa = pile (a, turn (turn (a))) val bb = pile (unturn (b), turn (b)) val p = sew (bb, aa) val q = sew (aa, bb) in pile (p,q) end

::= a | b | | ( ) | turn ( ) | sew (, ) | let in end ::= |, ::= | ::= fun ( ) = | val = ::= |, Syntax of the Little Quilt language is strings, usually processed by lexical analysis. In BNF, can be defined as follows. ::= | ::= a | b | c | d | e …