Presentation is loading. Please wait.

Presentation is loading. Please wait.

Evolution of Programming Languages Generations of PLs.

Similar presentations


Presentation on theme: "Evolution of Programming Languages Generations of PLs."— Presentation transcript:

1 Evolution of Programming Languages Generations of PLs

2 First generation computers relied on machine language, the instructions of which are long strings of binary codes. http://fahmirahman.wordpress.com/2011/01/04/five-generations-of-computer/

3 Generations of PLs 1GL – Machine language. String of 0’s and 1’s. Directly executed by CPU 2GL – Assembly language. Symbolic equivalent of machine language 3GL – Procedural language. Give how to do/ algorithm. E.g. Pascal 4GL – Declarative language. Specify what to do. E.g. SQL 5GL – Related to artificial intelligence

4 Low Level and High Level PLs Low Level PLs (1-2GLs) – Instructions directly operate computer hardware – Need to have machine level knowledge in order to write programs – Machine dependent – Machine language and assembly language High Level PLs (3-5 GLs) – More English like – Closer to human language

5 1 GL – Machine language A low level language Consists of strings of 0’s and 1’s Directly executed by the CPU Difficult and tedious to write and maintain Quickly replaced by assembly language (2GL)

6 2 GL – Assembly Language Instruction has a one-to-one correspondence with its machine language equivalent Instruction consists of opcode = operation code Action Memory Address, register or value e.g. ADD AX, 3 ; increase AX by 3 OpcodeOperand(s) Machine instructions are symbolized using mnemonics into assembly language instructions

7 A sample machine language program and the corresponding assembly language program

8 2 GL – Assembly Language A low level language Translated into machine language for execution Manipulate computer down to register level Hardware dependent Difficult to learn and debug Directly control of CPU operations, therefore the codes produce are more efficient

9 Extended Reading

10 Microsoft Windows DEBUG Textbook P.6 Act. 1 - Writing a real assembly language program General registers AX BX CX DX The 80x86 CPU has four general registers The accumulator AX stores the results of math operations. The base register BX stores the address or pointer. The counting register CX is used in counting and looping. The data register DX stores data.

11 Commands of DEBUG Command/ Prompt Operation -A prompt for accepting command rDisplay the contents of CPU registers. raxDisplay the contents of AX. :A prompt for accepting value to the register being worked with. aStart assembling (translating) symbolic instructions into machine codes. i.e. Start to accept assembly language program. tTrace the program. i.e. Execute the program and show the contents of the register. qQuit DEBUG.

12 A sample assembly language program explained Assembly InstructionExplanation mov ax, 5 Move the value 5 (hex) to register AX. mov bx, 3 Move the value 3 (hex) to register BX. add ax, bx Add the values stored in register AX and BX and the result back to register AX. int 20 Call the DOS interrupt 20 to terminate the program. Choose run > cmd to open the command prompt window Enter debug to the command prompt to run debug

13 Want to try it out yourself? P.6 Activity 1 Writing a simple assembly language program using DEBUG 5 minutes Typo in textbook P.8 Step 9: the first -t should be -r

14 3GLs (high level) Close to human language, more English like E.g. Pascal, FORTRAN, BASIC, COBOL, C,... Programmers can focus on solving problems rather than manipulating registers and memory addresses Easy to write, debug and maintain Loss of direct control of CPU operations and memory addresses Programs more portable (machine independent)

15 Assembly languagePascal 185B:0100 mov ax, 5 185B:0103 mov bx, 3 185B:0106 add ax, bx 185B:0108 int 20 185B:010A var a, b : integer; begin a := 5; b := 3; a := a + b end. The same program written in assembly language (2GL) and Pascal (3GL). The use of variables, data types and mathematical expression syntax in 3GL hides the complexities of CPU’s internal operations from the programmer.

