programming languages - languages ... beq r0,r0,loop # return to step e1 done: ... i fortran 90...
Post on 25-Mar-2018
Embed Size (px)
ECE2893 Programming Languages Spring 2011 1 / 26
Programming Languages1 We have use the C and C++ language in this class.2 There are of course many programming languages that can be
used to solve a particular problem.3 All of the languages have strenths and weaknesses, and often the
choice of which language to use is dependent on the application.4 We will discuss briefly a number of the other languages and
highlight when they might be appropriate or not.
ECE2893 Programming Languages Spring 2011 2 / 26
Binary Programming1 The very first programs were written in binary.2 The programmer wrote out, in 1s and 0s the machine code to
execute a particular program.3 This is obviously very tedious and error prone, but it worked.
ECE2893 Programming Languages Spring 2011 3 / 26
Assembly Language1 The complexity and difficulty of programming in binary led to the
development of the first assembler.2 The assembler allowed the programmer to enter the instructions
not in binary form, but using instruction mnemonics and refer toaddresses by name (such as Loop:.
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.
# Program to execute euc l id s a lgo r i t hm# George F . Ri ley , F a l l 2008
LDI R0,0 # Set R0 to zeroLDM R1,m # Get value f o r mLDM R2, n # Get value f o r n
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
Done : STM R2, gcd # Store r e s u l tHLT
ECE2893 Programming Languages Spring 2011 4 / 26
Fortran1 The earlist uses for mainframe computers was for scientific
processing, such as calculating earth orbits given initial velocityand acceleration.
2 Also used for nuclear physics, weather prediction, and oilexploration (just to name a few).
3 The Fortran (FORmula TRANslation) language was designedspecifically for implementing scientific analysis applications.
4 Fortran has seen several upgrades over time with differentspecifications.
I Fortran I written 19541957I Fortran II 1958I Fortran IV 1962
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)
ECE2893 Programming Languages Spring 2011 5 / 26
Early Fortran Drawbacks1 Early Fortran (Through Fortran IV) did not have the notion of a
2 Did not have structures3 Did not have pointers4 Did not have variable declarations
I A variable was automatically created when referenced:I = 2 Integer variable I automatically created
I If the variable name started with I M, it was automaticallydetermined to be an integer, otherwise a float (or double).
5 Extensive use of line numbers6 Extensive use of the goto statement.7 Input/Output specifications built into the language.8 Spaces Completely Ignored
ECE2893 Programming Languages Spring 2011 6 / 26
Fortran with Punched Cards1 Most early Fortran programs were implemented using punched
ECE2893 Programming Languages Spring 2011 7 / 26
Fortran GOTO1 The Fortran language makes extensive use of the GOTO
statement.2 This often resulted in completely unmaintainable spaghetti code.
ECE2893 Programming Languages Spring 2011 8 / 26
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
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" )
INTEGER A,B,C10 READ(5 ,501 ,END=50 ,ERR=90) A,B,C
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
50 WRITE(6 ,602)STOP
90 WRITE(6 ,603)STOPEND
ECE2893 Programming Languages Spring 2011 9 / 26
Fortran Summary1 Fortran is still used today
I Millions of lines of legacy code that is still in useI Try Googling written in FORTRAN 77 (1.9M hits).
2 The languate syntax is uglyI Built for speed decades agoI Still in use in the High Performance Computing and Scientific
Computational community3 Language has improved over the years with several new
standards, but backwards compatibility always an issue.
ECE2893 Programming Languages Spring 2011 10 / 26
Basic1 Beginners All-purpose Symbolic Instruction Code2 Invented in 1964, but became popular with the advent of personal
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.
ECE2893 Programming Languages Spring 2011 11 / 26
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
ECE2893 Programming Languages Spring 2011 12 / 26
Basic Integrated Development Environment
ECE2893 Programming Languages Spring 2011 13 / 26
Pascal1 Named after Blaise Pascal, a French mathematician, who
designed an Arithmetical Machine in 1641.2 Language designed by Niklaus Wirth in 1970.3 Goals were:
I Make a language suitable for teaching programmingI Make a language that could easily be compiled and executed on
computing platforms of that day.4 Support for:
I records (what C calls structures)I Local variables and scopingI recursionI pointers
5 Again, the microcomputer revolution boosted the popularity ofthe language.
6 Turbo Pascal by Borland was one of the more popularimplemenations.
I Efficient inmemory compilationI A true Integrated Developement Environment
ECE2893 Programming Languages Spring 2011 14 / 26
Employee_type = ( Hourly , Salary , SalaryExempt ) ;InputRec = RECORD
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 ;
Varindex : integer ;r a t i o : rea l ;found : boolean ;i n p f : f i l e of InputRec ;
ECE2893 Programming Languages Spring 2011 15 / 26
Pascal ExampleProgram TowersOfHanoi ( input , ou tput ) ;
Vard isks : integer ;
Procedure Hanoi ( source , temp , d e s t i n a t i o n : char ; n : integer ) ;
begini f n > 0 then
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 ;
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 .
ECE2893 Programming Languages Spring 2011 16 / 26
Turbo Pascal IDE
ECE2893 Programming Languages Spring 2011 17 / 26
LISP1 List Processing Language2 Developed in 1958
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:
I Lost in Stupid ParenthesesI Lots of Irritating Superfluous Parentheses
ECE2893 Programming Languages Spring 2011 18 / 26
Lisp Example; ; Options Menu Se t t i ngs; ; =====================(cond
( ( and ( str ingmatch "XEmacs" emacsversion )(boundp emacsmajorversion )( or (and
(= emacsmajorversion 19)(>= emacsminorversion 14) )
(= emacsmajorversion 20) )( fboundp l oadopt ions f i l e ) )
( loadopt ions f i l e " ~ / . xemacsoptions " ) ) ); ; ============================; ; End of Options Menu Se t t i ngs
ECE2893 Programming Languages Spring 2011 19 / 26
Another Lisp Example; ; Customized C/C++ mode s t u f f( defconst mycstyle
( ( ctabalways indent . t )( cautonewline . t )( ccommentonly l ineoffset . 2)( changingbracesalist . ( ( substatementopen a f t e r )
( brace l istopen ) ) )( changingcolonsal ist . ( ( member in i t intro before )
( 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 ) ) )
( ccleanup l is t . ( scopeoperatoremptydefunbracesdefunclosesemi ) )
( 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
. 2)( blockopen
. 0)( knrargdec l in t ro . ) ) )
( cechosyntact ic informationp . t ))
"My C Programming Sty le " )
; ; 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 . ++ ) ) )
ECE2893 Programming Languages Spring 2011 20 / 26
APL1 A Programming Language2 Invented in 19573 A number of built-in operators that worked on arrays, rather than
individual variables.4 Used a number of special keystroke characters for various
operations.I Up and down arrowsI Greek charactersI Set union and intersection
5 Language is known for its terseness, and (in general) lack ofunderstandability.
ECE2893 Programming Languages Spring 2011 21 / 26