Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

SCANNING AND PARSSING, Lecture notes of System Programming

domnvdwipvn feowwfnwaoidnvW[DOIBN VPWAINEG[IOAWEBVAWIOD[BV"sdnvC:lkcNsdv:kNSdoinDVIN

Typology: Lecture notes

2020/2021

Uploaded on 03/28/2022

rahul-kamleshkumar-pithadia
rahul-kamleshkumar-pithadia 🇮🇳

5

(1)

2 documents

1 / 49

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
System Programming
Prof. Trilok Suthar, Assistant Professor
Information Technology
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31

Partial preview of the text

Download SCANNING AND PARSSING and more Lecture notes System Programming in PDF only on Docsity!

System Programming

Prof. Trilok Suthar, Assistant Professor

Information Technology

Compilers

CHAPTER-

Aspects of compilation

  • PL Features
  • Data Types
  • Data Structures
  • Scope Rules
  • Control Structure

Aspects of compilation-data Types

  • Data Types
    • A data is a specification of i. Legal values for variables of the type and ii. Legal operations on the legal values of the type.
    • The following tasks are involved i. Checking legality of an operation for types of operands. ii. Use type conversion operations. iii. Use appropriate instruction sequence of the target machine.

Aspects of compilation-data Structure

- Data Structure - A PL permits the declaration and use of data structure like arrays, stacks, records, lists etc.

  • To compile a reference to an element of a data structure, compiler must develop a memory mappings to access memory word(s) allocated to the element.
  • A user defined type requires mapping of a different kind.

Aspects of compilation-Scope Rule

Scope Rule It determines the accessibility of variables declared in different block of a program. Example:

x, y : real; y, z: integer; x := y

Memory Allocation

  • Memory allocation involves three important tasks:
    1. Determining the amount of memory required for storing the value of data item.
    2. Using an appropriate memory allocation model.
    3. Developing appropriate memory mappings for accessing values stored in a data structure.
  • Types of memory allocations are:
    1. Static memory allocation
    2. Dynamic memory allocation

Memory Allocation-Static Memory

  • In static memory allocation, memory is allocated to a variable before the execution of a program begins.
  • No memory allocation or deallocation actions are performed during the execution of a program. Thus, variables remain permanently allocated.

Code(A) Data(A) Code(B) Data(B) Code(C) Data(C)

Memory Allocation-Dynamic Memory

  • Types of dynamic memory allocation are:
    1. Automatic allocation: memory is allocated to the variables declared in a procedure when the procedure is entered during execution and is deallocated when the procedure is exited.
    2. Program controlled allocation: a program can allocate or deallocate memory at any time during its execution

Dynamic Memory Allocation & Access

  • Each record in a stack is used to accommodate variables of one activation of a block, is called activation record.

ARB (activation record base) 0 (ARB): Dynamic pointer 1 (ARB): static pointer

Reserved pointer

TOS Stack record format

Used for memory allocation and deallocation.

Used for accessing nonlocal variables.

Image source : Google

Compilation of Expression

  • The major issues in code generation for expressions are as follows:
    1. Determination of an evaluation order for the operators in an expression.
    2. Selection of instruction to be used in target code.
    3. Use of registers.

Toy Code Generator for Expressions

  • A toy code generator has to track both the registers (for availability) and addresses (location of values) while generating the code.
  • For both of them, the following two descriptors are used:
  • The code generator uses the notation of an operand descriptor to maintain type, length and addressability information for each operand.
  • It uses a register descriptor to maintain information about what operand or partial result would be contained in a CPU register during execution of the generated code.

Register Descriptor

  • A register descriptor has two fields:
    1. Status: Contains the code free or occupied to indicate register status.
    2. Operand descriptor: If status = occupied, this field contains the descriptor for the operand contained in the register.
  • The register descriptor for AREG after generating code for a*b would be:
  • This indicates that register AREG contains the operand described by descriptor #3.

(Image Source: http://ictpost.com/e-content-challenges-in )

Status Operand descriptor # Occupied #

Types of intermediate forms

  • Types of intermediate forms:
    1. Expression tree
    2. Postfix notation
    3. Three address code