Download presentation
Presentation is loading. Please wait.
Published bySabrina Blankenship Modified over 8 years ago
1
CS451 Programming Languages
2
Why study languages? Description- how to best document languages? Evaluation - which is the best language to use? Learning - how do you learn to learn languages? Design - how do you design a new language? Implementation - how do you implement a language?
3
Turing-Complete languages Turing, 1936 -- Turing Machine Church, 1937 -- Recursive Function Theory Church-Turing Thesis –All effectively computable processes can be simulated by a Turing machine. Implication: All general purpose languages are equivalent in expressiveness. What does it take to be Turing-Complete?
4
Turing-Complete Addition and integers While (or if and goto) Test for equality Unlimited variables (!?) OR Strings that can simulate integers
5
General vs. Special Languages General purpose - C, C++, Java, PL/I –Swiss Army knives - useful for all purposes Special - scripting languages, AWK, Matlab –Dedicated to a particular purpose Data formats - 3D graphics, Powerpoint, etc. –Non-Turing-Complete, special purpose.
6
Language = Syntax + Semantics Syntax –Form, pattern of language How it appears on the screen. if X = Y then X:=3 end; if (X == Y) X = 3;
7
Semantics –How the program means. –Turing-Complete => all semantics equal in some sense –Differences: Raw data types - integers, float, strings, other –Prefer to read directory in C or Perl? Control structures –If, switch, do while, repeat until, case, recursion, functions
8
The Big Three in Syntax Prefix notation + 2 2 –Lisp, Scheme (requires (lots of (parens))) Postfix notation2 2 + –Forth, Postscript (stack-based,no parens) Infix notation2 + 2 –C, Java, and most of the world –Still need parens, precedence rules
9
The Big Three in Control Imperative languages (or sequential) –Do this now! Then this! Logic languages (or declarative) –If you need X, do Y Functional –Print ( f(x,y), g( h(x)) ) A fourth wheel? Message passing –X.print()
10
Other control differences Recursion –Requires reentry to functions Object-oriented grouping and polymorphism Concurrency and parallel programing –Do all these things (a,b,c,d) at the same time –Occam, Linda
11
Semantics and data types Numbers, matrices, vectors –Matlab, APL Strings, pattern matching –Snobol, Awk, Perl Lists –Lisp, Prolog Roll-it-Yourself from little Bits –C, Java, C++
12
Environment Differences Whose standard?Java vs. C# Does it come in an IDE? Free? Compiled vs. Interpreted –Bytecode, Jit, and all that stuff Platform - how big is your class library? Component-based programming –Visual Basic, the most ignored of languages
13
Evaluating a Language Readability Writability Reliability Cost
14
Terminology Simplicity Orthogonality Control and data type considerations Syntax
15
APL - 1960, Iverson
16
Cobol -1953-1959, Hopper $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Multiplier. AUTHOR. Michael Coughlan. * Example program using ACCEPT, DISPLAY and MULTIPLY to * get two single digit numbers from the user and multiply them together DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. PROCEDURE DIVISION. DISPLAY "Enter first number (1 digit) : " WITH NO ADVANCING. ACCEPT Num1. DISPLAY "Enter second number (1 digit) : " WITH NO ADVANCING. ACCEPT Num2. MULTIPLY Num1 BY Num2 GIVING Result. DISPLAY "Result is = ", Result. STOP RUN.
17
Fortran - 1955, Backus C PROGRAM 8.2 COMPUTE AVERAGE OF FIVE HEIGHTS IN FORTRAN REAL AVERAGE, HEIGHTS(5) READ 5 (H(I), I = 1, 5) 5 FORMAT(5F4.0) SUM = 0.0 DO 10 I = 1, 5 10 SUM = SUM + HEIGHTS(I) AVERAGE = SUM / 5.0 PRINT 15, “THE AVERAGE IS “, AVERAGE 15 FORMAT(A15, F6.2) STOP END Sample output 5.0 6.0 6.0 6.0 7.0 THE AVERAGE IS 6.0
18
Algol 60 - 1955-1960, International Committee begin integer N; Read Int(N); begin real array Data[1:N]; real sum, avg; integer i; sum:=0; for i:=1 step 1 until N do begin real val; Read Real(val); Data[i]:=if val<0 then -val else val end; for i:=1 step 1 until N do sum:=sum + Data[i]; avg:=sum/N; Print Real(avg) end
19
Lisp - 1958, McCarthy >(defun toh (height start-peg-name extra-peg-name end-peg-name) (cond ((= height 0) nil) ((= height 1) (list (cons start-peg-name end-peg-name))) (t (append (toh (1- height) start-peg-name end-peg-name extra-peg-name) (toh 1 start-peg-name extra-peg-name end-peg-name) (toh (1- height) extra-peg-name start-peg-name end-peg-name))))) TOH >(defun towers-of-hanoi (height) (toh height 'start-peg 'extra-peg 'end-peg))
20
Prolog - 1972, Colmerauer, Roussel, Kowalski /* FACTS */ mother(gaia,uranus). mother(X,Y) :- parentS(_,X,Y). parentS(uranus,gaia,rhea). parentS(cronus,rhea,zeus). parentS(cronus,rhea,hera). parentS(cronus,rhea,demeter). parentS(zeus,leto,artemis). parentS(zeus,leto,apollo). parentS(demeter,zeus,persephone). female(artemis). female(persephone). female(X) :- mother(X,_). male(apollo). father(X,Y) :- parentS(X,_,Y).
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.