COSC 2P05 - Programming Languages (Week 2) PDF
Document Details
![SeamlessOmaha2830](https://quizgecko.com/images/avatars/avatar-16.webp)
Uploaded by SeamlessOmaha2830
Brock University
COSC
M. Winter
Tags
Summary
This presentation covers several programming languages, including PL/I, APL, Snobol, Simula 67, C, and examples of PL/I, C, and Ada programs. The documents also contains examples for each language. It traces the history of programming concepts and features.
Full Transcript
COSC 2P05 – Programming languages PL/I First attempt to design a language that could be used for a broad spectrum of application areas Developed by IBM in 1963 PL/I includes the best parts of – Algol 60 (block struc...
COSC 2P05 – Programming languages PL/I First attempt to design a language that could be used for a broad spectrum of application areas Developed by IBM in 1963 PL/I includes the best parts of – Algol 60 (block structure and recursion) – Fortran IV (separate compilation with communication through global data) – COBOL (data structures, input/output, report generating facilities) Huge language with a lot of features; first in having – Creating concurrently executing subprograms – Exception handling; 23 different types of exceptions or run- time errors – Efficient linking for nonrecursive subprograms – Pointers were included as a data type – Cross-sections of arrays could be referenced © M. Winter 2.1 COSC 2P05 – Programming languages A PL/I Program PLIEX: PROCEDURE OPTIONS (MAIN); DECLARE INTLIST (1:99) FIXED. DECLARE (LISTLEN, COUNTER, SUM, AVERAGE, RESULT) FIXED; SUM = 0; RESULT = 0; GET LIST (LISTLEN); IF (LISTLEN > 0) & (LISTLEN < 100) THEN DO; DO COUNTER = 1 TO LISTLEN; GET LIST (INTLIST (COUNTER)); SUM = SUM + INTLIST (COUNTER); END; © M. Winter 2.2 COSC 2P05 – Programming languages AVERAGE = SUM / LISTLEN; DO COUNTER = 1 TO LISTLEN; IF INTLIST (COUNTER) > AVERAGE THEN RESULT = RESULT + 1; END; PUT SKIP LIST ('THE NUMBER OF VALUES > AVERAGE IS:’); PUT LIST (RESULT); END; ELSE PUT SKIP LIST ('ERROR-INPUT LIST LENGTH IS ILLEGAL'); END PLIEX; © M. Winter 2.3 COSC 2P05 – Programming languages APL and SNOBOL Both languages are not based on any previous language Common: Dynamic typing and storage allocation APL – Designed around 1960 at IBM – Published in the book “A Programming Language” in 1962 – Large number of powerful operators – Hard to maintain SNOBOL – Designed in the early 1960s for text processing – Powerful operations for string pattern matching © M. Winter 2.4 COSC 2P05 – Programming languages SIMULA 67 SIMULA I was developed between 1962 and 1964 in Norway – Designed for simulations – Later extended to become a general purpose language SIMULA 67 presented in 1967 – Extends Algol 60 – Introduces coroutines – Introduces the class construct © M. Winter 2.5 COSC 2P05 – Programming languages C Developed at Bell Laboratories in 1972 Ancestors: CPL, BCPL, B, and Algol 68 Designed as a language to implement UNIX Fist official standard in 1989 (ANSI C); next in 1999 (C99) Lack of complete type checking © M. Winter 2.6 COSC 2P05 – Programming languages A C Program int main (){ int intlist, listlen, counter, sum, average, result; sum = 0; result = 0; scanf("%d", &listlen); if ((listlen > 0) && (listlen < 100)) { for (counter = 0; counter < listlen; counter++) { scanf("%d", &intlist[counter]); sum += intlist[counter]; } average = sum / listlen; © M. Winter 2.7 COSC 2P05 – Programming languages for (counter = 0; counter < listlen; counter++) if (intlist[counter] > average) result++; printf("Number of values > average is:%d\n", result); } else printf("Error-input list length is not legal\n"); } © M. Winter 2.8 COSC 2P05 – Programming languages C Examples What does this C program print? int j; for(int i=(j=1)*n; i; j=j*i--); printf("%d",j); And how about this one? for(char *p=str, *q=str+strlen(str)-1; p 0) and (List_Len < 100) then -- Read input data into an array and compute the sum © M. Winter 2. COSC 2P05 – Programming languages for Counter := 1.. List_Len loop if Int_List(Counter) > Average then Result:= Result+ 1; end if; end loop; -- Print result Put ("The number of values > average is:"); Put (Result); New_Line; else Put_Line ("Error-input list length is not legal"); end if; end Ada_Ex; © M. Winter 2. COSC 2P05 – Programming languages Ada Tasks (Concurrency) with TEXT_IO; procedure PRODUCER_CONSUMER is use TEXT_IO; task PRODUCER is end PRODUCER; task CONSUMER is entry NO_MORE_CARDS; end CONSUMER; task BUFFER is entry STORE(C: in CHARACTER); entry RETRIEVE(C: out CHARACTER); entry PRODUCER_DONE; end BUFFER; task body PRODUCER is separate; task body CONSUMER is separate; task body BUFFER is separate; begin PUT_LINE("They're off and running"); end PRODUCER_CONSUMER; © M. Winter 2. COSC 2P05 – Programming languages separate (PRODUCER_CONSUMER) task body BUFFER is BUFFER_SIZE: constant INTEGER := 100; BUFFER_DATA: array (0..BUFFER_SIZE - 1) of CHARACTER; BUFFER_FRONT: INTEGER := 0; BUFFER_REAR: INTEGER := 0; BUFFER_EMPTY: BOOLEAN := TRUE; BUFFER_FULL: BOOLEAN := FALSE; PRODUCER_IS_DONE: BOOLEAN := FALSE; begin while not (BUFFER_EMPTY and PRODUCER_IS_DONE) loop select when not BUFFER_FULL => accept STORE(C: in CHARACTER) do BUFFER_DATA(BUFFER_REAR) := C; BUFFER_REAR := (BUFFER_REAR + 1) rem BUFFER_SIZE; BUFFER_EMPTY := FALSE; BUFFER_FULL := BUFFER_REAR = BUFFER_FRONT; end STORE; or © M. Winter 2. COSC 2P05 – Programming languages when not BUFFER_EMPTY => accept RETRIEVE(C: out CHARACTER) do C := BUFFER_DATA(BUFFER_FRONT); BUFFER_FRONT := (BUFFER_FRONT+1)rem BUFFER_SIZE; BUFFER_EMPTY := BUFFER_FRONT = BUFFER_REAR; BUFFER_FULL := FALSE; end RETRIEVE; or accept PRODUCER_DONE do PRODUCER_IS_DONE := TRUE; end PRODUCER_DONE; end select; end loop; CONSUMER.NO_MORE_CARDS; end BUFFER; © M. Winter 2. COSC 2P05 – Programming languages Smalltalk First object-oriented programming language Originated in the PhD thesis of Alan Kay in the late 1960s as part of the Dynabook idea Kay developed an “Interim” Dynabook, consisting of Xerox Alto hardware and Smalltalk-72 at Xerox. In 1980 a better Dynabook using Smalltalk-80 was developed Features – Everything in Smalltalk is an object – Computing is done by sending messages to an object by invoking one of its methods – A reply to a message is an object – Classes are object abstractions that can create objects Smalltalk used a graphical user interface (windowed) © M. Winter 2. COSC 2P05 – Programming languages A Smalltalk Program "Smalltalk Example Program" "The following is a class definition, instantiations of which can draw equilateral polygons of any number of sides" class name Polygon superclass Object instance variable names ourPen numSides sideLength "Class methods“ "Create an instance" new ^ super new getPen "Get a pen for drawing polygons" getPen ourPen