Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Principles of programming languages 1: Introduction (with a simple language) Isao Sasano Department of Information Science and Engineering."— Presentation transcript:

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

2 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

3 Contact information Isao Sasano Office: Toyosu campus 14K32 on the 14 th floor E-mail: sasano@sic.shibaura-it.ac.jpsasano@sic.shibaura-it.ac.jp web: http://www.sic.shibaura- it.ac.jp/~sasano/index.htmlhttp://www.sic.shibaura- it.ac.jp/~sasano/index.html The lecture page is linked from the above web page.

4 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

5 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.

6 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.

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

8 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.

9 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).

10 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.

11 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.

12 Semantics of programming languages (ex.) Syntax of the language of dates ::= / / 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.

13 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.

14 A simple language ---Little Quilt A quilt

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

16 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.

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

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

19 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.

20 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.

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

22 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

23 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

24 ::= 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 …


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

Similar presentations


Ads by Google