Information Science and Engineering

Slides:



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

Introduction to Programming Languages Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
Principles of programming languages 4: Parameter passing, Scope rules Department of Information Science and Engineering Isao Sasano.
CPSC Compiler Tutorial 9 Review of Compiler.
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.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
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.
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.
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.
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.
Principles of programming languages 6: Types 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.
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.
LECTURE 10 Semantic Analysis. REVIEW So far, we’ve covered the following: Compilation methods: compilation vs. interpretation. The overall compilation.
Introduction to Automata Theory
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Describing Syntax and Semantics
Advanced Computer Systems
Compiler Design (40-414) Main Text Book:
Introduction Chapter : Introduction.
Principles of programming languages 12: Functional programming
Topic: Programming Languages and their Evolution + Intro to Scratch
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
CSCI-235 Micro-Computer Applications
Principles of programming languages 8: Types
Compiler Construction (CS-636)
Java Primer 1: Types, Classes and Operators
Ch. 7 Programming Languages
Representation, Syntax, Paradigms, Types
Principles of programming languages 4: Parameter passing, Scope rules
Chapter 1 Introduction.
Compiler Lecture 1 CS510.
Principles of programming languages Supplement
Compiler Construction
Introduction to Automata Theory
Mini Language Interpreter Programming Languages (CS 550)
Representation, Syntax, Paradigms, Types
CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics
Representation, Syntax, Paradigms, Types
Chapter 6: Programming Languages
Principles of Programming Languages
Representation, Syntax, Paradigms, Types
Course Overview PART I: overview material PART II: inside a compiler
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Chapter 10: Compilers and Language Translation
Introduction Chapter : Introduction.
Chapter 15 Functional Programming 6/1/2019.
COMPILER CONSTRUCTION
SPL – PS1 Introduction to C++.
Faculty of Computer Science and Information System
Presentation transcript:

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

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 14th floor E-mail: sasano@sic.shibaura-it.ac.jp web: http://www.sic.shibaura-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] 00000010101111001010 00000010111111001000 00000011001110101000 (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 independence (i.e., portability) Availability of program libraries Consistency checking that detects syntax and type errors (ex.) The language C UNIX kernel (originally written in assembly languages) was rewritten in the language C in 1973. 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 Programming languages are roughly classified into the following four according to their computational models. Imperative languages (or procedural languages) Functional languages Object-oriented languages Logic programming languages

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) Variables in imperative languages A variable abstracts some address in memory. Variables are instantiated in compile time and runtime. (ex. 2) Functions in imperative languages 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. 3, advanced) Polymorphic types in functional languages 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 <d> ::= 0|1|2|3|4|5|6|7|8|9 <digit_seq> ::= <d> | <d><digit-seq> <real-number> ::= <digit-seq> . <digit-seq> Usually the grammar 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 <date> ::= <d><d> / <d><d> / <d><d><d><d> 01/02/2001 In US this represents January 2, 2001. In some other countries is represents February 1, 2001. 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 in BNF and semantics in 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 semantics, and axiomatic semantics which suits formal arguments.

A simple language ---Little Quilt A quilt

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

Expressions of Little Quilt <exp> ::= a | b | turn (<exp>) | sew (<exp>, <exp>) 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 quilts b turn (b) turn (turn (b)) a sew (turn (turn (b)), a)

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

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. Function declaration provides a way to name computation patterns that frequently occur. Syntax of function declaration: fun <name> (<formals>) = <exp> <formals> ::= <name> | <name>, <formals> Later we add <name> and function application to the definition of <exp>.

Local declarations (let expressions) 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 <decls> in <exp> end We define <decls> later. The scope of each of the names of the functions declared in <decls> is in the declarations after its declaration in <decls> and between in and end, where the scopes of the same name declared there are excluded.

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

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 <name> = <exp> 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

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