1 / 33

Principles of Programming Languages

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

Download Presentation

Principles of Programming Languages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  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. Programming Language Programming Languages • What is a 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. The Number of Programming Languages • 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

  10. int sum(int[] x) { int sum = 0; n = 0; while (n < x.length) { sum += x[n]; } return sum; } 00101010101010 10101011111010 11101010101110 00101010101010 ... Abstraction In Programming Languages

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

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

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

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

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

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

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

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

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

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

  21. Quicksort in Java • A programming language is a way of thinking • Different people think in a different way

  22. Quicksort in Haskell 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 <- xs, y > x]

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

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

  25. Interpreter

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

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

  28. Compiler - 2

  29. Linking • Libraries of subroutines

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

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

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

More Related