0% found this document useful (0 votes)
8 views

Unit 5 CD

Uploaded by

Harsh Singhal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Unit 5 CD

Uploaded by

Harsh Singhal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Unit 5

What is an activation record?


An activation record, also known as a stack frame, is a block
of memory that is used to store information about a function
call. Each time a function is called, an activation record is
created and added to the call stack. This record contains all
the necessary information to manage the function’s execution,
including where to return after the function ends, the
function’s local variables, parameters passed to the function,
and other necessary data.
Key Components of an Activation Record
1. Return Address:

What it is: The place where the function should go back to once it
finishes running.

Why it's important: Ensures the program continues from the right
spot after the function is done.

2. Parameter List (Actual Parameters):

What it is: The inputs or arguments you give to the function when
you call it.

These are the values the function uses to do its job.

3. Control Link (Dynamic Link):

What it is: A pointer to the caller's activation record.

Why it's important: Helps the function return control back to the
function that called it.

4. Access Link (Static Link):

What it is: A pointer to the activation record of the function that


contains the current function, if there is one.

Why it's important: Lets the function access variables that are in its
surrounding functions (for languages that allow nested functions).

5. Saved Machine Status:

What it is: The saved state of the computer’s registers before the
function call.

Wh Keeps track of where everything was before the function call so


the program can return to that state afterward.
6. Local Variables (Local Data):

What it is: Variables declared inside the function.

Stores data that the function uses while it’s running.

7. Temporaries:

What it is: Temporary storage for intermediate results created during


function execution.

Why it's important: Holds values that are needed briefly, for
example, parts of complex calculations.

What is an activation trees?


Activation trees, also known as call trees or dynamic call
trees, are conceptual structures used in compiler design and
program execution to represent the hierarchy and relationships
of function calls during the execution of a program. Each
node in the activation tree corresponds to a function call
(activation record), and the edges represent the calling
relationships between these functions.
Basic block :
A basic block is a set of statement always execute in a sequence one after the
other

A basic block contains only A Single Entry Point, Exit point

The instruction within block are executed sequentially without any jump or
branches except at the end

Algorithm: Partitioning three-address code into basic blocks.

Input: A sequence of three address instructions.

Output: List of basic block

Process: Instructions from intermediate code which are leaders are determined.
The following are the rules used for finding a leader:

1. The first three-address instruction of the intermediate code is a leader.

2. Instructions that are targets of unconditional or conditional jump/goto


statements are leaders.

3. Instructions that immediately follow unconditional or conditional


jump/goto statements are considered leaders.

Flow Graphs

Flow Graph (Control Flow Graph): A flow graph is a directed graph that
represents the control flow of a program.

Components:

1. Nodes: Each node represents a basic block.


2. Edges: Directed edges represent the control flow between basic blocks.
Error Control in Compiler Design

Error control is a critical aspect of compiler design, ensuring that a


program is syntactically and semantically correct before it is executed.
There are different types of errors that a compiler must detect and
handle effectively:

Types of Errors

1. Lexical Errors:

Errors that occur at the lexical analysis phase, such as invalid


characters or incorrect token sequences.

Example: Using an illegal character in the source code, like @ in a


variable name.

2. Syntax Errors:

Errors that occur during parsing, when the source code violates the
grammar rules of the programming language.

Example: Missing a semicolon at the end of a statement.

3. Semantic Errors:

Errors that occur during semantic analysis, where the syntax is correct
but the code has logical inconsistencies or type mismatches.

Example: Adding an integer to a string.

4. Runtime Errors:

Errors that occur during the execution of a program, which compilers


often aim to prevent or catch early.

Example: Division by zero.

5. Logical Errors:
Description: Errors that result in incorrect output, where the logic of
the code does not produce the intended result.

Example: Using <= instead of < in a loop condition.

Error Handling Techniques

1. Panic Mode:

Description: The compiler skips parts of the input until it finds a


designated set of synchronizing tokens, allowing it to continue
parsing.

Advantage: Simple to implement and prevents the parser from


getting stuck.

Disadvantage: May skip over significant portions of code, missing


multiple errors.

2. Phrase-Level Recovery:

Description: The compiler attempts to correct the error on the spot,


possibly by inserting or deleting tokens.

Advantage: Can allow the parser to recover quickly and continue


with minimal disruption.

Disadvantage: Might introduce new errors or incorrect corrections.

3. Error Productions:

Description: Adding specific grammar rules to handle common


errors.

Advantage: Provides precise handling for anticipated errors.

Disadvantage: Increases the complexity of the grammar and the


parser.

4. Global Correction:
Description: The compiler considers the entire program to find the
minimal set of changes that correct the errors.

Advantage: Provides a more accurate correction of errors.

Disadvantage: Computationally expensive and difficult to


implement.

Symbol Table in Compiler Design

A symbol table is a crucial data structure used by a compiler to store


information about the identifiers (names of variables, functions,
objects, etc.) in a program. It is used throughout various stages of
compilation to ensure correct and efficient program translation.

Components and Structure

1. Entries: Each entry in the symbol table typically contains:

Identifier Name: The name of the variable, function, etc.

Type: The data type of the identifier (e.g., integer, float, custom type).

Scope: The scope level in which the identifier is defined.

Attributes: Additional information such as size, dimensions (for


arrays), function parameters, and more.

2. Implementation:

Data Structures: Commonly implemented using hash tables, linked


lists, or binary search trees.

Hash Table: Provides efficient insertion, deletion, and lookup


operations.

Role and Importance

1. Lexical Analysis:
The symbol table is populated with tokens representing identifiers,
along with their basic attributes.

2. Syntax Analysis:

The parser checks the symbol table to ensure identifiers are declared
before use and adheres to scope rules.

3. Semantic Analysis:

Enforces type checking and ensures that operations performed on


identifiers are semantically valid.

4. Code Generation:

Provides necessary information for the allocation of memory and the


generation of machine or intermediate code.

5. Optimization:

Helps identify and optimize repeated computations, dead code


elimination, and other optimizations.

You might also like