5-Names - 5. Names, Bindings, Type Checking and Scopes 5.2...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
ICS 313 - Fundamentals of Programming Languages 1 5. Names, Bindings, Type Checking and Scopes 5.2 Names ± We discuss all user-defined names here ± Design issues for names: ` Maximum length? ` Are connector characters allowed? ` Are names case sensitive? ` Are special words reserved words or keywords? ± 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 implementors often impose one ± Connectors ` Pascal, Modula-2, and FORTRAN 77 don't allow ` Others do
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ICS 313 - Fundamentals of Programming Languages 2 5.2 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 ± 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 ¾ Disadvantage: poor readability ` A reserved word is a special word that cannot be used as a user- defined name 5.3 Variables ± A variable is an abstraction of a memory cell ± Variables can be characterized as a sextuple of attributes ` name, address, value, type, lifetime, and scope ± Name - not all variables have them (anonymous) ± Address - the memory address with which it is associated ` A variable may have different addresses at different times during execution ` A variable may have different addresses at different places in a program ` If two variable names can be used to access the same memory location, they are called aliases ` Aliases are harmful to readability (program readers must remember all of them)
Background image of page 2
ICS 313 - Fundamentals of Programming Languages 3 5.3 Variables (continued) ± How aliases can be created ` Pointers, reference variables, Pascal variant records, C and C++ unions, and FORTRAN EQUIVALENCE (and through parameters - discussed in Chapter 9) ` Some of the original justifications for aliases are no longer valid; e.g. memory reuse in FORTRAN ¾ Replace them with dynamic allocation ± Type ` determines the range of values of variables and the set of operations that are defined for values of that type; in the case of floating point, type also determines the precision ± Value ` the contents of the location with which the variable is associated ± Abstract memory cell ` the physical cell or collection of cells associated with a variable 5.4 The Concept of Binding ± The l-value of a variable is its address ± The r-value of a variable is its value ± A binding is an association, such as between an attribute and an entity, or between an operation and a symbol ± Binding time is the time at which a binding takes place ± Possible binding times ` Language design time (e.g. bind operator symbols to operations) ` Language implementation time (e.g., bind fl. pt.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

5-Names - 5. Names, Bindings, Type Checking and Scopes 5.2...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online