Upload
sophie-cummings
View
217
Download
1
Embed Size (px)
Citation preview
Programming LanguagesProgramming Languages
Informatics I101Informatics I101
March 22, 2004March 22, 2004
John C. PaolilloJohn C. Paolillo
ComputersComputers
• Programmable, general-purpose deviceProgrammable, general-purpose device– performs any desired computationperforms any desired computation
– the program is an arrangement of logical relations of the program is an arrangement of logical relations of bitsbits
• How does one accomplish the programming?How does one accomplish the programming?– Hard-wiring (ENIAC)Hard-wiring (ENIAC)
– Machine instructions (“code”)Machine instructions (“code”)
Interacting with ComputersInteracting with Computers
• OriginallyOriginally– Computer instructions are binary numbersComputer instructions are binary numbers
• ““machine code”machine code”
• Low-level languages (“assembly language”)Low-level languages (“assembly language”)– Easily-remembered mnemonics translated Easily-remembered mnemonics translated
directly into machine codedirectly into machine code
High-Level LanguagesHigh-Level Languages
• CompiledCompiled– Translated into machine code in two-stepsTranslated into machine code in two-steps
• compile (into “relocatable object code”)compile (into “relocatable object code”)
• link (with various resources into machine code)link (with various resources into machine code)
– Not interactiveNot interactive
• InterpretedInterpreted– Translated into machine code and executed Translated into machine code and executed
directlydirectly
Some High-level LanguagesSome High-level Languages
CompiledFORTRAN
PascalCC++
TeXPerl, Java
Interpreted
LISPPascal
Unix Shell lgsDOS .BAT filesJavaScript, C#PHPPostscript
PurposeScientific,Other applications
Interactive Shells
Web support
Typesetting
QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.
D.C. Engelbart’s system with mouse; Bootstrap Alliance
D.C. Engelbart’s original mouse, 1964; Bootstrap Alliance
D.C. Engelbart’s original mouse, 1964; Bootstrap Alliance
User Interface LanguagesUser Interface Languages
• Command-line systemsCommand-line systems– UNIXUNIX– DOSDOS– VAX, TOPS-20VAX, TOPS-20– MULTICSMULTICS
• Graphic User InterfacesGraphic User Interfaces– Windows, Icons, Menus and Pointers (WIMP)Windows, Icons, Menus and Pointers (WIMP)
• Xerox StarXerox Star• MacOSMacOS• WindowsWindows• X-WindowsX-Windows
What’s in a High-level What’s in a High-level Language?Language?
• Commands and built-in functionsCommands and built-in functions• Sequence/order of executionSequence/order of execution• Variables (to hold values) and assignmentVariables (to hold values) and assignment• Operators (especially for arithmetic)Operators (especially for arithmetic)• Constructs for defining Constructs for defining
– Data structuresData structures– Algorithms (programs, subroutines, functions)Algorithms (programs, subroutines, functions)
• Control structuresControl structures– if/then/else, loopsif/then/else, loops– Recursion (through the program stack)Recursion (through the program stack)
<?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) ; ?>
Programming ParadigmsProgramming Paradigms
• ProceduralProcedural– Step-wise proceduresStep-wise procedures
• FORTRAN, BASIC, C, PascalFORTRAN, BASIC, C, Pascal
• FunctionalFunctional– Mathematical functionsMathematical functions– Function composition, no assignmentsFunction composition, no assignments
• Scheme, XSLTScheme, XSLT
• Object-OrientedObject-Oriented– Algorithms and data “encapsulated” togetherAlgorithms and data “encapsulated” together– Objects arranged in a hierarchy of inheritanceObjects arranged in a hierarchy of inheritance
• SmallTalk, C++, SmallTalk, C++,
• Logic ProgrammingLogic Programming– Logical relationsLogical relations
• PrologProlog
Procedural: PHPProcedural: PHP
function factorial($n) {function factorial($n) {
if ($n == 1) {if ($n == 1) {
return 1 ;return 1 ;
} else {} else {
return n * factorial(n-1) ;return n * factorial(n-1) ;
}}
}}
Procedural: PostscriptProcedural: Postscript
/factorial/factorial
{ dup 1 gt { dup 1 gt
{ dup 1 sub factorial mul } if{ dup 1 sub factorial mul } if
} def} def
Functional: LISPFunctional: LISP
(defun fact (x)(defun fact (x) (if (<= x 0) 1 (* x (fact (- x 1))))) (if (<= x 0) 1 (* x (fact (- x 1)))))
Functional: APLFunctional: APL
XX
Functional: JFunctional: J
factorial=. 1:`(]*factorial@<:) @. * factorial=. 1:`(]*factorial@<:) @. *
Functional: XSLTFunctional: XSLT
<xsl:template name=“factorial”><xsl:template name=“factorial”> <xsl:param name=“val”/><xsl:param name=“val”/> <xsl:choose><xsl:choose> <xsl:when test=“$val=‘1’”><xsl:when test=“$val=‘1’”> <xsl:value-of select=“1”/><xsl:value-of select=“1”/> </xsl:when> </xsl:when> <!-- end base case --><!-- end base case --> <xsl:otherwise> <xsl:otherwise> <xsl:variable name=“factless”><xsl:variable name=“factless”> <xsl:call-template name=“factorial”><xsl:call-template name=“factorial”> <xsl:with-param name=“val” select=“$val - 1”/><xsl:with-param name=“val” select=“$val - 1”/> </xsl:call-template></xsl:call-template> </xsl:variable></xsl:variable> <xsl:value-of select=“$val * $factless”/><xsl:value-of select=“$val * $factless”/> </xsl:otherwise> </xsl:otherwise> <!-- end recursive case --><!-- end recursive case --> </xsl:choose></xsl:choose></xsl:template></xsl:template>
Object-Oriented: PrographObject-Oriented: Prograph
Logic Programming: PrologLogic Programming: Prolog
factorial(1,1) :- !.factorial(1,1) :- !.
factorial(N,FactN) :- factorial(N,FactN) :-
M is N - 1,M is N - 1,
factorial(M,FactM),factorial(M,FactM),
FactN is M * FactM.FactN is M * FactM.
http://www.digibarn.com/collections/posters/tongues/ComputerLanguagesChart-med.png
Collection of Programming languages:[99 Bottles of Beer] - Section A
An unusual language: Brainf***
ECMA-262.pdf
The ECMAScript Language Specification
Sun’s Java Technology
C++: http://gcc.gnu.org/
Programming Language Naming Patterns