1 / 37

CS 424/524 PROGRAMMING LANGUAGES

CS 424/524 PROGRAMMING LANGUAGES. Overview. Course Organization. Class meetings: MW 3:55pm-5:15pm TH N326 Instructor Information: Dr. Mary Ellen Weisskopf Email: weisskop@cs.uah.edu Phone number: (256) 824-6306 Office: Technology Hall, N300A.

Télécharger la présentation

CS 424/524 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. CS 424/524PROGRAMMING LANGUAGES Overview

  2. Course Organization Class meetings: • MW 3:55pm-5:15pm • TH N326 Instructor Information: • Dr. Mary Ellen Weisskopf • Email: weisskop@cs.uah.edu • Phone number: (256) 824-6306 • Office: Technology Hall, N300A

  3. Programming Languages2nd editionTucker and Noonan Chapter 1 Overview A good programming language is a conceptual universe for thinking about programming. A. Perlis

  4. Contents 1.1 Principles 1.2 Paradigms 1.3 Special Topics 1.4 A Brief History 1.5 On Language Design 1.5.1 Design Constraints 1.5.2 Outcomes and Goals 1.6 Compilers, Interpreters, and Virtual Machines

  5. 1.1 Principles Programming languages have several properties: • Syntax • Names & types • Semantics For any language: • Its designers must define these properties • Its programmers must master these properties

  6. Syntax • The syntax of a programming language is a precise description of all its grammatically correct programs. • Rules that define how symbols can be combined to create legal language statements and how the statements can be combined into programs When studying syntax, we ask questions like: • What is the grammar for the language? (grammar = rules) • What is the basic vocabulary? (operators/variables/…) • How are syntax errors detected?

  7. Names Various kinds of entities in a program have names: variables, functions, parameters, classes, objects, … Named entities are bound in a running program to: • Scope • Visibility • Type • Lifetime

  8. Types A type is a collection of values and a collection of operations on those values. • Simple types: numbers, characters, booleans, … • Structured types: Strings, lists, trees, hash tables, … A language’s type system can help to: • Determine legal operations • Detect type errors

  9. Semantics A program’s meaning is called its semantics. In studying semantics, we ask questions like: • When a program is running, what happens to the values of the variables? • What does each statement mean? • What underlying model governs the run-time behavior of a function call? • How are objects allocated to memory at run-time? • Run-time stack, heap • Related to function behavior & implementation

  10. 1.2 Paradigms A programming paradigm is a pattern of problem-solving thought that underlies a particular category of programs and languages. There are four main programming paradigms: • Imperative • Object-oriented • Functional • Logic (declarative)

  11. Imperative Paradigm Follows the classic von Neumann-Eckert model: • Program and data are indistinguishable in memory • Program = a sequence of commands • State = values of all variables when program runs Large programs use procedural abstraction as a way to organize individual imperative statements. Example imperative languages: • Cobol, Fortran, C, Ada, Perl, …

  12. The von Neumann-Eckert Model

  13. Object-oriented (OO) Paradigm An OO Program consists of a collection of objects that interact by passing messages that transform object state. OO languages are characterized by • Data encapsulation/abstraction • Inheritance • Polymorphism Example OO languages: Smalltalk, Java, C++, C#, and Python

  14. Functional Paradigm Functional programming models a computation as a collection of mathematical functions. • Input = domain • Output = range Functional languages are characterized by: • Functional composition • Recursion Example functional languages: • Lisp, Scheme, ML, Haskell, …

  15. Logic Paradigm (Declarative) Logic programming declares what outcome the program should accomplish, rather than how it should be accomplished. Rule-based When studying logic programming we see: • Programs as sets of constraints on a problem • Programs that achieve all possible solutions • Programs that are “nondeterministic” Example logic programming languages: Prolog

  16. 1.3 Special Topics • Event handling • E.g., GUIs, home security systems, monitoring systems of various kinds • Concurrency • e.g., Client-server programs, rendering (in computer graphics) • Correctness • How can we prove that a program does what it is supposed to do under all circumstances?

  17. 1.4 A Brief History How and when did programming languages evolve? What communities have developed and used them? • Artificial Intelligence • Computer Science Education • Science and Engineering • Information Systems • Systems and Networks • World Wide Web

  18. 1.5 On Language Design 1.5.1 – Design Constraints • Computer architecture • Technical setting • Standards • Legacy systems

  19. Design Outcomes and Goals • Outcome: What makes a language successful? • Goals: What characteristics make a programming language “good” ?

  20. What Makes A Successful Language? Key characteristics: • Simplicity and readability • Clarity about binding • Reliability • Support • Abstraction • Orthogonality • Efficient implementation

  21. Simplicity (Writeability) and Readability • Easy to learn • Don’t include too many features • Don’t make it too complex • Simple conceptual model of semantics. • Uniformity:Similar syntax => similar semantics. • Lexical and syntactic conventions: • descriptive identifier names, blocking of compound statements • Readability is not synonymous with wordiness: COBOL is not easier to read.

  22. Clarity about Binding A language element is bound to a property at the time that property is defined for it. So a binding is the association between an object and a property of that object • Examples: • a variable and its type • a variable and its value

  23. Major Binding Times • Major binding times • Language definition time • Language implementation time • Program writing time • Compile time • Load time • Execution time • In general, • Early binding takes place at compile-time or before • Late binding takes place at load time or run time

  24. Reliability A language is reliable if: • Program behavior is the same on different platforms • E.g., early versions of Fortran weren’t • Type errors are detected • E.g., C vs Haskell • Semantic errors are properly trapped • E.g., C vs C++ or Java • Memory leaks are prevented • E.g., C vs Java

  25. Language Support • Accessible (public domain) compilers/interpreters • Good texts and tutorials • Wide community of users • Integrated with development environments (IDEs)

  26. Abstraction in Programming • Data • Programmer-defined types/classes • Class libraries • Procedural • Programmer-defined functions • Standard function libraries • Supports code reuse; simplifies the programming process.

  27. Orthogonality • A language is orthogonal if it is built on a small, mutually independent set of primitive operations. • You can use one feature without worrying about how it affects others • Rules don’t have exceptions; • Context doesn’t affect the behavior of a language feature (e.g., a reserved word doesn’t have different meanings based on where it’s used).

  28. Orthogonality • Non-orthogonal examples (rule exceptions): • In C, a function can return a struct, but not an array. Orthogonality => return value can be from any type. • Most imperative languages don’t allow function definitions to be passed as arguments • Orthogonal languages are in general easier to read and write

  29. Efficient Implementation • Embedded systems • Real-time responsiveness (e.g., navigation) • Failures of early Ada implementations – real time? • Web applications • Responsiveness to users (e.g., Google search) • Corporate database applications • Efficient search and updating

  30. 1.6 Compilers and Virtual Machines Compiler – produces machine code Interpreter – executes instructions directly • Example compiled languages: • Fortran, Cobol, C, C++ • Example interpreted languages: • Scheme, Haskell, Python • Hybrid compilation/interpretation: Java • The Java Virtual Machine (JVM)

  31. Translation/Execution – Compiler

  32. Compilers • Translates source code program into object code (machine language). • Object code can be executed without repeating the compilation process.

  33. Translation/Execution – Interpreter

  34. Interpreters • No object code. • Interpretive routines • Examine the program. When an action is recognized, do it (by calling one of the routines). • Slower execution (than with compilation) • Better interactive development environment.

  35. Virtual Machines & Interpreters • Some languages (e.g., Java) are compiled to machine code (byte code) that runs on a virtual machine (the JVM). • To run Java programs install a JVM for your machine that interprets the byte code. • Benefit: compiler is platform independent • Disdadvantage: slow • Solution: JIT compilers

  36. Summary SUMMARY • Programming language principles • Grammars, syntax, semantics • What makes a language successful? • Reliable, readable, writeable • Supported by simplicity, orthogonality, efficiency, support, … • Paradigms • Imperative, object-oriented, functional, logic • Language implementation • Compilers & interpreters

More Related