1 / 44

Chapter 9

Chapter 9. Programming Languages. O BJECTIVES. Distinguish between machine, assembly, and high-level languages. Understand the process of creating and running a program.

huey
Download Presentation

Chapter 9

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 9 ProgrammingLanguages

  2. OBJECTIVES Distinguish between machine, assembly, and high-level languages. Understand the process of creating and running a program. Distinguish between the different categories of languages:procedural, object-oriented, functional, declarative, and special. Become familiar with elements of the procedural language C. Have a vision of computer language evolution. After reading this chapter, the reader should be able to:

  3. 9.1 EVOLUTION

  4. Figure 9-1 Evolution of computer languages A computer language Is a set of predefined words that are combined into a program according to predefined rules (syntax)

  5. Program 9.1 Program in machine language 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 00000000 00000100 0000000000000000 01011110 00001100 11000010 0000000000000010 11101111 00010110 0000000000000101 11101111 10011110 0000000000001011 11111000 10101101 11011111 0000000000010010 01100010 11011111 0000000000010101 11101111 00000010 11111011 0000000000010111 11110100 10101101 11011111 0000000000011110 00000011 10100010 11011111 0000000000100001 11101111 00000010 11111011 0000000000100100 01111110 11110100 10101101 11111000 10101110 11000101 0000000000101011 00000110 10100010 11111011 0000000000110001 11101111 00000010 11111011 0000000000110100 00000100 0000000000111101 00000100 0000000000111101

  6. Note: The only language understood bya computer is machine language. • Instruction in ML must be in streams of 0s and 1s. • Internal circuit of a computer is made of switches, transistors and other electronic devices. • Two states : off (0) and on (1)

  7. Symbolic Language • 1950’s –Grace Hopper, a mathematician + U.S Navy • Develop concept of language that mirrored the ML using symbols, mnemonics • To represent various ML instruction • Known as symbolic language • Assembler : used to translate symbolic code into ML • Because SL had to be assembled into ML • Known as : Assembly language

  8. Program 9.2 Program in symbolic language 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Entry main, ^m<r2> subl2 #12,sp jsb C$MAIN_ARGS movab $CHAR_STRING_CON pushal -8(fp) pushal (r2) calls #2,read pushal -12(fp) pushal 3(r2) calls #2,read mull3 -8(fp),-12(fp),- pushal 6(r2) calls #2,print clrl r0 ret

  9. High Level Language • Required programmer to concentrate on the hardware • SL individually coded= tedious • Led to development of high-level languages • HL- portable to diff computers • Programmer concentrate on the application rather than the intricacies of PC • HL converted to ML – compilation • Eg: BASIC, COBOL, Pascal, Ada, C, C++ and JAva

  10. Program 9.3 Program in C++ language 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 /* This program reads two integer numbers from the keyboard and prints their product. */ #include <iostream.h> int main (void) { // Local Declarations int number1; int number2; int result; // Statements cin >> number1; cin >> number2; result = number1 * number2; cout << result; return 0; } // main

  11. Natural Language • English, French, Chinese

  12. 9.2 BUILDING A PROGRAM

  13. Computer understand a program only if the program translated to ML Programmer Job : Write a program, turn it into a executable file (ML) • Process • Writing and editing the program • Compiling the program • Linking the program with the required library modules

  14. Writing & Editing Program Text editor: Software used to write a program Source file: file that input in the compiler Compiling Program • Information : is a source file stored on disk- translated to ML • Compiler : 2 separate program; preprocessor ; translator • Preprocessor: reads the source code and prepare for translator; scans for special commands known as preprocessor directives ( tell preprocessor to look special code library) -> result: translation unit • Translator : convert translation unit into ML; reads; -> result: object module ( code in ML)

  15. Linker Programs Linker : assembles all of these functions, yours and the system’s into your final executable program

  16. Figure 9-2 Building a program

  17. 9.3 PROGRAM EXECUTION

  18. Figure 9-3 Program execution Loader: locates the executable program and reads it into memory

  19. 9.4 CATEGORIES OF LANGUAGES

  20. Figure 9-4 Categories of languages

  21. FORTRAN- FORmula TRANslation COBOL –COmmon Business_Oriented Language PASCAL C language Ada PROCEDURAL(IMPERATIVE) LANGUAGE

  22. In OOP, the object and the operations tied together The objects in OOP are active C++ language Java Three principles Encapsulation – hiding the data Inheritance – inherit from another object Polymorphism – define several operations with same name OBJECT-ORIENTED LANGUAGES

  23. Figure 9-5 Function in a functional language Considered a mathematical function. Function is a black box that maps a list of inputs to a list of outputs

  24. Figure 9-6 Extracting the third element of a list

  25. LISP : LiSt Programming =a list-processing programming language which everything considered a list Scheme : Version from LISP; a set of primitive functions that solves problems

  26. Declarative (LOGIC) language : • Use the principal of logical reasoning to answer queries. • Based on formal logic defined by Greek mathematicians; later develop into what is called firs-order predicate calculus. Prolog : famous; By A.Colerauer Made of facts and rules Eg: human (John) mortal (human) Q? ?-mortal (Jon) Answer = Yes

  27. Special Language • Mixture of two or more models and others belong to specific task • HTML : Hypertext Markup Language; is a pseudo language that includes marks • PERL : Practical Extraction and Report Language ; a high level with a syntax similar to C • SQL : Structured Query Language ; language used to answer queries about databases

  28. Table 9.1 Common tags Beginning Tag ---------------- <HTML> <HEAD> <BODY> <TITLE> <Hi> <B> <I> <U> <SUB> <SUP> <CENTER> <BR> <OL> <UL> <LI> <IMG> <A> Ending Tag ---------------- </HTML> </HEAD> </BODY> </TITLE> </Hi> </B> </I> </U> </SUB> </SUP> </CENTER> </OL> </UL> </LI> </A> Meaning---------------------------- document document head document body document title different header levelsboldface Italic underlined subscript superscript centered line break ordered list unordered list an item in the list an image an address (hyperlink)

  29. Program 9.4 HTML Program <HTML> <HEAD> <TITLE> Sample Document </TITLE> </HEAD> <BODY> This is the picture of a book: <IMG SRC="Pictures/book1.gif" ALIGN=MIDDLE> </BODY> </HTML>

  30. 9.5 A PROCEDURAL LANGUAGE: C

  31. Figure 9-7 Variables

  32. Table 9.2 Arithmetic operators Operator ---------------- + - * / % ---------- ++-- Definition ---------------- Addition Subtraction Multiplication Division (quotient) Division (remainder) ----------------------- Increment Decrement Example---------------------- 3 + 5 2 - 4 Num * 5 Sum / Count Count % 4 ----------------------- Count ++ Count --

  33. Table 9.3 Relational operators Operator ---------------- < <= > >= == != Definition ---------------- Less than Less than or equal to Greater than Greater than or equal to Equal to Not equal to Example---------------------- Num1 < 5 Num1 <= 5 Num2 > 3 Num2 >= 3 Num1 == Num2 Num1 != Num2

  34. Table 9.4 Logical operators Operator ---------------- ! && || Definition ---------------- NOT AND OR Example---------------------- ! ( Num1 < Num2 ) (Num1 < 5 ) && (Num2 > 10 ) (Num1 < 5 ) || (Num2 > 10 )

  35. Table 9.5 Assignment operators Operator ---------------- == += -= *= /= %= Example ---------------- Num = 5 Num += 5 Num -= 5 Num *= 5 Num /= 5 Num %= 5 Meaning---------------------- Store 5 in Num Num = Num + 5 Num = Num - 5 Num = Num * 5 Num = Num / 5 Num = Num % 5

  36. Figure 9-8 Statements

  37. Figure 9-9 Side effect of a function

  38. Figure 9-10 Function declaration

  39. Figure 9-11 if-else statement

  40. switch statement Figure 9-12

  41. Figure 9-13 while loop

  42. for loop Figure 9-14

  43. do-while loop Figure 9-15

  44. Mirrored Machine language through symbols/special word.

More Related