Programming Languages - Languages ... BEQ R0,R0,Loop # Return to step E1 Done: ... I Fortran 90 (1991) I Fortran 95 (1995) I Fortran 2003 (2003)

Download Programming Languages -   Languages ... BEQ R0,R0,Loop # Return to step E1 Done: ... I Fortran 90 (1991) I Fortran 95 (1995) I Fortran 2003 (2003)

Post on 25-Mar-2018

216 views

Category:

Documents

4 download

Embed Size (px)

TRANSCRIPT

<ul><li><p>Programming LanguagesECE2893</p><p>Lecture 26</p><p>ECE2893 Programming Languages Spring 2011 1 / 26</p></li><li><p>Programming Languages1 We have use the C and C++ language in this class.2 There are of course many programming languages that can be</p><p>used to solve a particular problem.3 All of the languages have strenths and weaknesses, and often the</p><p>choice of which language to use is dependent on the application.4 We will discuss briefly a number of the other languages and</p><p>highlight when they might be appropriate or not.</p><p>ECE2893 Programming Languages Spring 2011 2 / 26</p></li><li><p>Binary Programming1 The very first programs were written in binary.2 The programmer wrote out, in 1s and 0s the machine code to</p><p>execute a particular program.3 This is obviously very tedious and error prone, but it worked.</p><p>ECE2893 Programming Languages Spring 2011 3 / 26</p></li><li><p>Assembly Language1 The complexity and difficulty of programming in binary led to the</p><p>development of the first assembler.2 The assembler allowed the programmer to enter the instructions</p><p>not in binary form, but using instruction mnemonics and refer toaddresses by name (such as Loop:.</p><p>3 The first assembler was, of course, written in binary.4 Later assemblers were written in assembly language.5 Entire operating systems were written in assembly language.</p><p># Program to execute euc l id s a lgo r i t hm# George F . Ri ley , F a l l 2008</p><p>LDI R0,0 # Set R0 to zeroLDM R1,m # Get value f o r mLDM R2, n # Get value f o r n</p><p>Loop : MOD R3, R1,R2 # Remainder o f m / nBEQ R3, R0, Done # Done , s to re r e s u l tLD R1,R2 # Set m to nLD R2,R3 # Set n to rBEQ R0, R0, Loop # Return to step E1</p><p>Done : STM R2, gcd # Store r e s u l tHLT</p><p>ECE2893 Programming Languages Spring 2011 4 / 26</p></li><li><p>Fortran1 The earlist uses for mainframe computers was for scientific</p><p>processing, such as calculating earth orbits given initial velocityand acceleration.</p><p>2 Also used for nuclear physics, weather prediction, and oilexploration (just to name a few).</p><p>3 The Fortran (FORmula TRANslation) language was designedspecifically for implementing scientific analysis applications.</p><p>4 Fortran has seen several upgrades over time with differentspecifications.</p><p>I Fortran I written 19541957I Fortran II 1958I Fortran IV 1962</p><p>Actually written in Fortran IVI Fortran 66 Standard in 1966 (ANSI)I Fortran 77 (1978)I Fortran 90 (1991)I Fortran 95 (1995)I Fortran 2003 (2003)</p><p>ECE2893 Programming Languages Spring 2011 5 / 26</p></li><li><p>Early Fortran Drawbacks1 Early Fortran (Through Fortran IV) did not have the notion of a</p><p>stack.No recursion!</p><p>2 Did not have structures3 Did not have pointers4 Did not have variable declarations</p><p>I A variable was automatically created when referenced:I = 2 Integer variable I automatically created</p><p>I If the variable name started with I M, it was automaticallydetermined to be an integer, otherwise a float (or double).</p><p>5 Extensive use of line numbers6 Extensive use of the goto statement.7 Input/Output specifications built into the language.8 Spaces Completely Ignored</p><p>ECE2893 Programming Languages Spring 2011 6 / 26</p></li><li><p>Fortran with Punched Cards1 Most early Fortran programs were implemented using punched</p><p>cards</p><p>ECE2893 Programming Languages Spring 2011 7 / 26</p></li><li><p>Fortran GOTO1 The Fortran language makes extensive use of the GOTO</p><p>statement.2 This often resulted in completely unmaintainable spaghetti code.</p><p>ECE2893 Programming Languages Spring 2011 8 / 26</p></li><li><p>Fortran ExampleC AREA OF A TRIANGLE HERON S FORMULAC INPUT CARD READER UNIT 5 , INTEGER INPUT , NO BLANK CARD FOR END OF DATAC OUTPUT LINE PRINTER UNIT 6 , REAL OUTPUTC INPUT ERROR DISPAYS ERROR MESSAGE ON OUTPUT</p><p>501 FORMAT(3 I5 )601 FORMAT( " A= " , I5 , " B= " , I5 , " C= " , I5 , " AREA= " , F10 . 2 , "SQUARE UNITS " )602 FORMAT( "NORMAL END" )603 FORMAT( " INPUT ERROR OR ZERO VALUE ERROR" )</p><p>INTEGER A,B,C10 READ(5 ,501 ,END=50 ,ERR=90) A,B,C</p><p>IF (A=0 .OR. B=0 .OR. C=0) GO TO 90S = (A + B + C) / 2.0AREA = SQRT( S (S A) (S B) (S C) )WRITE(6 ,601) A,B,C,AREAGO TO 10</p><p>50 WRITE(6 ,602)STOP</p><p>90 WRITE(6 ,603)STOPEND</p><p>ECE2893 Programming Languages Spring 2011 9 / 26</p></li><li><p>Fortran Summary1 Fortran is still used today</p><p>I Millions of lines of legacy code that is still in useI Try Googling written in FORTRAN 77 (1.9M hits).</p><p>2 The languate syntax is uglyI Built for speed decades agoI Still in use in the High Performance Computing and Scientific</p><p>Computational community3 Language has improved over the years with several new</p><p>standards, but backwards compatibility always an issue.</p><p>ECE2893 Programming Languages Spring 2011 10 / 26</p></li><li><p>Basic1 Beginners All-purpose Symbolic Instruction Code2 Invented in 1964, but became popular with the advent of personal</p><p>computers in the early 1980s.3 Heavy use of line numbers and GOTO statements.4 Builtin string data type.5 Many implementations were interpreted rather than compiled.</p><p>ECE2893 Programming Languages Spring 2011 11 / 26</p></li><li><p>Basic Example10 INPUT "What i s your name : " , U$20 PRINT " He l lo " ; U$30 INPUT "How many s ta r s do you want : " , N40 S$ = " "50 FOR I = 1 TO N60 S$ = S$ + " "70 NEXT I80 PRINT S$90 INPUT "Do you want more s ta r s ? " , A$100 IF LEN(A$) = 0 THEN 90110 A$ = LEFT$(A$ , 1)120 IF A$ = "Y" OR A$ = " y " THEN 30130 PRINT " Goodbye " ; U$140 END</p><p>ECE2893 Programming Languages Spring 2011 12 / 26</p></li><li><p>Basic Integrated Development Environment</p><p>ECE2893 Programming Languages Spring 2011 13 / 26</p></li><li><p>Pascal1 Named after Blaise Pascal, a French mathematician, who</p><p>designed an Arithmetical Machine in 1641.2 Language designed by Niklaus Wirth in 1970.3 Goals were:</p><p>I Make a language suitable for teaching programmingI Make a language that could easily be compiled and executed on</p><p>computing platforms of that day.4 Support for:</p><p>I records (what C calls structures)I Local variables and scopingI recursionI pointers</p><p>5 Again, the microcomputer revolution boosted the popularity ofthe language.</p><p>6 Turbo Pascal by Borland was one of the more popularimplemenations.</p><p>I Efficient inmemory compilationI A true Integrated Developement Environment</p><p>ECE2893 Programming Languages Spring 2011 14 / 26</p></li><li><p>Pascal ExampleType</p><p>Employee_type = ( Hourly , Salary , SalaryExempt ) ;InputRec = RECORD</p><p>emp_name : packed array [ 1 . . 3 0 ] of char ;s o c i a l : packed array [ 1 . . 9 ] of char ;sa la ry : rea l ;emp_type : Employee_type ;end ;</p><p>Varindex : integer ;r a t i o : rea l ;found : boolean ;i n p f : f i l e of InputRec ;</p><p>ECE2893 Programming Languages Spring 2011 15 / 26</p></li><li><p>Pascal ExampleProgram TowersOfHanoi ( input , ou tput ) ;</p><p>Vard isks : integer ;</p><p>Procedure Hanoi ( source , temp , d e s t i n a t i o n : char ; n : integer ) ;</p><p>begini f n &gt; 0 then</p><p>beginHanoi ( source , des t i na t i on , temp , n 1 ) ;wri te ln ( Move d isk ,n : 1 , from peg , source , to peg , d e s t i n a t i o n ) ;Hanoi ( temp , source , des t i na t i on , n 1 ) ;end ;</p><p>end ;</p><p>beginwri te ( Enter the number o f d isks : ) ;readln ( d isks ) ;wri te ln ( So lu t i on : ) ;Hanoi ( A , B , C , d isks ) ;end .</p><p>ECE2893 Programming Languages Spring 2011 16 / 26</p></li><li><p>Turbo Pascal IDE</p><p>ECE2893 Programming Languages Spring 2011 17 / 26</p></li><li><p>LISP1 List Processing Language2 Developed in 1958</p><p>Predates all modern lanugages except Fortran.3 Build in support for linked lists and list management4 Became popular in Artificial Intelligence community5 Much of the popular Emacs text editor written in Lisp.6 Alternate acronyms:</p><p>I Lost in Stupid ParenthesesI Lots of Irritating Superfluous Parentheses</p><p>ECE2893 Programming Languages Spring 2011 18 / 26</p></li><li><p>Lisp Example; ; Options Menu Se t t i ngs; ; =====================(cond</p><p>( ( and ( str ingmatch "XEmacs" emacsversion )(boundp emacsmajorversion )( or (and</p><p>(= emacsmajorversion 19)(&gt;= emacsminorversion 14) )</p><p>(= emacsmajorversion 20) )( fboundp l oadopt ions f i l e ) )</p><p>( loadopt ions f i l e " ~ / . xemacsoptions " ) ) ); ; ============================; ; End of Options Menu Se t t i ngs</p><p>ECE2893 Programming Languages Spring 2011 19 / 26</p></li><li><p>Another Lisp Example; ; Customized C/C++ mode s t u f f( defconst mycstyle</p><p> ( ( ctabalways indent . t )( cautonewline . t )( ccommentonly l ineoffset . 2)( changingbracesalist . ( ( substatementopen a f t e r )</p><p>( brace l istopen ) ) )( changingcolonsal ist . ( ( member in i t intro before )</p><p>( i nhe r i n t r o )( case label a f t e r )( l a b e l a f t e r )( access label a f t e r ) ) )</p><p>( ccleanup l is t . ( scopeoperatoremptydefunbracesdefunclosesemi ) )</p><p>( co f f se t sa l i s t . ( ( a r g l i s tc l o s e . c l i neuparg l i s t )( substatementopen . 0)( case label</p><p>. 2)( blockopen</p><p>. 0)( knrargdec l in t ro . ) ) )</p><p>( cechosyntact ic informationp . t ))</p><p>"My C Programming Sty le " )</p><p>; ; o f f s e t cus tomiza t ions not i n mycstyle( setq co f f se t sa l i s t ( ( member in i t intro . ++ ) ) )</p><p>ECE2893 Programming Languages Spring 2011 20 / 26</p></li><li><p>APL1 A Programming Language2 Invented in 19573 A number of built-in operators that worked on arrays, rather than</p><p>individual variables.4 Used a number of special keystroke characters for various</p><p>operations.I Up and down arrowsI Greek charactersI Set union and intersection</p><p>5 Language is known for its terseness, and (in general) lack ofunderstandability.</p><p>ECE2893 Programming Languages Spring 2011 21 / 26</p></li><li><p>APL Examples</p><p>ECE2893 Programming Languages Spring 2011 22 / 26</p></li><li><p>TCL1 Tool Command Language2 Pronounced tickle3 Invented in 1988.4 Interpreted Language5 No data typing!</p><p>I Duck TypingI The type of each variable is determined at runtime by the</p><p>interpreter.I Variables can change type by assigning a new value</p><p>6 Popular for creating simple applications7 Combined with the Tk toolkit makes easy and simple graphical</p><p>applications.</p><p>ECE2893 Programming Languages Spring 2011 23 / 26</p></li><li><p>TCL Exampleset dirname [ l index $argv 0 ]set f i lename [ l index $argv 1 ]set f i l e s [ glob $dirname / Job ]foreach t h i s $ f i l e s {</p><p># Process each Job f i l eset f [ open $ t h i s r ]puts " Processing $ t h i s "set ncount 0while { ! [ eof $f ] } {</p><p>gets $f l i n ei f { [ str ing f i r s t " node count " $ l i n e ] &gt;= 0 } {</p><p>set nodecount [ l index $ l i n e 5 ]lappend n c l i s t $nodecount</p><p>}i f { [ str ing f i r s t " Prog 19 " $ l i n e ] &gt;= 0 } {</p><p>set memuse [ l index $ l i n e 3 ]set mb [ str ing f i r s t "MB" $memuse ]set memuse [ str ing range $memuse 0 [ expr $mb 1 ] ]set nodeary ( $nodecount ) $memuse</p><p>}}close $f</p><p>}</p><p>set n c l i s t [ l so r t integer $ n c l i s t ]set f [ open $f i lename w]foreach t $ n c l i s t {</p><p>i f [ info exists nodeary ( $ t ) ] {puts $f " NCount $ t mem $nodeary ( $ t ) "</p><p>}}close $f</p><p>ECE2893 Programming Languages Spring 2011 24 / 26</p></li><li><p>Java1 Developed in 1996 by Sun Microsystems2 Object oriented language</p><p>I Classes, objectsI Class inheritanceI Class member functions and virtual methods</p><p>3 Automatic garbage collection for unused memory4 Write Once, Run Anywhere</p><p>I Java compiler (javac) does not create platformspecific machinecode.</p><p>I Rather, generates a sequence of platformindepenent byte codes.I The byte codes are then interpreted by the java runtime interpreter</p><p>(java).I Does not always use native representation for integers or floats.I Immensely popular for webbased applications.</p><p>ECE2893 Programming Languages Spring 2011 25 / 26</p></li><li><p>Java Example/ / OddEven . javaimport javax . swing . JOptionPane ;</p><p>public class OddEven {private i n t i npu t ; / / a whole number ( " i n t " means i n t e g e r )public OddEven ( ) { }public s t a t i c void main ( S t r i n g [ ] args ) {</p><p>OddEven number = new OddEven ( ) ;number . showDialog ( ) ;</p><p>}</p><p>public void showDialog ( ) {t ry {</p><p>i npu t = In tege r . pa rse In t ( JOptionPane . showInputDialog (" Please Enter A Number " ) ) ;</p><p>c a l c u l a t e ( ) ;} catch ( NumberFormatException e ) {</p><p>System . e r r . p r i n t l n ( "ERROR: I n v a l i d i npu t . Please type i n a numer ica l value . " ) ;}</p><p>}</p><p>private void c a l c u l a t e ( ) {i f ( i n pu t % 2 == 0) {</p><p>System . out . p r i n t l n ( " Even " ) ;} else {</p><p>System . out . p r i n t l n ( "Odd" ) ;}</p><p>}}</p><p>ECE2893 Programming Languages Spring 2011 26 / 26</p></li></ul>

Recommended

View more >