Book contents
- Frontmatter
- Contents
- List of Boxes
- Preface
- Part I Introduction
- Part II Action Notation
- Part III Semantic Descriptions
- Chapter 11 Statements
- Chapter 12 Literals
- Chapter 13 Expressions
- Chapter 14 Declarations
- Chapter 15 Variables
- Chapter 16 Subprograms
- Chapter 17 Tasks
- Part IV Conclusion
- Appendices
- Bibliography
- Symbol Index
- Concept Index
Chapter 15 - Variables
Published online by Cambridge University Press: 19 January 2010
- Frontmatter
- Contents
- List of Boxes
- Preface
- Part I Introduction
- Part II Action Notation
- Part III Semantic Descriptions
- Chapter 11 Statements
- Chapter 12 Literals
- Chapter 13 Expressions
- Chapter 14 Declarations
- Chapter 15 Variables
- Chapter 16 Subprograms
- Chapter 17 Tasks
- Part IV Conclusion
- Appendices
- Bibliography
- Symbol Index
- Concept Index
Summary
Declarations of variables involve types, which indicate the values that may be assigned to the variables. Assignments are statements.
The semantics of variable declarations and assignment statements illustrates the use of the imperative action notation introduced in Chapter 8.
Semantic entities now include variables, types, and access values.
In programs, variables are entities that refer to stored data. The value of a variable is the data to which it currently refers; a variable may be assigned a succession of different values.
This concept of a program variable is quite different from that of a mathematical variable. In mathematics, variables are used to stand for particular unknown values—often the arguments of functions being defined. Although these variables can be ‘assigned’ values, e.g., by function application, their values do not subsequently vary! In the scope of a variable, all occurrences of that variable refer to the same value. In fact mathematical variables correspond exactly to the constant identifiers of programming languages, described in Chapter 14.
A declaration of a variable in a program determines a new variable: one whose value is, in general, independent of that of the values of all other variables. This is called allocating the variable. The declaration then binds an identifier to the variable. Usually the declaration specifies the type of the variable, indicating what sort of value may be assigned to it.
- Type
- Chapter
- Information
- Action Semantics , pp. 163 - 176Publisher: Cambridge University PressPrint publication year: 1992