Vignan’s Institute of Technology & Aeronautical Engg



Download 342.38 Kb.
Page7/16
Date28.01.2017
Size342.38 Kb.
#9046
1   2   3   4   5   6   7   8   9   10   ...   16

Scope and Lifetime


  • Ex:

void printheader()

{



} /* end of printheader */

void compute()

{

int sum;

printheader();



} /* end of compute */



  • The scope of sum in contained within compute.

  • The lifetime of sum extends over the time during which printheader executes.

  • Whatever storage location sum is bound to before the call to printheader, that binding will continue during and after the execution of printheader.

Referencing environment


  • It is the collection of all names that are visible in the statement.

  • In a static-scoped language, it is the local variables plus all of the visible variables in all of the enclosing scopes.

  • The referencing environment of a statement is needed while that statement is being compiled, so code and data structures can be created to allow references to non-local vars in both static and dynamic scoped languages.

  • A subprogram is active if its execution has begun but has not yet terminated.

  • In a dynamic-scoped language, the referencing environment is the local variables plus all visible variables in all active subprograms.

  • Ex: Ada

procedure Example is

A, B : Integer;



procedure Sub1 is

X, Y : Integer;



begin -- of Sub1

…  1



end -- of Sub1

procedure Sub2 is

X : Integer;



procedure Sub3 is

X : Integer;



begin -- of Sub3

…  2



end; -- of Sub3

begin -- of Sub2

…  3



end; { Sub2}

begin

 4



end; {Example}


  • The referencing environments of the indicated program points are as follows:


Point Referencing Environment

  1. X and Y of Sub1, A & B of Example

  2. X of Sub3, (X of Sub2 is hidden), A and B of Example

  3. X of Sub2, A and B of Example

  4. A and B of Example




main calls sub2, which calls sub1
void sub1()

{

int a, b;

…  1

} /* end of sub1 */



void sub2()

{

int b, c;

…  2

sub1;


} /* end of sub2 */

void main ()

{

int c, d;

…  3

sub2();


} /* end of main */


  • The referencing environments of the indicated program points are as follows:


Point Referencing Environment

1 a and b of sub1, c of sub2, d of main

2 b and c of sub2, d of main

3 c and of main


Named Constants


  • It is a var that is bound to a value only at the time it is bound to storage; its value can’t be change by assignment or by an input statement.

  • Advantages: readability and modifiability

Variable Initialization


  • The binding of a variable to a value at the time it is bound to storage is called initialization.

  • Initialization is often done on the declaration statement.

e.g., Java

int sum = 0;

UNIT – III

CHAPTER – VI




Introduction





  • A data type defines a collection of data objects and a set of predefined operations on those objects.

  • Computer programs produce results by manipulating data.

  • ALGOL 68 provided a few basic types and a few flexible structure-defining operators that allow a programmer to design a data structure for each need.

  • A descriptor is the collection of the attributes of a variable.

  • In an implementation a descriptor is a collection of memory cells that store variable attributes.

  • If the attributes are static, descriptor are required only at compile time.

  • They are built by the compiler, usually as a part of the symbol table, and are used during compilation.

  • For dynamic attributes, part or all of the descriptor must be maintained during execution.

  • Descriptors are used for type checking and by allocation and deallocation operations.

Primitive Data Types





  • Those not defined in terms of other data types.

  • The primitive data types of a language, along with one or more type constructors provide structured types.

Numeric Types


1. Integer

  • Almost always an exact reflection of the hardware, so the mapping is trivial.

  • There may be as many as eight different integer types in a language.

  • Java has four: byte, short, int, and long.

  • Integer types are supported by the hardware.


2. Floating-point

  • Model real numbers, but only as approximations for most real values.

  • On most computers, floating-point numbers are stored in binary, which exacerbates the problem.

  • Another problem, is the loss of accuracy through arithmetic operations.

  • Languages for scientific use support at least two floating-point types; sometimes more (e.g. float, and double.)

  • The collection of values that can be represented by a floating-point type is defined in terms of precision and range.

  • Precision: is the accuracy of the fractional part of a value, measured as the number of bits. Figure below shows single and double precision.

  • Range: is the range of fractions and exponents.


3. Decimal

  • Larger computers that are designed to support business applications have hardware support for decimal data types.

  • Decimal types store a fixed number of decimal digits, with the decimal point at a fixed position in the value.

  • Advantage: accuracy of decimal values.

  • Disadvantages: limited range since no exponents are allowed, and its representation wastes memory.

Boolean Types


  • Introduced by ALGOL 60.

  • They are used to represent switched and flags in programs.

  • The use of Booleans enhances readability.

Character Types


  • Char types are stored as numeric codings (ASCII / Unicode).


Download 342.38 Kb.

Share with your friends:
1   2   3   4   5   6   7   8   9   10   ...   16




The database is protected by copyright ©ininet.org 2024
send message

    Main page