Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Languages

Similar presentations


Presentation on theme: "Programming Languages"— Presentation transcript:

1 Programming Languages
Chapter 9 Programming Languages

2 OBJECTIVES After reading this chapter, the reader should be able to:
Have a vision of computer language evolution. 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.

3 Contents 9.1 Evolution 9.2 Building a Program 9.3 Program Execution
9.4 Categories of Language 9.5 A procedural Language:C Summary

4 9.1 EVOLUTION

5 Programming language:程序设计语言。
evolution:演化 Computer language :计算机语言。根据预先定义的规则(语法syntax)而写出的预定语句的结合,这些语句组成程序。

6 Evolution of computer languages
Figure 9-1 Evolution of computer languages

7 The only language understood by a computer is machine language.
Note: The only language understood by a computer is machine language.

8 Program 9.1 Program in machine language 1 2 3 4 5 6 7 8 9 10 11 12 13
14 15 16

9 Symbolic language:符号语言。
assembler(汇编程序):将符号代码翻译为机器语言的特定程序。 Assembly language(汇编语言)

10 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 mull (fp),-12(fp),- pushal 6(r2) calls #2,print clrl r0 ret

11 High-level language:高级语言
compilation(编译):高级语言转化为机器语言的过程。 Basic、Pascal、C、C++、Java Natural language:自然语言。

12 Program 9.3 Program in C language #include <stdio.h> int result;
/* This program reads two integer numbers from the keyboard and prints their product */ #include <stdio.h> int main (void) {/*Local Declarations */ int number1, number2; int result; // Statements */ scanf(“%d,%d”,&number1,&number2); result = number1 * number2; printf(“The result is:%d”, result); return 0; }

13 9.2 BUILDING A PROGRAM

14 Key terms Building a program:构建程序。
Executable file (machine language):可执行文件。 (1)writing and editing the program :编写和编辑程序 (2)compiling the program :编译程序 (3)Linking the program with the required library modules:用所需的库模块链接程序

15 Key terms Source file:源文件 preprocessor:预处理程序 Translator:翻译程序
Object module:目标模块 Linker:链接器

16 Figure 9-2 Building a program

17 9.3 PROGRAM EXECUTION

18 Figure 9-3 Program execution 载入

19 9.4 CATEGORIES OF LANGUAGES

20 Key terms Categories of languages:语言的分类。 procedural:过程化语言
Object-Oriented :面向对象的语言 Functional :函数型语言 Declarative:说明型语言 Special:专用语言

21 Categories of languages
Figure 9-4 Categories of languages

22 9.4 categories of Languages
Procedural (imperative)languages Fortran、Cobol、Pascal、C、Ada Object-Oriented C++、Java Encapsulation:封装 Inheritance:继承 Polymorphism:多态

23 Function in a functional language
Figure 9-5 Function in a functional language

24 Functional language: Lisp Scheme see page 176
Figure 9-6 Extracting the third element of a list Functional language: Lisp Scheme see page 176

25 9.4 categories of Languages-Declarative
说明性语言(declarative language )依据逻辑推理的原则回答查询。 First-order predicate calculus:一阶谓词演算 See Page 176

26 9.4 categories of Languages-special
HTML(Hypertext markup language):由格式标记(formatting hints)+超链接(links)组成的伪语言。 Head:文件头。包含页面标题和其他浏览器将要用到的参数。 Body:主体。页面的实际内容。包含文本(text)和标记(tags)。 Tags:嵌入到文本中的符号。

27 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 levels boldface Italic underlined subscript superscript centered line break ordered list unordered list an item in the list an image an address (hyperlink)

28 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>

29 9.5 A PROCEDURAL LANGUAGE: C

30 Key terms (Identifiers)
reserved words:保留字 keywords:关键字 Data types:数据类型 standard types: int char float Derived types(派生类型): pointer(指针)、 enumerated type(枚举类型)、 union(联合)、 array(数组)、 structure(结构)

31 Figure 9-7 Variables(变量)

32 Variable Initialization :变量初始化 float price=23.45;
Key terms (Variable) Variable declaration and definition:变量声明和定义。 float price; Variable Initialization :变量初始化 float price=23.45;

33 Constants:常量。在程序执行过程中不能更改的数据。
Key terms (Constants) Constants:常量。在程序执行过程中不能更改的数据。 Literal Constant :文字常量 Circumference=2*length*width Named Constant:命名常量 const pi=3.14; Symbolic Constant:符号常量 #define taxrate

34 Constants and Types:常量和类型。
Key terms (Constants) Constants and Types:常量和类型。 /*Integer literal*/ /*Floating-point literal*/ ' A ' /*Character literal*/ "Hello " /*String literal*/

35 Key terms (Input and Output)
scanf(" %d ",&num); Output: printf(" The value is: %d",&num);

36 Key terms (Expressions)
operator:运算符 Arithmetic operator:算术运算符 relational operator:关系运算符 logical operator:逻辑运算符 assignment operator:赋值运算符 operand:操作数 3+4

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

38 Greater than or equal to
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

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

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

41 Key terms (Statements)
Expression statement:表达式语句。 b=a+4; b+c*4; Compound statement:复合语句 { x=1; y=20; } Selection statement:选择语句 Iterative statement:循环语句 Jump statement:跳转语句

42 Figure 9-8 Statements

43 Figure 9-9 Functions Side effect of a function

44 Function declaration(函数声明)
Figure 9-10 Function declaration(函数声明)

45 printf(“This is a c program.”); }
main() { printf(“This is a c program.”); } This is a c program

46 printf(“Sum is %d”,result); }
main() /*求两数之和*/ {int num1,num2,result; num1=12; num2=23; result=num1+num2; printf(“Sum is %d”,result); } Sum is 35

47 scanf(“%d,%d”,&num1,&num2); Largest=max(num1,num2);
int max(int x,int y); main() {int num1,num2,largest; scanf(“%d,%d”,&num1,&num2); Largest=max(num1,num2); printf(“The largest is %d”,largest); } int max(int x,int y) {int z; if(x>y) z=x; else z=y return(z);} 18,20 This largest is 20

48 Figure 9-11 Selection if-else statement

49 Figure 9-12 switch statement Selection

50 Figure 9-13 while loop repetition

51 Figure 9-14 for loop

52 do-while loop Figure 9-15

53 Summary 计算机能理解的唯一语言是机器语言(machine language). • 符号语言使用符号来表示各种机器语言指令,符号语言也称为汇编语言。 高级语言可以使程序员避免考虑硬件。 • 构建程序的步骤包括编写、编辑、编译和链接代码。 有5种计算机语言:过程化语言、面向对象的语言、函数型语言、说明性语言、专用语言。

54 Summary 标识符在程序中用来命名数据和其他对象. • 数据类型定义了值的集合和可以应用于这些值的指令集合。 C语言中的标准数据类型有整型(int),字符型(char)、浮点型(float)。 • 常量就是在执行过程中不可改变的数据值。 变量是存储单元的名字。

55 表达式是一系列操作数和运算符的组合. Summary • 语句使程序执行动作。 函数是执行特定任务的独立模块。
• 语句使程序执行动作。 函数是执行特定任务的独立模块。 • C语言有一个称为main的主函数和0个或多个其他函数。 变量是存储单元的名字。

56 C中if-else语句或switch语句可以完成多个判断。
Summary C中if-else语句或switch语句可以完成多个判断。 C中的循环可以通过while、for、do-while来实现。


Download ppt "Programming Languages"

Similar presentations


Ads by Google