16 4GLs Declarative / non-procedural Specify what to do/ not how to do In 3GLs, detail steps in solving a problem has to be coded, in 4GL fewer statements are necessary More towards solving specific problems - SQL to make queries on relational database - SPSS to perform data analysis

17 SQL statement for outputting the number of female students in each class from the database table student : SELECT class, COUNT(*) FROM student WHERE sex = "F" GROUP BY class;

18 5GLs Related to artificial intelligence (AI) Able to search for solution of the problem by itself Based on constraints and conditions given Programmers can focus on what problems need to be solved and what constraints and conditions are to be satisfied, rather then algorithm to solve the problem E.g. Prolog

19 Prolog (Program Logic) In Prolog, the program logic is represented by relations, and queries can be constructed and run on these relations. Relations are defined by clauses and there are two types of clauses: facts and rules

20 Facts in Prolog loves(peter, snacks). - a fact clause that defined the relation loves between two objects peter and snacks - note that a clause must end with a full stop - object names must be in lower case (upper-case is for variable) - the fact defined can be interpreted as ‘Peter loves snacks’ (not the other way round) The following 5 clauses define 5 facts: loves(peter, snacks). loves(peter, mary). loves(mary, fruit). loves(mary, snacks). loves(mary, tom).

21 Queries in Prolog loves(peter,tom). can be interpreted as ‘Does Peter love tom?’ loves(peter,X). can be interpreted as ‘What/ who does Peter love?’ loves(X,snacks). can be interpreted as ‘Who loves snacks?’ Notes: - X is in upper case to indicate that it is a variable - loves(peter,tom). can be a fact clause or a query, depend on usage

22 QueryResult loves(peter,tom).no loves(peter,X).X = snacks X = loves(X,snacks).X = Queries in Prolog Fill in the table based on the following facts: loves(peter, snacks). loves(peter, mary). loves(mary, fruit). loves(mary, snacks). loves(mary, tom). Peter mary

23 Rules in Prolog loves(peter, X) :- loves(mary, X). means Peter loves X if Mary loves X lovers(X, Y) :- loves(X, Y), loves(Y, X). means X and Y are lovers if X loves Y and Y loves X

24 Given the 5 facts and the rule loves(peter, snacks). loves(peter, mary). loves(mary, fruit). loves(mary, snacks). loves(mary, tom). loves(peter, X) :- loves(mary, X). The query loves(peter, X) returns X = snacks X = (and more...)

25 Given the 5 facts and the rule loves(peter, snacks). loves(peter, mary). loves(mary, fruit). loves(mary, snacks). loves(mary, tom). loves(peter, X) :- loves(mary, X). The query loves(peter, X) returns X = snacks X = mary X = fruit X = snacks X = tom

26 Given the 3 facts and the rule loves(tom, mary). loves(peter, mary). loves(mary, tom). lovers(X, Y) :- loves(X, Y), loves(Y,X). The query lovers(peter, mary). returns The query lovers(mary, tom). returns The query lovers(tom, mary). returns no true

27 Your turn now (P.15 Activity 2) Step1: Create a text file named loves.pl storing all the relations (facts and rules) Step2: Open GNU Prolog enter the command consult('s:/loves.pl'). Step3: Make queries

28 Generations of PLs 1GL – Machine language. String of 0’s and 1’s. Directly executed by CPU 2GL – Assembly language. Symbolic equivalent of machine language 3GL – Procedural language. Give how to do/ algorithm. E.g. Pascal 4GL – Declarative language. Specify what to do. E.g. SQL 5GL – Related to artificial intelligence. E.g. Prolog

29 Hierarchy of programming languages

30 Try it out with GNU Prolog Step1: Create a text file named loves.pl storing all the relations (facts and rules) Step2: Open GNU Prolog enter the command consult('s:/loves.pl'). Step3: Make queries Reminders: -don’t leave out the full stop -place loves.pl in your S drive ~ simpler path


Download ppt "Evolution of Programming Languages Generations of PLs."

Similar presentations


Ads by Google