Presentation is loading. Please wait.

Presentation is loading. Please wait.

Principles of Programming Languages Asst. Prof. Dr. Ahmet Sayar Spring-2012 Kocaeli University Computer Engineering Department Introduction.

Similar presentations


Presentation on theme: "Principles of Programming Languages Asst. Prof. Dr. Ahmet Sayar Spring-2012 Kocaeli University Computer Engineering Department Introduction."— Presentation transcript:

1 Principles of Programming Languages Asst. Prof. Dr. Ahmet Sayar Spring-2012 Kocaeli University Computer Engineering Department Introduction

2 Goal of This Course Introducing major principles and concepts underlying all programming languages without concentrating on one particular language. It is not necessary for you to be familiar with all the programming languages. Familiarity from one of them is enough. It would be great if you have some general knowledge of data structures, algorithms and computational processes.

3 Different Names for the Same Course Formal Languages Programming Languages The Principles of Programming Languages Theory of Computing Computational Theories Fundamentals of Programming Languages

4 Related Studies in Literature Computer Engineering Computer Science Linguistics – Scientific Study of Human Language – Morphology, syntax and phonology Cognitive Science – Interdisciplinary scientific study of mind and its processes – Intelligence and behavior – How information is represented carried processed within nervous systems (humans and animals) and machines – Consists of multiple disciplines: psychology, artificial intelligence (computer eng and science), philosophy, linguistics, sociology, anthropology

5 What is a programming language? Programming Languages Programming Language

6 What is a Programming Language A notation for communicating with a computer what we want it to do. A major advance in computer design occurred in 1940 – Instead of hard-wired jobs – A series of codes stored as data would determine the actions taken by a central processing unit. – Soon, programmers realized attaching symbols to the instruction codes as well as to the memory locations – And assembly language was born.

7 What is a Programming Language Assembly language are machine dependent. Low- level languages. Hard to read and write High-level languages? Von Neumann model – An area of memory where both programs and data are stored and a separate central processing unit that sequentially executes instructions fetched from memory. New Definition: Notational system for describing computation in machine-readable and human- readable form.

8 Computation? Any process that can be carried out by a computer. Not necessarily mean mathematical calculations Data manipulation, text processing, information storage retrieval Special purpose languages – Graphics, reports, database General purpose languages – C, JAVA

9 How many programming languages do you know? – This is a sample list… http://dmoz.org/Computers/Programming/Languages Why is the number of programming languages so large? – Evolution – Special Purpose – Personal Preference The Number of Programming Languages

10

11 Abstraction In Programming Languages int sum(int[] x) { int sum = 0; int sum = 0; n = 0; n = 0; while (n < x.length) { while (n < x.length) { sum += x[n]; sum += x[n]; } return sum; return sum;}00101010101010101010111110101110101010111000101010101010...

12 Abstraction In Programming Languages Data Abstraction – Abstracts properties of data Control Abstraction – Abstracts properties of the transfer of control Abstractions fall into 3 levels – Basic – Structured – Unit

13 Data Abstraction: Basic Abstracts the internal representation of common data values in a computer Locations in computer memory that contain data values are abstracted by giving them names and are called variables. Pascal – var x : integer; C – int x;

14 Data Abstraction: Structured Abstracting collections of data values that are related – Employee record may contain name, company, salary etc. Each diff type – Group of items having same type In C – int a[10]; In Fortran – INTEGER a(10)

15 Data Abstraction: Unit Collecting related code into specific locations within a program, either as separate files or as separate language structures Include access conventions and restrictions – Referred to as data encapsulation and information hiding. – Modules in ML and Haskell – Packages in JAVA Unit data abstractions become the basis for language library mechanism – reusability

16 Control Abstraction: Basic Typical basic control abstraction is the statements in a language that combine a few machine instructions into a more understandable abstract statement. – Assignment statement x = x + 3; Another basic control statement is the GOTO statement – Example from Fortran

17 Control Abstraction: Structured Divide a program into group of instructions that are nested in the code In C: In Haskell:

18 Control Abstraction: Structured Structured control – Procedure ADA example for GCD (finding greatest common divisor)

19 Control Abstraction: Unit It is similar to data unit abstraction. The only difference is here the focus is on the operations rather than the data But goals of the reusability and library building remain the same

20 Language Definition Language Definition can be loosely divided into two parts – SYNTAX (structure): grammar of a language An if-statement consists of the word “if” followed by an expression inside parentheses, followed by… – SEMANTICS (meaning) An if=statement is executed by first evaluating its expression, which must have arithmetic or pointer type, including all side effects, and if it compares unequal to 0, ….

21 Syntax The description of language syntax is one of the areas where formal definitions have gained acceptance, and the syntax of almost all languages is now using context-free grammar Example context-free grammar

22 Quicksort in Java A programming language is a way of thinking Different people think in a different way

23 qsort [] = [] qsort (x:xs) = qsort lt_x ++ [x] ++ qsort ge_x where lt_x = [y | y <- xs, y < x] mid = [y | y <- xs, y = x] ++ [x] ge_x = [y | y x] Quicksort in Haskell

24 Semantics Much more complex than syntax. Meaning can be defined in many ways. No generally accepted method Several notational systems for formal definitions have been developed and are increasingly in use. – Operational Semantics – Denotational Semantics – Axiomatic semantics

25 Language Translation Translator – Interpreter – Compiler Interpretation is a one-step- process, in which both the program and the input are provided to the interpreter, and the output is obtained

26 Interpreter

27 Examples Some examples of interpreted programs are BASIC, QBASIC, and Visual Basic (version 5 of which has both a compiler and interpreter) The Practical Extraction and Reporting Language, or Perl, is a script-based programming language whose syntax parallels that of the C language but is an interpreted language; Perl can optionally be compiled prior to execution into either C code or cross-platform bytecode JavaScript is another example of an interpreted script-based programming language.

28 Compiler - 1 Compilation is two-step process Original program – source program is the input and new program – target program is output. Target program may then be executed. More commonly target language is assembly language Target program must be translated by an assembler into an object-program Then, linked with other object programs and then, loaded into appropriate memory locations before it can be executed

29 Compiler - 2

30 Linking Libraries of subroutines

31 From Source Code to Executable Code program gcd(input, output); var i, j: integer; begin read(i, j); while i <> j do if i > j then i := i – j; else j := j – i; writeln(i)end. program gcd(input, output); var i, j: integer; begin read(i, j); while i <> j do if i > j then i := i – j; else j := j – i; writeln(i)end. Compilation

32 Hybrid Implementation System JAVA uses both interpretation and compilation Source code is compiled into byte-code JVM (Java Virtual Machine) runs it as if it is an interpreter

33 1-33 Compiler vs. Interpretation Compilation – Translate high-level program to machine code – Slow translation – Fast execution Compiler vs. Interpretation – Compiler are better in terms of time efficiency – Interpreters are better in terms of memory usage – Interpreters are better in terms of exception handling


Download ppt "Principles of Programming Languages Asst. Prof. Dr. Ahmet Sayar Spring-2012 Kocaeli University Computer Engineering Department Introduction."

Similar presentations


Ads by Google