1 / 32

Programming Languages

Programming Languages. Informatics I101 March 22, 2004 John C. Paolillo. Computers. Programmable, general-purpose device performs any desired computation the program is an arrangement of logical relations of bits How does one accomplish the programming? Hard-wiring (ENIAC)

rowena
Télécharger la présentation

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. Programming Languages Informatics I101 March 22, 2004 John C. Paolillo

  2. Computers • Programmable, general-purpose device • performs any desired computation • the program is an arrangement of logical relations of bits • How does one accomplish the programming? • Hard-wiring (ENIAC) • Machine instructions (“code”)

  3. Interacting with Computers • Originally • Computer instructions are binary numbers • “machine code” • Low-level languages (“assembly language”) • Easily-remembered mnemonics translated directly into machine code

  4. High-Level Languages • Compiled • Translated into machine code in two-steps • compile (into “relocatable object code”) • link (with various resources into machine code) • Not interactive • Interpreted • Translated into machine code and executed directly

  5. Purpose Scientific, Other applications Interactive Shells Web support Typesetting Compiled FORTRAN Pascal C C++ TeX Perl, Java Interpreted LISP Pascal Unix Shell lgs DOS .BAT files JavaScript, C# PHP Postscript Some High-level Languages

  6. D.C. Engelbart’s system with mouse; Bootstrap Alliance

  7. D.C. Engelbart’s original mouse, 1964; Bootstrap Alliance

  8. D.C. Engelbart’s original mouse, 1964; Bootstrap Alliance

  9. User Interface Languages • Command-line systems • UNIX • DOS • VAX, TOPS-20 • MULTICS • Graphic User Interfaces • Windows, Icons, Menus and Pointers (WIMP) • Xerox Star • MacOS • Windows • X-Windows

  10. What’s in a High-level Language? • Commands and built-in functions • Sequence/order of execution • Variables (to hold values) and assignment • Operators (especially for arithmetic) • Constructs for defining • Data structures • Algorithms (programs, subroutines, functions) • Control structures • if/then/else, loops • Recursion (through the program stack)

  11. <?php // Solution to chart portion of PHP exercise 2.     // John Paolillo, October 2003. $ncol = sizeof($_GET) ; // $_GET holds the histogram $mx = max($_GET) ;       // maximum value $wd = 400 ;              // width $ht = 200 ;              // height $cw = $wd / ($ncol + 2) ; // column width $hh = $ht - 2 * $cw ;    // maximum height (pixels) $ccc = $cw/2 ;       // half-width (for labels) $b = $ht - $cw ;         // bottom line $image = imagecreate($wd,$ht) ; // First color defined (red) is automatically the picture background. $red = imagecolorallocate($image, 255, 0, 0) ; $wht = imagecolorallocate($image, 255, 255, 255) ; ksort($_GET) ; // Sort the bars by key value while (list($key,$val) = each($_GET)) { $t = $b - ($hh * $val / $mx) ; // Bar height $l = $l + $cw ;     // Bar left $r = $l + $cw ;      // Bar right imagefilledrectangle($image,$l,$t,$r,$b,$wht) ; imagestring($image,1,$l+$ccc,$ht-$ccc,"$key",$wht) ; } // Chart title imagestring($image,1,$cw,$ccc, "Distribution of Amino Acids in Peptide",$wht) ; // Output as PNG & clean up. header("Content-type: image/png") ; imagepng($image) ; imagedestroy($image) ; ?>

  12. Programming Paradigms • Procedural • Step-wise procedures • FORTRAN, BASIC, C, Pascal • Functional • Mathematical functions • Function composition, no assignments • Scheme, XSLT • Object-Oriented • Algorithms and data “encapsulated” together • Objects arranged in a hierarchy of inheritance • SmallTalk, C++, • Logic Programming • Logical relations • Prolog

  13. Procedural: PHP function factorial($n) { if ($n == 1) { return 1 ; } else { return n * factorial(n-1) ; } }

  14. Procedural: Postscript /factorial { dup 1 gt { dup 1 sub factorial mul } if } def

  15. Functional: LISP (defun fact (x) (if (<= x 0) 1 (* x (fact (- x 1)))))

  16. Functional: APL    X

  17. Functional: J factorial=. 1:`(]*factorial@<:) @. *

  18. Functional: XSLT <xsl:template name=“factorial”> <xsl:param name=“val”/> <xsl:choose> <xsl:when test=“$val=‘1’”> <xsl:value-of select=“1”/> </xsl:when> <!-- end base case --> <xsl:otherwise> <xsl:variable name=“factless”> <xsl:call-template name=“factorial”> <xsl:with-param name=“val” select=“$val - 1”/> </xsl:call-template> </xsl:variable> <xsl:value-of select=“$val * $factless”/> </xsl:otherwise> <!-- end recursive case --> </xsl:choose> </xsl:template>

  19. Object-Oriented: Prograph

  20. Logic Programming: Prolog factorial(1,1) :- !. factorial(N,FactN) :- M is N - 1, factorial(M,FactM), FactN is M * FactM.

  21. http://www.digibarn.com/collections/posters/tongues/ComputerLanguagesChart-med.pnghttp://www.digibarn.com/collections/posters/tongues/ComputerLanguagesChart-med.png

  22. C++: http://gcc.gnu.org/ Sun’s Java Technology The ECMAScript Language Specification ECMA-262.pdf Programming Language Naming Patterns Collection of Programming languages: [99 Bottles of Beer] - Section A An unusual language: Brainf***

  23. END

More Related