1 / 32

COMP 205 Survey of Computer Languages

COMP 205 Survey of Computer Languages. Dr. Chunbo Chu. About me. Lead Faculty in Computer Science Education in Computer Science BS (1997) MS (2000) PhD (2008) Specialty and Interests Distributed Systems, Networking, CS Education. About you…. About COMP205.

nslade
Download Presentation

COMP 205 Survey of Computer 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. COMP 205Survey of Computer Languages Dr. Chunbo Chu

  2. About me • Lead Faculty in Computer Science • Education in Computer Science • BS (1997) • MS (2000) • PhD (2008) • Specialty and Interests • Distributed Systems, Networking, CS Education

  3. About you…

  4. About COMP205 • Overview of the concepts and practice with several programming languages • The Syllabus

  5. Error in gradebook • Assignment 13-2 :Working with Prolog is missing • 25 points

  6. About COMP205 • Structure • Module 1 (week 1)Introduction to Programming Languages: HTML/XML/XSLT • Module 2 (week 2-6)Markup and Scripting Languages: JavaScript/PHP • Module 3 (week 7-8) Scripting Languages: Perl, Ruby • Midterm (week 8) • Module 4 (week 9-10) Microsoft .Net and C# • Module 5 (week 11-14) Non-Imperative Languages: Lisp, Prolog • Final (week 15)

  7. About COMP205 • Outcomes • Write simple programs in a variety of languages • HTML/XML/XSLT • JavaScript/PHP • Perl/Ruby • MS .Net/C# • Lisp/Prolog • Compare and contrast language paradigms (imperative, functional, declarative). • Demonstrate the ability to move between programming languages.

  8. About COMP205 • Virtual Machine DVD • VMware Workstation: desktop-based virtualization program that permits a guest operating system to run as an application under your host operating system. • Virtual Machine for COM205 • Submit your assignment in Drop Box • Turnitin.com • class: COMP205 V1FF Summer 2009 • class ID: 2711966 • enrollment password: COMP205Su09

  9. Module 1 • Outcomes: • Describe language paradigms. • Explore the history of programming languages. • Examine the general features of programming languages.

  10. Computer languages • A notational system for describing computation in machine-readable and human-readable form • Machine-readable: the existence of a (more or less) linear-time translation algorithm; the syntax must be given by a context-free grammar. • Computation Described by a Turing Machine - a very simple computer that can carry out all known computations

  11. Language Paradigms • Imperative • traditional sequential programming (passive data, active control). Characterized by variables, assignment, and loops. • Procedural: • Object-oriented: data-centric, data controls its own use, action by request to data objects. Characterized by messages, instance variables, and protection.

  12. Language Paradigms • Declarative • Logic and functional paradigms share this property: state “what” needs computing, not “how” (sequence). • Functional: passive data, but no sequential control; all action by function evaluation (“call”), particularly recursion. No variables! • Logic: assertions are the basic data; logic inference the basic control. Again, no sequential operation. • Parallel • well, maybe not really a paradigm, but some think so. Again, no sequential operation. • … …

  13. K. Louden, Programming Languages Examples in three languages (Euclid’s gcd algorithm):Compute the greatest common divisor of two integers input by the user, and print the result. For example, the gcd of 15 and 10 is 5.

  14. K. Louden, Programming Languages C: #include <stdio.h> int gcd(int u, int v) /* “functional” version */ { if (v == 0) return u; else return gcd (v, u % v); /* “tail” recursion */ } main() /* I/O driver */ { int x, y; printf("Input two integers:\n"); scanf("%d%d",&x,&y); printf("The gcd of %d and %d is %d\n", x,y,gcd(x,y)); return 0; }

  15. K. Louden, Programming Languages Java: import java.io.*; class IntWithGcd { public IntWithGcd( int val ) { value = val; } public int getValue() { return value; } public int gcd ( int v ) { int z = value; /* “imperative” version */ int y = v; while ( y != 0 ) { int t = y; y = z % y; z = t; } return z; } private int value; }

  16. K. Louden, Programming Languages Java (continued): class GcdProg /* driver */ { public static void main (String args[]) { System.out.println("Input two integers:"); BufferedReader in = new BufferedReader( new InputStreamReader(System.in)); try /* must handle I/O exceptions */ { IntWithGcd x = /* create an object */ new IntWithGcd(Integer.parseInt(in.readLine())); int y = Integer.parseInt(in.readLine()); System.out.print("The gcd of " + x.getValue() + " and " + y + " is "); System.out.println(x.gcd(y)); } catch ( Exception e) { System.out.println(e); System.exit(1); } } }

  17. K. Louden, Programming Languages Scheme: (define (gcd u v) (if (= v 0) u (gcd v (modulo u v))))

  18. K. Louden, Programming Languages Scheme: (define (euclid) ; sequential! (display "enter two integers:") (newline) ; goes to next line on screen (let ((u (read)) (v (read))) (display "the gcd of ") (display u) (display " and ") (display v) (display " is ") (display (gcd u v)) (newline)))

  19. K. Louden, Programming Languages Paradigm use is rarely "pure” • The C program defined the gcd function in a purely functional style, even though C is mainly imperative. • The Java program used some imperative code to compute the gcd, and was not completely object-oriented (integers aren’t objects). • The Scheme code used sequencing to do I/O, an imperative feature.

  20. K. Louden, Programming Languages Examples of languages that are pure (mostly): • Imperative: (old) FORTRAN • Functional: Haskell • Object-oriented: Smalltalk

  21. Evaluation Criteria • Usability: how easy it is to read, write, and change programs • Support for abstraction: the ability to define and then use complicated structures or operations in ways that allow many of the details to be ignored. • Orthogonality: components are independent of each other and they behave in the same way in any circumstance. • Reliability: behaves as advertised and produces results the software engineer expects

  22. Evaluation Criteria • Efficiency: it can produce programs that are consistent with system specifications • Portability: if the source code can be moved from one platform to another without modification. • Cost: availability of software engineers who know the language, usability, reliability, efficiency, and portability.

  23. Language Discussion • Create a list of the languages you know • Group them into: • Interactive • Compiled • Paradigm • Old • New

  24. K. Louden, Programming Languages Language definition • Syntax: the structure of a program. Usually given a formal (i.e., mathematical) definition using a context-free language. (Lexical structure - the structure of the words or tokens - uses regular expressions.) • Semantics: the actual result of execution. Usually described in English, but can be done mathematically. • Semantics can have a static component: type checking, definition checking, other consistency checks prior to execution.

  25. K. Louden, Programming Languages Syntax • Syntax is the structure of a language, i.e., the form that each program or source code file must take. • Since the early 1960s, syntax has been given as a set of grammar rules in a form developed by Noam Chomsky, John Backus, and Peter Naur. (Context-free grammar, Backus Naur Form [BNF].) • Syntax includes the definition of the words, or tokens, of the language, which can be called its lexical structure. • Both lexical and syntactic structure have precise mathematical definitions that every computer scientist should know.

  26. Grammar and BNF <program> -> begin <stmts> end <stmts> -> <stmt> | <stmt> ; <stmts> <stmt>-><var> = <expr> <var> ->a | b | c | d <expr> -><term> + <term> | <term> - <term> | <term> <term> -> <var> | const begin a = a + c end

  27. K. Louden, Programming Languages Language translation • Compiler: two-step process that translates source code into target code; then the user executes the target code. • Interpreter: one-step process in which the source code is executed directly. • Hybrids are also possible (Java).

  28. K. Louden, Programming Languages Error classification • Lexical: character-level error, such as illegal character (hard to distinguish from syntax). • Syntax: error in structure (e.g., missing semicolon or keyword). • Static semantic: non-syntax error prior to execution (e.g., undefined vars, type errors). • Dynamic semantic: non-syntax error during execution (e.g., division by 0). • Logic: programmer error, program not at fault.

  29. K. Louden, Programming Languages Attributes • Properties of language entities, especially identifiers used in a program. • Important examples: • Value of an expression • Data type of an identifier • Maximum number of digits in an integer • Location of a variable • Code body of a function or method

  30. Attributes • Declarations ("definitions") bind attributes to identifiers. • Different declarations may bind the same identifier to different sets of attributes.

  31. K. Louden, Programming Languages Binding times can vary widely: • Value of an expression: during execution or during translation (constant expression). • Data type of an identifier: translation time (Java) or execution time (Smalltalk, Lisp). • Maximum number of digits in an integer: language definition time or language implementation time. • Location of a variable: load or execution time. • Code body of a function or method: translation time or link time or execution time.

  32. New Assignments • Assignment 1-1: Survey of Languages • Assignment 1-2: Programming Language History Paper • Turnitin.com • Drop box

More Related