0% found this document useful (0 votes)
19 views4 pages

Unit-Iii: 1. Storage Management

UNIT-III of a Programming Languages or Compiler Design course covers Storage Management, Sequence Control, and Subprogram Control. It details memory allocation strategies including static and dynamic management, the flow of control in programs through implicit and explicit sequencing, and the mechanisms of subprogram control including parameter passing and scoping. The unit emphasizes the importance of how these concepts affect program execution and structure.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views4 pages

Unit-Iii: 1. Storage Management

UNIT-III of a Programming Languages or Compiler Design course covers Storage Management, Sequence Control, and Subprogram Control. It details memory allocation strategies including static and dynamic management, the flow of control in programs through implicit and explicit sequencing, and the mechanisms of subprogram control including parameter passing and scoping. The unit emphasizes the importance of how these concepts affect program execution and structure.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Here is a detailed explanation of UNIT-III of a typical Programming Languages or Compiler

Design course, covering Storage Management, Sequence Control, and Subprogram Control:

UNIT-III

🔹 1. Storage Management

Storage management refers to how memory is allocated and organized during the execution of a
program. It involves three key strategies:

a) Static Storage Management

 Definition: Allocation of memory during compile time, and it remains


fixed throughout the program's execution.
 Example: Global variables and static local variables in C/C++.
 Characteristics:
o Fast access.
o Cannot handle dynamic size data.
o Lifetime: Entire program run.

b) Dynamic Storage Management

 Definition: Allocation of memory during runtime.


 Two types:
o Stack-based: For function calls and local variables.
o Heap-based: For dynamically allocated objects using functions
like malloc() or new.

c) Stack-Based Storage Management

 Uses stack data structure (LIFO).


 Suitable for:
o Local variables.
o Function parameters.
o Return addresses.
 Automatically managed (memory is pushed/popped as functions are
called and return).
 Efficient but cannot handle complex lifetimes (like shared references).
d) Heap-Based Storage Management

 Uses heap area of memory.


 Suitable for:
o Objects that need to outlive function calls.
o Dynamic data structures (e.g., linked lists, trees).
 Requires manual or garbage-collected memory management.
o E.g., malloc()/free() in C, new/automatic GC in Java/Python.

🔹 2. Sequence Control

Sequence control governs the order in which instructions/statements in a program are executed.

a) Implicit Sequencing

 Default flow of control in a program.


 Follows the textual order of statements unless altered by control
constructs.
 Example:
 int x = 10;
 x = x + 5;
b) Explicit Sequencing

 Involves control structures that change the normal flow.


 Types:
o Conditionals: if-else, switch-case
o Loops: for, while, do-while
o Jumps: break, continue, goto, return
 Example:
 if (x > 0)
 x = x - 1;

c) Sequencing with Arithmetic and Non-Arithmetic Expressions

 Arithmetic: x = a + b * c; — follows operator precedence and


associativity.
 Non-Arithmetic: Function calls, logical operations, assignment
operations — sequence depends on language rules.
d) Sequence Control Between Statements

 Involves:
o Basic sequencing (line-by-line).
o Control transfers (if-else, loops).
o Function or subprogram calls (control jumps to the
subprogram and returns after execution).
 Language design affects flexibility and readability.

🔹 3. Subprogram Control

Subprograms are named sequences of statements (functions, procedures) that can be invoked
from different parts of the program.

a) Subprogram Sequence Control

 Refers to how the control passes to and from subprograms.


 Call mechanism:
o Execution jumps to the subprogram.
o After completion, control returns to the point of call.
 May involve recursion or nested calls.

b) Subprogram Data Control and Referencing Environments

 Referencing Environment: The set of variable bindings visible to a


subprogram.
 Two types:
o Static (Lexical) Scoping: Variables are resolved based on
program structure.
o Dynamic Scoping: Variables are resolved based on calling
sequence at runtime.

c) Parameter Passing Mechanisms

How arguments are passed to subprograms:


d) Static and Dynamic Scope

 Static Scope:
o Determined at compile-time.
o Based on the structure of the program code.
o Used by most modern languages (e.g., C, Java).

 Dynamic Scope:
o Determined at runtime.
o Based on the calling sequence of subprograms.
o Used in some functional and scripting languages (e.g., older LISP
versions).

e) Block Structure

 Programming constructs that define scopes for variables and


functions.
 A block may contain:
o Local declarations.
o Nested blocks.
o Statements.
 Languages with block structures:
o Pascal, C, Java, Python (via indentation).

✅ Summary Table

Let me know if you want diagrams, examples in a specific language, or short notes for revision.

You might also like