1. DATA TYPES AND TYPE CHECKING
A data type is defined by the set of primary values allowed and the
operations defined on these values. A data type is used to declare
variables (e.g., integer, real, array of integer, string, etc.).
Type checking is the activity of ensuring that the data types of
operands of an operator are legal or equivalent to the legal type.
TWO MAJOR TYPE EQUIVALENCE POLICIES:
1. structural equivalence
2. name equivalence
structural equivalence policy is used, the two types are equivalent if they
have the same set of values (data range) and the same operations.
This policy follows the stored program concept and gives programmers the
maximum flexibility to manipulate data. The stored program concept
suggests that instruction and data are stored in computer memory as binary bit
patterns and it is the programmer’s responsibility to interpret the meanings
of the bit patterns.
name equivalence policy is used, two types are equivalent only if they
have the same name. Since no programming language will normally
allow two different data types to have the same name, this policy does
not allow any variable of one type to be used in the place where a variable
of another type is expected without explicit type conversion. If name
equivalence policy is used, the statement “i = s + a;” is then illegal.
BSCS 311 PRINCIPLES OF PROGRAMMING LANGUAGES. 1
, INTRODUCTION TO LANGUAGE TRANSLATION:
BSCS 311 PRINCIPLES OF PROGRAMMING LANGUAGES. 2
A data type is defined by the set of primary values allowed and the
operations defined on these values. A data type is used to declare
variables (e.g., integer, real, array of integer, string, etc.).
Type checking is the activity of ensuring that the data types of
operands of an operator are legal or equivalent to the legal type.
TWO MAJOR TYPE EQUIVALENCE POLICIES:
1. structural equivalence
2. name equivalence
structural equivalence policy is used, the two types are equivalent if they
have the same set of values (data range) and the same operations.
This policy follows the stored program concept and gives programmers the
maximum flexibility to manipulate data. The stored program concept
suggests that instruction and data are stored in computer memory as binary bit
patterns and it is the programmer’s responsibility to interpret the meanings
of the bit patterns.
name equivalence policy is used, two types are equivalent only if they
have the same name. Since no programming language will normally
allow two different data types to have the same name, this policy does
not allow any variable of one type to be used in the place where a variable
of another type is expected without explicit type conversion. If name
equivalence policy is used, the statement “i = s + a;” is then illegal.
BSCS 311 PRINCIPLES OF PROGRAMMING LANGUAGES. 1
, INTRODUCTION TO LANGUAGE TRANSLATION:
BSCS 311 PRINCIPLES OF PROGRAMMING LANGUAGES. 2