Title: Programming Languages
1Chapter 9
ProgrammingLanguages
2OBJECTIVES
After reading this chapter, the reader should be
able to
39.1
EVOLUTION
4Figure 9-1
Evolution of computer languages
5Program 9.1
Program in machine language
00000000 00000100 0000000000000000 01011110 000011
00 11000010 0000000000000010 11101111 00010110
0000000000000101 11101111 10011110 000000000000
1011 11111000 10101101 11011111 0000000000010010
01100010 11011111 0000000000010101 11101111 000
00010 11111011 0000000000010111 11110100 10101101
11011111 0000000000011110 00000011 10100010 110111
11 0000000000100001 11101111 00000010 11111011 000
0000000100100 01111110 11110100 10101101 111110
00 10101110 11000101 0000000000101011 00000110 101
00010 11111011 0000000000110001 11101111 00000010
11111011 0000000000110100 00000100 0000000000
111101 00000100 0000000000111101
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
6Note
The only language understood bya computer is
machine language.
7Program 9.2
Program in symbolic language
Entry main, mltr2gt subl2 12,sp jsb
CMAIN_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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
8Program 9.3
Program in C language
/ This program reads two integer numbers from
the keyboard and prints their product. /
include ltiostream.hgt int main (void) //
Local Declarations int number1 int
number2 int result // Statements cin gtgt
number1 cin gtgt number2 result number1
number2 cout ltlt result return 0 // main
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
99.2
BUILDING A PROGRAM
10Figure 9-2
Building a program
119.3
PROGRAM EXECUTION
12Figure 9-3
Program execution
139.4
CATEGORIES OF LANGUAGES
14Figure 9-4
Categories of languages
15Figure 9-5
Function in a functional language
16Figure 9-6
Extracting the third element of a list
17Table 9.1 Common tags
Meaning---------------------------- d
ocument document head document body document
title different header levelsboldface Italic unde
rlined subscript superscript centered line
break ordered list unordered list an item in the
list an image an address (hyperlink)
Beginning Tag ---------------- ltHTMLgt ltHEADgt ltBODY
gt ltTITLEgt ltHigt ltBgt ltIgt ltUgt ltSUBgt ltSUPgt ltCENTERgt ltB
Rgt ltOLgt ltULgt ltLIgt ltIMGgt ltAgt
Ending Tag ---------------- lt/HTMLgt lt/HEADgt lt/BODY
gt lt/TITLEgt lt/Higt lt/Bgt lt/Igt lt/Ugt lt/SUBgt lt/SUPgt lt/CE
NTERgt lt/OLgt lt/ULgt lt/LIgt lt/Agt
18Program 9.4
HTML Program
ltHTMLgt ltHEADgt ltTITLEgt Sample Document
lt/TITLEgt lt/HEADgt ltBODYgt This is the
picture of a book ltIMG
SRC"Pictures/book1.gif" ALIGNMIDDLEgt lt/BODYgt
lt/HTMLgt
199.5
A PROCEDURAL LANGUAGE C
20Figure 9-7
Variables
21Table 9.2 Arithmetic operators
Example---------------------- 3 5 2 -
4 Num 5 Sum / Count Count
4 ----------------------- Count Count --
Operator ---------------- - / ----------
--
Definition ---------------- Addition Subtraction M
ultiplication Division (quotient) Division
(remainder) ----------------------- Increment Decr
ement
22Table 9.3 Relational operators
Example---------------------- Num1 lt 5 Num1
lt 5 Num2 gt 3 Num2 gt 3 Num1 Num2 Num1 !
Num2
Operator ---------------- lt lt gt gt !
Definition ---------------- Less than Less than
or equal to Greater than Greater than or equal
to Equal to Not equal to
23Table 9.4 Logical operators
Example---------------------- ! ( Num1 lt Num2
) (Num1 lt 5 ) (Num2 gt 10 ) (Num1 lt 5 )
(Num2 gt 10 )
Operator ---------------- !
Definition ---------------- NOT AND OR
24Table 9.5 Assignment operators
Meaning---------------------- Store
5 in Num Num Num 5 Num Num -
5 Num Num 5 Num Num /
5 Num Num 5
Operator ---------------- - /
Example ----------------
Num 5 Num 5 Num
- 5 Num 5 Num
/ 5 Num 5
25Figure 9-8
Statements
26Figure 9-9
Side effect of a function
27Figure 9-10
Function declaration
28Figure 9-11
if-else statement
29switch statement
Figure 9-12
30Figure 9-13
while loop
31for loop
Figure 9-14
32do-while loop
Figure 9-15