Ch05
Ch05
Names, Bindings,
Type Checking, and
Scopes
ISBN 0-321-33025-0
Chapter#5:Names, Bindings, Type Checking, and
Scopes
• Introduction
• Names
• Variables
• The Concept of Binding
• Type Checking
• Strong Typing
• Scope and Lifetime
1-2
Introduction
1-3
Names
1-4
Names (continued)
• Length
– If too short, they cannot be connotative
– Language examples:
• FORTRAN I: maximum 6
• COBOL: maximum 30
• FORTRAN 90 and ANSI C: maximum 31
• Ada and Java: no limit, and all are significant
• C++: no limit, but implementers often impose one
1-5
Names (continued)
• Connectors
– Pascal, Modula-2, and FORTRAN 77 don't allow
– Others do
1-6
Names (continued)
• Case sensitivity
– Disadvantage: readability (names that look alike
are different)
• worse in C++ and Java because predefined names
are mixed case (e.g.
IndexOutOfBoundsException)
– C, C++, and Java names are case sensitive
• The names in other languages are not
1-7
Names (continued)
• Special words
– An aid to readability; used to delimit or separate
statement clauses
• A keyword is a word that is special only in certain
contexts, e.g., in Fortran
– Real VarName (Real is a data type followed with a name,
therefore Real is a keyword)
– Real = 3.4 (Real is a variable)
– A reserved word is a special word that cannot
be used as a user-defined name
1-8
Variables
1-9
Variables Attributes
1-10
Variables Attributes (continued)
1-11
The Concept of Binding
1-12
Possible Binding Times
1-14
Type Binding
1-15
Explicit/Implicit Declaration
1-16
Dynamic Type Binding
1-17
Categories of Variables by Lifetimes
1-18
Categories of Variables by Lifetimes
1-19
Type Checking
1-20
Type Checking (continued)
1-21
Structure Type Compatibility
1-22
Variable Attributes: Scope
1-23
Blocks
1-24
Evaluation of Static Scoping
1-25
Variable Initialization
1-26