140 likes | 260 Views
Types and Related Issues. Bindings. Bindings. Are factors that characterize objects name location value type scope lifetime. Bindings (continued). Can be static or dynamic Can occur at many different times: language design operator symbols to operations language implementation
E N D
Types and Related Issues • Bindings
Bindings • Are factors that characterize objects • name • location • value • type • scope • lifetime
Bindings (continued) • Can be static or dynamic • Can occur at many different times: • language design • operator symbols to operations • language implementation • range of values for integers • compile • variable to type • link • call to library subprogram • load • static variables to memory cells • run • value to variable
Names • Format • length • character set • case • reserved word or keyword for meaningful names in the language? • Aliasing
Location • Static • Stack dynamic • Explicit heap dynamic • Implicit heap dynamic • rare, used in APL and Algol-68
Type • Primitive or complex • Usually bound statically • but can be dynamic in LISP, APL, SNOBOL • Coercion or casting • Strong typing • language “always detects type errors” • Name compatibility or structure compatibility • name: same declaration or same type name • easier to implement but restrictive • structure: same internal structure • may not be strict enough
Type (continued) • Most languages use a combination of equivalence methods • Pascal: usually structure, but in some cases name is used (formal parameters) • C: structure, except for records • C++: name • Ada: restricted form of name • derived types allow types with the same structure to be different • type celcius is new real; type fahrenheit is new real; • subtype allows types to be compatible even with different names • subtype digit is INTEGER range 0..9;
Scope • Range of statements in a program when a name can be referenced (is visible) • Controlled by subprograms, compound statements • Static • most languages • Dynamic • APL, SNOBOL, some LISPs • means no compile-time type checking of non-local objects
Period when data object is allocated memory • Can be different than scope • hole in scope • static variables • invoking external subprogram