A variable must be found to the properties associated with it. Aside from its name and associated address, it should be bound to some type and a value. The time of this binding, whether during compilation or execution, becomes important in understanding a language. When we add functions and procedures, we must consider also the scope and lifetime of these variables.
1.0
IN THIS CHAPTER
When considering variables and types issues, it is helpful to look at both the basic concepts and some principles for their implementation. In this chapter we will consider:
- Primitive data types and their representation
- Binding of attributes to variables
- Blocks, scope, and implementation via avtivation records
- Structured types and their allocation
- Type checking and type compatibility issues
PRIMITIVE DATA TYPES
Languages provide the programmer with certain basic data types, specifying both the set of data items data a set of operations on them. The number of types vary, from pure LISP with one essential type, the symbolic expression or S-expression, to a rich language Ada, with six basic types : enumeration, integer, real, array, record, and access, as well as types derived from these. The enumeration types we will present include character and boolean types.
Many Labguages include such primitive types as integer, real, character, boolean, and pointer. While the specifications of these types may varubetween languages and machines, there are a number of commont aspects.
Integer
One of the most common primitive data types as integer. For many languages, the integer size may be determined by the word size of the target machine.1 While several representations are possible, if a machine supports 2s-complement arithmetic with a 16-bit word, using one bit for the sign, the largest 15-bit value would be +32,767. Hence this would likely become the value of maxint on this machine for a language like Pascal. Clearly like can be a problem if we desire that programs be portable between target machines with different word sizes that support a common language.
Some language like C and Ada also provide short integer and long integer types. These are generally implementation dependent on what hardware support available and may use a byte or word for short integers, while long integers might be composed of double words of four words. Again, if portability is important, one must be aware of differences on target machines.
It also becoming common for a language to support unsigned integers, in which positive values only are used. In this case, room is not needed for a sign bit so we can reach a maximum value of 65,535 on a 16-bit machine. The language C even includes unsigned short and long integers.
Some machines (such as the IBM 370) are able to store integers in decimal rather than binary, format. In this binary coded decimal (BCD) representations, digits 0 to 9 are stored in four bits each, so that 0011 0101 woul represent 35. Arithmetic operations need to be supported, and there may be a limit on the number of digits permitted. While a language may support a type such as BCD integers, it might not be supported by the hardware of the target machine. In this case, a compiler might either provide it in software or not support the type.
These are not the only models, of course. The set language SETL22 permits an integer to be practically "infinite" in size, limited only by the memory available. Such a language can be particularly useful for mathematical problems involving large numbers.
to be continued...
No comments:
Post a Comment