This document discusses runtime environments and compiler design. It contains the following key points:
- A runtime environment provides services like memory allocation, libraries, and environment variables to allow programs to execute. It maps program elements like names and identifiers to actual memory locations.
- Programs use stack allocation for procedure calls and return addresses. Variables use heap allocation which dynamically allocates and frees memory as needed.
- Symbol tables stored information about program elements to check scopes, declarations, and types. They are typically implemented as hash tables for efficient lookups. Scope is determined by nested symbol tables.
The document discusses intermediate code generation in compilers. It describes various intermediate representations like syntax trees, DAGs, postfix notation, and 3-address code. Syntax trees represent the hierarchical structure of a program and are constructed using functions like mknode() and mkleaf(). DAGs provide a more compact representation by identifying common subexpressions. Postfix notation linearizes the syntax tree. The document also discusses run-time environments, storage allocation strategies like static, stack and heap allocation, and activation records.
The runtime environment manages memory allocation and procedure activations at runtime. It uses a runtime support system and handles procedure calls through activation records stored on a call stack. Activation records contain local variables, parameters, and return addresses. Procedures can be allocated memory statically at compile time or dynamically on the call stack or heap as needed. The runtime environment maps names to memory locations and handles memory management through allocation and deallocation.
The document discusses run-time environments and how they manage memory allocation and procedure calls at runtime. A run-time system handles mapping names to storage locations, allocating and deallocating memory, and managing procedure activations through techniques like activation records, control stacks, and dynamic storage allocation using stacks and heaps. The key responsibilities of a run-time system include storage management and keeping track of the dynamic execution state as programs execute.
The document discusses procedures and recursion in machine level programming. It describes how procedures use stack frames to pass arguments, save registers, and allocate local variables. Stack frames contain saved registers, arguments, local variables, and return addresses. Calling a procedure involves pushing this information onto the stack. Returning involves popping this information off the stack. Recursive procedures work because each call has its own private stack frame that does not interfere with other calls.
This document discusses user defined functions in C programming. It defines functions as self-contained programs that can be divided into smaller modules to make programs more maintainable and readable. The key parts of a function are defined as the function prototype, definition, actual and formal arguments, and return statement. Functions allow for code reusability, modularity, easier debugging and maintenance of programs. Methods of passing arguments to functions include call by value and call by address.
The document discusses different runtime environments for programming languages:
(1) Fully static environments where all data remains fixed in memory like FORTRAN77. No dynamic allocation.
(2) Stack-based environments used by languages allowing recursion and dynamic allocation like C/C++. Activation records are allocated on a runtime stack.
(3) Dynamic environments like LISP where data is allocated on a heap.
It covers key aspects of runtime environments like memory organization, calling conventions, parameter passing, and handling local variables and procedures. Different languages require different solutions for variable-length data, nested declarations, non-local references, and procedure parameters.
The document discusses concepts related to sequence control and subprograms in programming languages. It covers conditional statements, loops, exception handling, subprogram definition and activation, and subprogram environments. Key points include implicit and explicit sequence control using statements, precedence and associativity rules for expressions, stack-based implementation of subprogram calls, and static versus dynamic scoping of identifiers through referencing environments.
The document discusses functions in C++. It defines a function as a self-contained program that performs a specific task. Functions help break large programs into smaller, modular pieces. The key parts of a function include the prototype, definition, arguments, return statement, and calling a function. Functions make programs easier to understand, maintain and debug.
The document discusses intermediate code generation in compilers. It describes various intermediate representations like syntax trees, DAGs, postfix notation, and 3-address code. Syntax trees represent the hierarchical structure of a program and are constructed using functions like mknode() and mkleaf(). DAGs provide a more compact representation by identifying common subexpressions. Postfix notation linearizes the syntax tree. The document also discusses run-time environments, storage allocation strategies like static, stack and heap allocation, and activation records.
The runtime environment manages memory allocation and procedure activations at runtime. It uses a runtime support system and handles procedure calls through activation records stored on a call stack. Activation records contain local variables, parameters, and return addresses. Procedures can be allocated memory statically at compile time or dynamically on the call stack or heap as needed. The runtime environment maps names to memory locations and handles memory management through allocation and deallocation.
The document discusses run-time environments and how they manage memory allocation and procedure calls at runtime. A run-time system handles mapping names to storage locations, allocating and deallocating memory, and managing procedure activations through techniques like activation records, control stacks, and dynamic storage allocation using stacks and heaps. The key responsibilities of a run-time system include storage management and keeping track of the dynamic execution state as programs execute.
The document discusses procedures and recursion in machine level programming. It describes how procedures use stack frames to pass arguments, save registers, and allocate local variables. Stack frames contain saved registers, arguments, local variables, and return addresses. Calling a procedure involves pushing this information onto the stack. Returning involves popping this information off the stack. Recursive procedures work because each call has its own private stack frame that does not interfere with other calls.
This document discusses user defined functions in C programming. It defines functions as self-contained programs that can be divided into smaller modules to make programs more maintainable and readable. The key parts of a function are defined as the function prototype, definition, actual and formal arguments, and return statement. Functions allow for code reusability, modularity, easier debugging and maintenance of programs. Methods of passing arguments to functions include call by value and call by address.
The document discusses different runtime environments for programming languages:
(1) Fully static environments where all data remains fixed in memory like FORTRAN77. No dynamic allocation.
(2) Stack-based environments used by languages allowing recursion and dynamic allocation like C/C++. Activation records are allocated on a runtime stack.
(3) Dynamic environments like LISP where data is allocated on a heap.
It covers key aspects of runtime environments like memory organization, calling conventions, parameter passing, and handling local variables and procedures. Different languages require different solutions for variable-length data, nested declarations, non-local references, and procedure parameters.
The document discusses concepts related to sequence control and subprograms in programming languages. It covers conditional statements, loops, exception handling, subprogram definition and activation, and subprogram environments. Key points include implicit and explicit sequence control using statements, precedence and associativity rules for expressions, stack-based implementation of subprogram calls, and static versus dynamic scoping of identifiers through referencing environments.
The document discusses functions in C++. It defines a function as a self-contained program that performs a specific task. Functions help break large programs into smaller, modular pieces. The key parts of a function include the prototype, definition, arguments, return statement, and calling a function. Functions make programs easier to understand, maintain and debug.
This document discusses modular programming and functions in C programming. Modular programming involves separating a program's functionality into independent, interchangeable modules. There are advantages to this approach such as improved manageability, reusability, and collaboration between programmers.
The document then discusses functions in C programming. Functions allow programmers to divide a program into reusable modules. There are two types of functions - standard library functions defined in header files, and user-defined functions. User-defined functions have advantages like making programs easier to understand, maintain, and debug. The key parts of a user-defined function are the declaration, definition, and call. Functions can take arguments, return values, and be used recursively. Arrays and 2D arrays
The document discusses C functions, including their definition, types, uses, and implementation. It notes that C functions allow large programs to be broken down into smaller, reusable blocks of code. There are two types of functions - library functions and user-defined functions. Functions are declared with a return type, name, and parameters. They are defined with a body of code between curly braces. Functions can be called within a program and allow code to be executed modularly and reused. Parameters can be passed by value or by reference. Functions can return values or not, and may or may not accept parameters. Overall, functions are a fundamental building block of C that improve code organization, reusability, and maintenance.
Functions allow programmers to organize code into reusable units and divide large programs into smaller, more manageable parts. The document discusses key concepts related to functions in Python like defining and calling user-defined functions, passing arguments, scope, and recursion. It provides examples of different types of functions and how concepts like mutability impact parameter passing. Functions are a fundamental part of modular and readable program design.
Functions allow programmers to organize code into reusable blocks. A function performs a specific task and can accept input parameters and return an output. Functions make code more modular and easier to maintain. Functions are defined with a name, parameters, and body. They can be called from other parts of the code to execute their task. Parameters allow functions to accept input values, while return values allow functions to return output to the calling code. Functions can be called by passing arguments by value or reference. The document provides examples and explanations of different types of functions in C++ like inline functions, functions with default arguments, and global vs local variables.
The document provides an overview of functions in C++. It discusses the basic concepts of functions including declaring, defining, and calling functions. It covers function components like parameters and arguments. It explains passing parameters by value and reference. It also discusses different types of functions like built-in functions, user-defined functions, and functions with default arguments. Additionally, it covers concepts like scope of variables, return statement, recursion, and automatic vs static variables. The document is intended to teach the fundamentals of functions as building blocks of C++ programs.
The document provides an overview of functions in C++. It discusses the basic concepts of functions including declaring, defining, and calling functions. It covers different types of functions such as built-in functions, user-defined functions, and functions that return values. The key components of a function like the prototype, definition, parameters, arguments, and return statement are explained. It also describes different ways of passing parameters to functions, including call by value and call by reference. Functions allow breaking down programs into smaller, reusable components, making the code more readable, maintainable and reducing errors.
The document discusses various C programming concepts like algorithms, flowcharts, tokens, data types, operators, functions, and hardware components of a computer. It includes questions and answers on these topics. Key points covered are definition of algorithm and flowchart, different types of tokens in C, differences between while and do-while loops, definition of software and its types, and examples of standard header files.
slide1: the content of functons
slide2: Introduction to function
slide3:function advantages
slide4 -5: types of functions
slide6: elements of user defined functions
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxrajkumar490591
This document discusses various topics related to C programming language including:
- The structure of a typical C program which includes header files inclusion, main method declaration, variable declaration, function body, and return statement.
- Different types of variables in C like local, global, static, automatic, and external variables. Local variables are declared within a function while global variables are declared outside. Static variables retain their value between function calls.
- Key concepts like data types, valid variable names, compilers, linkers, and how a C program is executed after compilation.
A function provides a convenient way of packaging a computational recipe, so that it can be used as often as required. A function definition consists of two parts: interface and body. The interface of a function (also called its prototype) specifies how it may be used. It consists of three entities:
The function name. This is simply a unique identifier.
The function parameters (also called its signature). This is a set of zero or more typed identifiers used for passing values to and from the function.
The function return type. This specifies the type of value the function returns. A function which returns nothing should have the return type void.
The body of a function contains the computational steps (statements) that comprise the function.
Here are the steps to complete the experiments:
1. Create a procedure that outputs a message:
CREATE OR REPLACE PROCEDURE expert IS
BEGIN
DBMS_OUTPUT.PUT_LINE('I am a PL/SQL expert.');
END;
/
2. Create a function to check for leap year:
CREATE OR REPLACE FUNCTION isLeapYear(year IN NUMBER) RETURN VARCHAR2 IS
BEGIN
IF MOD(year,4)=0 THEN
IF MOD(year,100)=0 THEN
IF MOD(year,400)=0 THEN
RETURN 'Leap year';
ELSE
RETURN 'Not leap year';
END IF;
ELSE
RETURN '
The document discusses object oriented programming concepts. It describes key object oriented programming concepts like encapsulation, inheritance, polymorphism, and message passing. It also discusses benefits of object oriented programming like modularity, reusability and extensibility. Some disadvantages discussed are compiler overhead, runtime overhead and need for reorientation of developers to object oriented thinking. The document also covers C++ programming concepts like data types, control flow, functions, arrays, strings, pointers and storage classes.
Brief description on subprograms and functions it helps to u . In any case u cn understand the descripion and concepts with easy manner. I think it helps to u
This document provides an overview of a sample C program and explanations of key concepts:
1. The sample "Hello World" program prints that message to the screen using the printf function. It demonstrates the required main function and use of a pre-defined function.
2. Key concepts discussed include functions, parameters, header files, data types, expressions, assignment statements, increment/decrement operators, and input/output statements.
3. Input is received using built-in functions, while output display is handled by functions like printf that use format specifiers to control output formatting.
This document discusses functions in C programming. It defines functions as a group of statements that perform a specific task and have a name. Main functions must be included in every C program as it is where program execution begins. Functions help facilitate modular programming by dividing programs into smaller parts. Functions can be user-defined or built-in library functions. Parameters can be passed to functions by value or by reference. Functions can call themselves through recursion. Variables have different storage classes like auto, register, static, and external that determine scope and lifetime.
1. A function is a block of code that performs a specific task. Functions allow programmers to split a large program into smaller sub-tasks and call them multiple times.
2. There are two main types of functions - library functions provided by the standard library, and user-defined functions created by the programmer.
3. Functions make programs easier to write, read, update and debug by splitting them into smaller, well-defined tasks.
The document discusses functions in C programming. It defines what a function is, how functions are declared and defined, how to pass arguments to functions, and different ways to call functions. It provides examples of using functions to calculate factorials, Fibonacci series, find the highest common factor and lowest common multiple of two numbers, and sum the digits of a number recursively. Various ways of implementing functions using loops, recursion, and by passing arguments are demonstrated through code examples.
This document discusses modular programming and functions in C programming. Modular programming involves separating a program's functionality into independent, interchangeable modules. There are advantages to this approach such as improved manageability, reusability, and collaboration between programmers.
The document then discusses functions in C programming. Functions allow programmers to divide a program into reusable modules. There are two types of functions - standard library functions defined in header files, and user-defined functions. User-defined functions have advantages like making programs easier to understand, maintain, and debug. The key parts of a user-defined function are the declaration, definition, and call. Functions can take arguments, return values, and be used recursively. Arrays and 2D arrays
The document discusses C functions, including their definition, types, uses, and implementation. It notes that C functions allow large programs to be broken down into smaller, reusable blocks of code. There are two types of functions - library functions and user-defined functions. Functions are declared with a return type, name, and parameters. They are defined with a body of code between curly braces. Functions can be called within a program and allow code to be executed modularly and reused. Parameters can be passed by value or by reference. Functions can return values or not, and may or may not accept parameters. Overall, functions are a fundamental building block of C that improve code organization, reusability, and maintenance.
Functions allow programmers to organize code into reusable units and divide large programs into smaller, more manageable parts. The document discusses key concepts related to functions in Python like defining and calling user-defined functions, passing arguments, scope, and recursion. It provides examples of different types of functions and how concepts like mutability impact parameter passing. Functions are a fundamental part of modular and readable program design.
Functions allow programmers to organize code into reusable blocks. A function performs a specific task and can accept input parameters and return an output. Functions make code more modular and easier to maintain. Functions are defined with a name, parameters, and body. They can be called from other parts of the code to execute their task. Parameters allow functions to accept input values, while return values allow functions to return output to the calling code. Functions can be called by passing arguments by value or reference. The document provides examples and explanations of different types of functions in C++ like inline functions, functions with default arguments, and global vs local variables.
The document provides an overview of functions in C++. It discusses the basic concepts of functions including declaring, defining, and calling functions. It covers function components like parameters and arguments. It explains passing parameters by value and reference. It also discusses different types of functions like built-in functions, user-defined functions, and functions with default arguments. Additionally, it covers concepts like scope of variables, return statement, recursion, and automatic vs static variables. The document is intended to teach the fundamentals of functions as building blocks of C++ programs.
The document provides an overview of functions in C++. It discusses the basic concepts of functions including declaring, defining, and calling functions. It covers different types of functions such as built-in functions, user-defined functions, and functions that return values. The key components of a function like the prototype, definition, parameters, arguments, and return statement are explained. It also describes different ways of passing parameters to functions, including call by value and call by reference. Functions allow breaking down programs into smaller, reusable components, making the code more readable, maintainable and reducing errors.
The document discusses various C programming concepts like algorithms, flowcharts, tokens, data types, operators, functions, and hardware components of a computer. It includes questions and answers on these topics. Key points covered are definition of algorithm and flowchart, different types of tokens in C, differences between while and do-while loops, definition of software and its types, and examples of standard header files.
slide1: the content of functons
slide2: Introduction to function
slide3:function advantages
slide4 -5: types of functions
slide6: elements of user defined functions
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxrajkumar490591
This document discusses various topics related to C programming language including:
- The structure of a typical C program which includes header files inclusion, main method declaration, variable declaration, function body, and return statement.
- Different types of variables in C like local, global, static, automatic, and external variables. Local variables are declared within a function while global variables are declared outside. Static variables retain their value between function calls.
- Key concepts like data types, valid variable names, compilers, linkers, and how a C program is executed after compilation.
A function provides a convenient way of packaging a computational recipe, so that it can be used as often as required. A function definition consists of two parts: interface and body. The interface of a function (also called its prototype) specifies how it may be used. It consists of three entities:
The function name. This is simply a unique identifier.
The function parameters (also called its signature). This is a set of zero or more typed identifiers used for passing values to and from the function.
The function return type. This specifies the type of value the function returns. A function which returns nothing should have the return type void.
The body of a function contains the computational steps (statements) that comprise the function.
Here are the steps to complete the experiments:
1. Create a procedure that outputs a message:
CREATE OR REPLACE PROCEDURE expert IS
BEGIN
DBMS_OUTPUT.PUT_LINE('I am a PL/SQL expert.');
END;
/
2. Create a function to check for leap year:
CREATE OR REPLACE FUNCTION isLeapYear(year IN NUMBER) RETURN VARCHAR2 IS
BEGIN
IF MOD(year,4)=0 THEN
IF MOD(year,100)=0 THEN
IF MOD(year,400)=0 THEN
RETURN 'Leap year';
ELSE
RETURN 'Not leap year';
END IF;
ELSE
RETURN '
The document discusses object oriented programming concepts. It describes key object oriented programming concepts like encapsulation, inheritance, polymorphism, and message passing. It also discusses benefits of object oriented programming like modularity, reusability and extensibility. Some disadvantages discussed are compiler overhead, runtime overhead and need for reorientation of developers to object oriented thinking. The document also covers C++ programming concepts like data types, control flow, functions, arrays, strings, pointers and storage classes.
Brief description on subprograms and functions it helps to u . In any case u cn understand the descripion and concepts with easy manner. I think it helps to u
This document provides an overview of a sample C program and explanations of key concepts:
1. The sample "Hello World" program prints that message to the screen using the printf function. It demonstrates the required main function and use of a pre-defined function.
2. Key concepts discussed include functions, parameters, header files, data types, expressions, assignment statements, increment/decrement operators, and input/output statements.
3. Input is received using built-in functions, while output display is handled by functions like printf that use format specifiers to control output formatting.
This document discusses functions in C programming. It defines functions as a group of statements that perform a specific task and have a name. Main functions must be included in every C program as it is where program execution begins. Functions help facilitate modular programming by dividing programs into smaller parts. Functions can be user-defined or built-in library functions. Parameters can be passed to functions by value or by reference. Functions can call themselves through recursion. Variables have different storage classes like auto, register, static, and external that determine scope and lifetime.
1. A function is a block of code that performs a specific task. Functions allow programmers to split a large program into smaller sub-tasks and call them multiple times.
2. There are two main types of functions - library functions provided by the standard library, and user-defined functions created by the programmer.
3. Functions make programs easier to write, read, update and debug by splitting them into smaller, well-defined tasks.
The document discusses functions in C programming. It defines what a function is, how functions are declared and defined, how to pass arguments to functions, and different ways to call functions. It provides examples of using functions to calculate factorials, Fibonacci series, find the highest common factor and lowest common multiple of two numbers, and sum the digits of a number recursively. Various ways of implementing functions using loops, recursion, and by passing arguments are demonstrated through code examples.
Similar to chapter-7-runtime-environments.ppt (20)
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...Aggregage
This webinar will explore cutting-edge, less familiar but powerful experimentation methodologies which address well-known limitations of standard A/B Testing. Designed for data and product leaders, this session aims to inspire the embrace of innovative approaches and provide insights into the frontiers of experimentation!
Analysis insight about a Flyball dog competition team's performanceroli9797
Insight of my analysis about a Flyball dog competition team's last year performance. Find more: https://github.com/rolandnagy-ds/flyball_race_analysis/tree/main
Codeless Generative AI Pipelines
(GenAI with Milvus)
https://ml.dssconf.pl/user.html#!/lecture/DSSML24-041a/rate
Discover the potential of real-time streaming in the context of GenAI as we delve into the intricacies of Apache NiFi and its capabilities. Learn how this tool can significantly simplify the data engineering workflow for GenAI applications, allowing you to focus on the creative aspects rather than the technical complexities. I will guide you through practical examples and use cases, showing the impact of automation on prompt building. From data ingestion to transformation and delivery, witness how Apache NiFi streamlines the entire pipeline, ensuring a smooth and hassle-free experience.
Timothy Spann
https://www.youtube.com/@FLaNK-Stack
https://medium.com/@tspann
https://www.datainmotion.dev/
milvus, unstructured data, vector database, zilliz, cloud, vectors, python, deep learning, generative ai, genai, nifi, kafka, flink, streaming, iot, edge
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeWalaa Eldin Moustafa
Dynamic policy enforcement is becoming an increasingly important topic in today’s world where data privacy and compliance is a top priority for companies, individuals, and regulators alike. In these slides, we discuss how LinkedIn implements a powerful dynamic policy enforcement engine, called ViewShift, and integrates it within its data lake. We show the query engine architecture and how catalog implementations can automatically route table resolutions to compliance-enforcing SQL views. Such views have a set of very interesting properties: (1) They are auto-generated from declarative data annotations. (2) They respect user-level consent and preferences (3) They are context-aware, encoding a different set of transformations for different use cases (4) They are portable; while the SQL logic is only implemented in one SQL dialect, it is accessible in all engines.
#SQL #Views #Privacy #Compliance #DataLake
Learn SQL from basic queries to Advance queriesmanishkhaire30
Dive into the world of data analysis with our comprehensive guide on mastering SQL! This presentation offers a practical approach to learning SQL, focusing on real-world applications and hands-on practice. Whether you're a beginner or looking to sharpen your skills, this guide provides the tools you need to extract, analyze, and interpret data effectively.
Key Highlights:
Foundations of SQL: Understand the basics of SQL, including data retrieval, filtering, and aggregation.
Advanced Queries: Learn to craft complex queries to uncover deep insights from your data.
Data Trends and Patterns: Discover how to identify and interpret trends and patterns in your datasets.
Practical Examples: Follow step-by-step examples to apply SQL techniques in real-world scenarios.
Actionable Insights: Gain the skills to derive actionable insights that drive informed decision-making.
Join us on this journey to enhance your data analysis capabilities and unlock the full potential of SQL. Perfect for data enthusiasts, analysts, and anyone eager to harness the power of data!
#DataAnalysis #SQL #LearningSQL #DataInsights #DataScience #Analytics
"Financial Odyssey: Navigating Past Performance Through Diverse Analytical Lens"sameer shah
Embark on a captivating financial journey with 'Financial Odyssey,' our hackathon project. Delve deep into the past performance of two companies as we employ an array of financial statement analysis techniques. From ratio analysis to trend analysis, uncover insights crucial for informed decision-making in the dynamic world of finance."
2. RUNTIME ENVIRONMENTS IN COMPILER DESIGN
A program as a source code is merely a collection of text
(code, statements etc.) and to make it alive, it requires
actions to be performed on the target machine.
A program needs memory resources to execute
instructions. A program contains names for procedures,
identifiers etc., that require mapping with the actual
memory location at runtime.
By runtime, we mean a program in execution. Runtime
environment is a state of the target machine, which may
include software libraries, environment variables, etc., to
provide services to the processes running in the system.
2
3. CTD..
Runtime support system is a package, mostly
generated with the executable program itself and
facilitates the process communication between the
process and the runtime environment. It takes care
of memory allocation and de-allocation while the
program is being executed
3
4. CTD..
A translation needs to relate the static source text of a
program to the dynamic actions that must occur at
runtime to implement the program. The program
consists of names for procedures, identifiers etc., that
require mapping with the actual memory location at
runtime. Runtime environment is a state of the target
machine, which may include software libraries,
environment variables, etc., to provide services to the
processes running in the system.
4
5. ACTIVATION TREES
A program is a sequence of instructions combined into a
number of procedures. Instructions in a procedure are
executed sequentially. A procedure has a start and an end
delimiter and everything inside it is called the body of
the procedure. The procedure identifier and the
sequence of finite instructions inside it make up the body
of the procedure.
The execution of a procedure is called its activation. An
activation record contains all the necessary information
required to call a procedure. An activation record may
contain the following units (depending upon the source
language used).
5
6. Temporaries Stores temporary and intermediate values of an
expression.
Local Data Stores local data of the called procedure.
Machine
Status
Stores machine status such as Registers, Program
Counter etc., before the procedure is called.
Control Link Stores the address of activation record of the caller
procedure.
Access Link Stores the information of data which is outside the
local scope.
Actual
Parameters
Stores actual parameters, i.e., parameters which are
used to send input to the called procedure.
Return Value Stores return values.
6
7. CTD..
Whenever a procedure is executed, its activation record
is stored on the stack, also known as control stack. When
a procedure calls another procedure, the execution of the
caller is suspended until the called procedure finishes
execution. At this time, the activation record of the called
procedure is stored on the stack.
We assume that the program control flows in a sequential
manner and when a procedure is called, its control is
transferred to the called procedure. When a called
procedure is executed, it returns the control back to the
caller. This type of control flow makes it easier to
represent a series of activations in the form of a tree,
known as the activation tree.
7
8. TO UNDERSTAND THIS CONCEPT, WE TAKE A PIECE OF
CODE AS AN EXAMPLE:
printf(“Enter Your Name: “);
scanf(“%s”, username);
show_data(username);
printf(“Press any key to continue…”);
. . .
int show_data(char *user)
{
printf(“Your name is %s”, username);
return 0;
}
. . . 8
9. BELOW IS THE ACTIVATION TREE OF THE CODE GIVEN.
Now we understand that procedures are executed in depth-first manner,
thus stack allocation is the best suitable form of storage for procedure
activations.
9
10. STORAGE ALLOCATION
Runtime environment manages runtime memory
requirements for the following entities:
Code : It is known as the text part of a program that does
not change at runtime. Its memory requirements are
known at the compile time.
Procedures : Their text part is static but they are called
in a random manner. That is why, stack storage is used to
manage procedure calls and activations.
Variables : Variables are known at the runtime only,
unless they are global or constant. Heap memory
allocation scheme is used for managing allocation and
de-allocation of memory for variables in runtime.
10
11. STATIC ALLOCATION
In this allocation scheme, the compilation data is bound
to a fixed location in the memory and it does not change
when the program executes. As the memory requirement
and storage locations are known in advance, runtime
support package for memory allocation and de-allocation
is not required.
Stack Allocation
Procedure calls and their activations are managed by
means of stack memory allocation. It works in last-in-
first-out (LIFO) method and this allocation strategy is
very useful for recursive procedure calls.
11
12. HEAP ALLOCATION
Variables local to a procedure are allocated and de-
allocated only at runtime. Heap allocation is used to
dynamically allocate memory to the variables and claim
it back when the variables are no more required.
Except statically allocated memory area, both stack and
heap memory can grow and shrink dynamically and
unexpectedly. Therefore, they cannot be provided with a
fixed amount of memory in the system
As shown in the image blow , the text part of the code is
allocated a fixed amount of memory. Stack and heap
memory are arranged at the extremes of total memory
allocated to the program. Both shrink and grow against
each other.
12
13. 13
Stack and heap memory are arranged at the extremes of total
memory allocated to the program.
14. PARAMETER PASSING
The communication medium among procedures is known
as parameter passing. The values of the variables from a
calling procedure are transferred to the called procedure by
some mechanism. Before moving ahead, first go through
some basic terminologies pertaining to the values in a
program.
r-value(right hand side value)
The value of an expression is called its r-value. The value
contained in a single variable also becomes an r-value if it
appears on the right-hand side of the assignment operator.
r-values can always be assigned to some other variable.
14
15. L-VALUE(LEFT HAND SIDE VALUE)
The location of memory (address) where an expression is
stored is known as the l-value of that expression. It always
appears at the left hand side of an assignment operator.
For example:
day = 1;
week = day * 7;
month = 1;
year = month * 12;
From this example, we understand that constant values like 1, 7, 12,
and variables like day, week, month and year, all have r-values. Only
variables have l-values as they also represent the memory location
assigned to them.
For example:
7 = x + y;
is an l-value error, as the constant 7 does not represent any memory
location.
15
16. FORMAL PARAMETERS
Variables that take the information passed by the
caller procedure are called formal parameters.
These variables are declared in the definition of
the called function.
Actual Parameters
Variables whose values or addresses are being
passed to the called procedure are called actual
parameters. These variables are specified in the
function call as arguments.
16
17. EXAMPLE:
fun_one()
{
int actual_parameter = 10;
call fun_two(int actual_parameter);
}
fun_two(int formal_parameter)
{
print formal_parameter;
}
Formal parameters hold the information of the actual
parameter, depending upon the parameter passing
technique used. It may be a value or an address 17
18. PASS BY VALUE
In pass by value mechanism, the calling procedure passes
the r-value of actual parameters and the compiler puts
that into the called procedure’s activation record. Formal
parameters then hold the values passed by the calling
procedure. If the values held by the formal parameters
are changed, it should have no impact on the actual
parameters.
Pass by Reference
In pass by reference mechanism, the l-value of the actual
parameter is copied to the activation record of the called
procedure. This way, the called procedure now has the
address (memory location) of the actual parameter and
the formal parameter refers to the same memory location.
Therefore, if the value pointed by the formal parameter is
changed, the impact should be seen on the actual
parameter as they should also point to the same value.
18
19. PASS BY COPY-RESTORE
This parameter passing mechanism works similar to
‘pass-by-reference’ except that the changes to actual
parameters are made when the called procedure ends.
Upon function call, the values of actual parameters are
copied in the activation record of the called procedure.
Formal parameters if manipulated have no real-time
effect on actual parameters (as l-values are passed), but
when the called procedure ends, the l-values of formal
parameters are copied to the l-values of actual
parameters
19
20. EXAMPLE:
int y;
calling_procedure()
{
y = 10;
copy_restore(y); //l-value of y is passed
printf y; //prints 99
}
copy_restore(int x)
{
x = 99; // y still has value 10 (unaffected)
y = 0; // y is now 0
}
When this function ends, the l-value of formal parameter x is copied to
the actual parameter y. Even if the value of y is changed before the
procedure ends, the l-value of x is copied to the l-value of y making it
behave like call by reference.
20
21. PASS BY NAME
Languages like Algol provide a new kind of parameter
passing mechanism that works like preprocessor in C
language. In pass by name mechanism, the name of the
procedure being called is replaced by its actual body.
Pass-by-name textually substitutes the argument
expressions in a procedure call for the corresponding
parameters in the body of the procedure so that it can
now work on actual parameters, much like pass-by-
reference.
21
22. SYMBOL TABLE
Symbol table is an important data structure created and
maintained by compilers in order to store information
about the occurrence of various entities such as variable
names, function names, objects, classes, interfaces, etc.
Symbol table is used by both the analysis and the synthesis
parts of a compiler.
A symbol table may serve the following purposes
depending upon the language in hand:
To store the names of all entities in a structured form at one
place.
To verify if a variable has been declared.
To implement type checking, by verifying assignments and
expressions in the source code are semantically correct.
To determine the scope of a name (scope resolution). 22
23. CTD..
A symbol table is simply a table which can be either
linear or a hash table. It maintains an entry for each
name in the following format:
<symbol name, type, attribute>
For example, if a symbol table has to store
information about the following variable declaration:
static int interest;
then it should store the entry such as:
<interest, int, static>
The attribute clause contains the entries related to the
name.
23
24. IMPLEMENTATION
If a compiler is to handle a small amount of data, then the
symbol table can be implemented as an unordered list,
which is easy to code, but it is only suitable for small tables
only. A symbol table can be implemented in one of the
following ways:
Linear (sorted or unsorted) list
Binary Search Tree
Hash table
Among all, symbol tables are mostly implemented as hash
tables, where the source code symbol itself is treated as a
key for the hash function and the return value is the
information about the symbol
24
25. OPERATIONS
A symbol table, either linear or hash, should provide the
following operations.
insert()
This operation is more frequently used by analysis phase, i.e.,
the first half of the compiler where tokens are identified and
names are stored in the table. This operation is used to add
information in the symbol table about unique names occurring
in the source code. The format or structure in which the names
are stored depends upon the compiler in hand.
An attribute for a symbol in the source code is the information
associated with that symbol. This information contains the
value, state, scope, and type about the symbol.
25
26. CTD…
The insert() function takes the symbol and its
attributes as arguments and stores the information
in the symbol table.
For example:
int a;
should be processed by the compiler as:
insert(a, int);
26
27. LOOKUP()
lookup() operation is used to search a name in the symbol
table to determine:
if the symbol exists in the table.
if it is declared before it is being used.
if the name is used in the scope.
if the symbol is initialized.
if the symbol declared multiple times.
The format of lookup() function varies according to the
programming language. The basic format should match the
following:
lookup(symbol)
This method returns 0 (zero) if the symbol does not exist in
the symbol table. If the symbol exists in the symbol table, it
returns its attributes stored in the table
27
28. SCOPE MANAGEMENT
A compiler maintains two types of symbol tables: a global
symbol table which can be accessed by all the procedures
and scope symbol tables that are created for each scope in
the program.
To determine the scope of a name, symbol tables are
arranged in hierarchical structure as shown in the example
below:
int value=10;
void pro_one()
{
int one_1;
int one_2;
{
int one_3; |_ inner scope 1
int one_4; |
}
28
29. CTD..
int one_5;
{
int one_6; |_ inner scope 2
int one_7; |
} /
}
void pro_two()
{
int two_1;
int two_2;
{
int two_3; |_ inner scope 3
int two_4; |
} /
int two_5;
}
29
30. THE ABOVE PROGRAM CAN BE REPRESENTED IN A HIERARCHICAL
STRUCTURE OF SYMBOL TABLES
30
31. THE GLOBAL SYMBOL TABLE
The global symbol table contains names for one global variable
(int value) and two procedure names, which should be available to
all the child nodes shown above. The names mentioned in the
pro_one symbol table (and all its child tables) are not available for
pro_two symbols and its child tables.
This symbol table data structure hierarchy is stored in the
semantic analyzer and whenever a name needs to be searched in a
symbol table, it is searched using the following algorithm:
first a symbol will be searched in the current scope, i.e. current
symbol table.
if a name is found, then search is completed, else it will be
searched in the parent symbol table until,
either the name is found or global symbol table has been searched
for the name. 31