1. Trang chủ
  2. » Công Nghệ Thông Tin

Nguyên lý các ngôn ngữ lập trình Lập trình chỉ thị

43 378 2

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 43
Dung lượng 613,35 KB

Nội dung

Content of Lesson 1. Imperative Programming Model 2. Memory Management 3. Some Typical Programming Techniques 4. Some exercises Command in an imperative language were simple abstraction of the instruction in standard con Neumann machines These included assignment statement, conditional statement, branch statement, loop statement

IT6020 (c) PGS.TS. H.Q.Thắng, Dep. of SE 1 IT6020 Nguyên l cc ngôn ng lp trnh Lecturer: Dr. Huỳnh Quyết Thắng, Assoc. Prof at Dept. of Software Engineering, SoICT, HUST Email: thanghq@soict.hut.edu.vn Mobile: 0913536752 Chương 2 – Lp trnh ch th AT in PMT 2 Content of Lesson 1. Imperative Programming Model 2. Memory Management 3. Some Typical Programming Techniques 4. Some exercises (c) PGS.TS. H.Q.Thắng, Dep. of SE AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE 3 1. Imperative Programming model Von Neumann machine has a memory, which contains both programming instruction (the program store) and data values (data store) Imperative languages have variable declaration, expression and command  Declaration assign names to memory allocation and associate types with stores values  Expression are interpreted in term of the current value in the data store  Commands are normally executed in the ordr they appear in the program store, although conditional or unconditional jumps can change the flow of execution AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE 4 1. Imperative Programming model Command in an imperative language were simple abstraction of the instruction in standard con Neumann machines These included assignment statement, conditional statement, branch statement, loop statement AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE 5 1.1. Feature of imperative programming languages Data type for integer, real, characters, string, booleans and their operator Control structures: statement sequencing, conditionals, branching statements, for and while loop, case (switch) statement Assignment statement Array and element assignment Record structures and element assignment Input and output commands Pointer Procedure and function AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE 6 1.2. Naming and Variables The model uses a single-assignment store, which is a set of variables that are initially unbound and that can be bound to one value. AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE 7 1.2. Naming and Variables Declarative variables: Variables in the single-assignment store are called declarative variables. We use this term whenever there is a possible confusion with other kinds of variables. Later we will also call these variables dataflow variables because of their role in dataflow execution. Once bound, a declarative variable stays bound throughout the computation and is indistinguishable from its value. What this means is that it can be used in calculations as if it were the value. Doing the operation x + y is the same as doing 11 + 22, if the store is {x = 11, y = 22}. AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE 8 1.2. Naming and Variables Value store: A store where all variables are bound to values is called a value store. A value is a mathematical constant. Value creation: The basic operation on a store is binding a variable to a newly-created value. We will write this as x=value. Here, x refers directly to a variable in the store (and is not the variable’s textual name in a program!) and value refers to a value, e.g., 314 or [1 2 3]. AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE 9 1.2. Naming and Variables Variable identifiers: So far, we have looked at a store that contains variables and values, i.e., store entities, with which calculations can be done. It would be nice if we could refer to a store entity from outside the store. This is the role of variable identifiers. A variable identifier is a textual name that refers to a store entity from outside the store. The mapping from variable identifiers to store entities is called an environment. AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE 10 1.2. Naming and Variables Variable-variable binding: Variables can be bound to variables. For example, consider two unbound variables x1 and y1 referred to by the identifiers X and Y.  x1=X  y1=Y Dataflow variables: In the declarative model, creating a variable and binding it are done separately. What happens if we try to use the variable before it is bound? We call this a variable use error. . Expression Expression in real language:  Scope resolution  Member Selection  Unary negation, complement. increment, address- of, de-reference, allocate, de-allocate  Multiply, divide, Modulo  Add,. statements  SwitchStatement->switch (Expression) {cases}  Cases->Case Cases | Default  Case->CaseHead Cases | CaseHead Statement  CaseHead-> case Literal;  Default->default : statement Break,. and Semantics of statements in real language For loops  ForStatement->for (assigntment1; Expression; Assigntment2) Statement Do Statement  DoStatement-> do Statement while (Expression) Switch

Ngày đăng: 28/07/2014, 00:33

TỪ KHÓA LIÊN QUAN

w