PSD1C SYSTEM SOFTWAE UNIT: I - V 1
Syllabus Unit-I Language Processors Types of Language Processors Language Processing Activities Fundamentals of Language Processing Language Specification Data Structures for Language Processing Scanners Parsers 2
Language Processor A language processor is a software which bridges a specification or execution gap. 3
Types of Language Processor 4
Language Processor Activities 5
Fundamentals of Language Processor 6
Fundamentals of Language Processor Analysis Phase and Synthesis Phase 7
Language Specification 8
Data Structures for Language Processing Types: Linear : Example : Array, Stack Non-Linear: Example: Tree, Graph Based on Operations: Search data structures Hashing functions Linked list and tree structures Allocation data structures Stacks Heaps 9
Search Data Structures Entry Format: Types of operations: 1. Add: Add the entry of a symbol. 2. Search: Search and locate entry of a symbol. 3. Delete: Delete the entry of a symbol. 10
Allocation Data Structures Stacks: Allocation & De allocation performed based on LIFO. Only last entry is accessible at any time. A pointer Stack Base(BS) points to starting location of a stack. A pointer Top of Stack(TOS) points to last location of the stack. Allocation PUSH, De allocation POP and Length is denote by l. Heaps: A non-linear data structure which permits random order processing. Memory management: Due to repetition of allocation and deallocation of memory area holes are created in memory area. It increases performance and speed of allocation and deallocation of memory spaces. Two popular techniques are :- Reference counts Garbage Collection 11
Scanner Finite State Automation(FSA) is a triple(s, Σ, T): S Set of finite states. One as initial and one other as final states. Σ Set of alphabets or source symbols. T Set of state transitions. Example: d Start d Int 12
Parsers Abstract Syntax Tree Vs. Parse Tree 13
Types of Parsing 14
Syllabus Unit - II Elements of Assembly Language programming Overview of the Assembly process Design of a Two-pass assembler Advanced Assembler Directives A single pass assembler for IBM-PC 15
Assemblers Machine dependent, low level programming language. Basic Features: Mnemonic operation codes. Symbolic operands(data / Instruction) Data declarations.(any notations like binary, decimal, etc) Statement Format: [Label] <Opcode> <operand spec>[,<operand spec>..] 16
Overview of Assembly process In this language each statement has two operands. The first operand is always is always a register which can be any one of AREG, BREG, CREG, DREG. The second operand refers to a memory word using a symbolic name and an optional displacement. Example: MOVER <operand1> <operand2> Operand1 denotes target operand. Operand 2 denotes source operand. 17
Assembly language Statements Imperative statements: Indicates an action to be performed. Translates into one machine instruction. Declaration statements: Syntax: [Label] DS <constant> : Ex: A DS 1.(Storage) [Label] DC <value> : Ex: ONE DC 1.(Constant) Assembler directives: Indicates to perform certain actions. Example: START, END 18
Design Specification 1. Identify the information necessary to perform a task. 2. Design a suitable data structure to record the information. 3. Determine the processing necessary to obtain and maintain the information. 4. Determine the processing necessary to perform a task. 19
Data Structures 20
2 Pass Assembler 21
Design of Two Pass Assemblers 22
Two Pass Translation Pass I: Symbols are entered into the symbol table. Construct the Intermediate Representation of source program. Handles forward references. Pass II: Target program will be synthesizes using address found in the symbol table. 23
Advanced Assembler Directives ORIGIN: OIRGIN <address spec> : Tell assembler where to load instruction / data into memory. Ex: ORIGIN 1024. EQU: <symbol> EQU <address spec>: Defines the symbol to represent <address spec>. Equates the a value to a symbol. Ex: Sunday EQU 1, Monday EQU 2. LTORG: Origin for Literals: Allows a programmer to specify where the literals to be placed. (Memory allocation Literal Pools). 24
IC for Imperative Statements Format: (operand class, code). 25
IC for Declarative Statements Example: START 200 (AD,01) (C,200) AREA1 DS 20 200) (DL, 02) (C,20) SIZE DC 5 220) (DL, 01) (C,5) 26
Syllabus Unit - III Macros and Macro Pre-processors Macro Definition, Call and Expansion Nested Macro Calls Advanced Macro facilities Design of a Macro pre-processor 27
Macros A Macro is a unit of specification for program generation through expansion. A Macro consists of a name, set of formal parameters and a body of code. A macro name with a set of actual parameters is replaced by some code generated from its body. It is called Macro Expansion. 28
Macros 29
Macro Expansion 30
Macro Expansion Lexical Expansion: Replacement of character string by another during program generation. Typically used for replacement of formal parameter by corresponding actual parameters. Semantic Expansion: Generation of instructions tailored to the requirements of a specific usage. 31
Macro Definition It is enclosed between a macro header and macro end statement. Macro definition are typically located at the start of a program. Definition consists of: A macro prototype statement One or more model statement Macro pre-processor statement 32
Macro Expansion Implemented using Macro Expansion Counter(MEC). Algorithm: MEC=statement number of first statement following the prototype statement; While statement pointed by MEC is not a MEND statement (a) if a model statement then (i) Expand the statement (ii) MEC=MEC+1; (b) Else (i.e. a per-processor statement) (i) MEC= new value specified in the statement; Exit from macro expansion. 33
Macro Call A Macro is called by writing the macro name in the mnemonic field of an assembly statement. <macro name> [<actual parameter spec>, ] Where an actual parameter typically an operand specification in an assembly language statement. 34
Nested Macro Calls A model statement in a macro may be a call on another macro. Such calls are known as nested macro calls. Calling macro Outer macro. Called macro Inner macro. Expansion of nested macro call Last in First Out(LIFO) rule. 35
Nested Macro Calls 36
Advance Macro Facilities Supports semantic expansion. Facilities for alternation of flow of control during expansion. Expansion time variables. Attributes of parameters. Expansion time statements AIF, AGO, ANOP. AIF statement: AIF(<expression>) <sequencing symbol> Expression Relational expression (If true move to sequencing symbol) AGO Statement: AGO <Sequencing Symbol> ANOP statement: <sequencing symbol> ANOP 37
Design of Macro Pre-processor 38
Design Overview Tasks involved in macro expansion: 1. Identify macro calls in the program. 2. Determine the values of formal parameters. 3. Maintain values of expansion time variables. 4. Organize expansion time control flow. 5. Determine the values of sequencing symbols. 6. Perform expansion of a model statement. 39
Design Specification Identify the information necessary to perform a task. Design a suitable data structure to record the information. Determine the processing necessary to obtain the information. Determine the processing necessary to perform the task. 40
Tables of Macro Pre processor Table Macro name Table(MNT) Fields in each entry Macro name, Number of positional parameter(#pp), Number of keyword parameter(#kp), Number of expansion time variables(#ev), MDT pointer (MDTP). KPDTAB pointer (KPDTP). SSTAB pointer (SSTP). Parameter Name Table(PNTAB) EV Name Table (EVNTAB) SS Name Table (SSNTAB) Keyword Parameter Default Table(KPDTAB) Macro Definition Table(MDT) Actual Parameter Table(APTAB) EV Table (EVTAB) Parameter name EV name SS name Parameter name, default value Label, Opcode, Operands Value Value SS Table (SSTAB) MDT entry # 41
Syllabus Unit - IV Compilers: Aspects of Compilation Memory Allocation Compilation of Expressions and Control structures Code Optimization Interpreters 42
Aspects of Compilation Compiler & Interpreter Bridge Semantic Gap PL Domain Execution domain Generate Code to implement meaning of a source program in ED. Provide Diagnostics for violation of PL semantics in a SP. 43
Data types Definition: A data type is the specification of Legal values for variable of type. Legal operations on the legal values of the type. Tasks: Check legality of operations for type of its operands. Use type conversion operations wherever necessary & permissible. Use appropriate instruction sequence. Example: Var x,y: real; i:integer; y:=10; x:=y+i; Type conversion of I is needed. 44
Data Structure PL permits declaration of DS and use it. Compiler must develop memory mapping to access allocated memory area of an element. A record, heterogeneous DS leads to complex memory mapping. User defined DS requires mapping of different kind. Proper combination of DS is required to manage such complexity of structure. Two kind of mapping is involved Mapping array reference Access field of record 45
Scope Rules Determine the accessibility of variable declared in different blocks of a program. Eg: x, y: real; y, z: interger; A x:=y; B x:=y uses the value of y of block B and x of block A. To determine accessibility of variable compiler performs the following operations: Scope Analysis Name Resolution 46
Control Structure Definition: It is a collection of language features for altering flow of control during execution. It includes: Conditional Transfer Conditional Execution Iteration Control Procedure Calls Compiler must ensure non-violation of program semantics. 47
Memory Allocation Memory allocation involves three important tasks: Determine the amount of memory required for a value. Use of appropriate model to implement lifetime and scope of a variable. Determine appropriate memory mappings to access the values in a non scalar data item. Activities: Static and Dynamic memory allocation. Memory allocation in Block Structured languages. Array allocation and Access. 48
Static & Dynamic Allocation Static Allocation MA done before execution of program begins. Performed during compilation. At execution no allocation & de-allocation. Allocation is active throughout the program. Dynamic Allocation MA done during the time of execution. Performed during execution. Allocation & de-allocation occurs only at execution. Allocation is active only if program unit is active. 49
Compilation of Expression The major issues in generator for expression: A Toy generator for expression Intermediate code for expression 50
A Toy generator for Expression Determination of execution order for operators. Selection of instruction used in target code. Use of registers and handling partial result. Operand descriptor(to maintain type, length, address) Register descriptor(status: Free/Occupied) Generating an instruction(operand / Register) 51
Intermediate Code Generation Postfix string(operator appear immediately after Operands) Triples[Opr oprnd1 oprnd2] Quadruples [Opr Oprnd1 Oprnd2 Result Name] Expression Trees (Evaluative order) 52
Compilation of Control Structures Governs the sequencing of control through a program. Control Transfer, Conditional Execution & Iterative Constructs. (Goto, If, For) Function & Procedure Calls (Actual parameters, Control transfer, return value). Calling Conventions. (Static and Dynamic) Parameter Passing Mechanism a) Call by Value b) Call by Value Result(Return formal parameter value to Actual parameter) c) Call by Reference d) Call by Name (same as CBR) 53
Code Optimization Aims at improving the execution efficiency of a program. Redundancies in a program are eliminated. Computations are rearranged or rewritten to execute efficiently. Types: Local Global Source Program Front End Optimization Phase Back End Target Program IR 54
Interpreters Avoid overhead of compilation. Modification at every execution is managed by interpreters. Each statement is subject to follow the following interpreters cycle: Fetch the instruction. Analyse statement and determine meaning. Execute the meaning of statement. 55
Syllabus Unit - V Linkers: Linking and Relocation Concepts Design of a linker Self relocating Programs A linker for MSDOS Linking for overlays Loaders Software Tools for Program development Editors Debug Monitors Programming Environments User interfaces 56
Linkers Execution of a program written in a language L involves the following steps: Translation of the program. Linking of the program with other programs needed for its execution. Relocation of the program to execute from the specific memory area allocated to it. Loading of the program in the memory for the purpose of execution. 57
Schematic of program execution Data Translator Linker Loader Contro l Flow Binary Program Results Object Modul e Binary Program s Arrows indicate Data flows 58
Relocation Let AA be the set of Absolute Addresses or instruction address or data address. AA ф ; means instruction or data occupy memory words with specific address. Such a program is called address sensitive program. which contains: Address Sensitive Instruction: An instruction which contains address ai Є AA. Address Constant: a data word which contains an address ai Є AA. 59
Linking Concepts Definition: Linking is the process of binding an external reference to the correct link time address. AP(Application Program) consisting of a set of program units SP = {Pi}. A program unit Pi interacts with another program unit Pj using instructions and addresses of Pj. To realize such interactions, Pj and Pi must contain public definitions and external references. Public Definition: a symbol pub_symb defined program unit which may be referenced in other program. External reference: a reference to a symbol ext_symb which is not defined in program unit containing the reference. 60
Design of a Linker 61
Self Relocating Programs Programs can be classified based on the load origin: Non Re-locating programs. Re-locatable programs. Self Re-locating programs. 62
Linker for MS DOS Design of a linker for Intel 8088 processor which resembles of MS DOS. Object Module Format. It is a sequence of object records. Categories: Binary image, External reference, public definition, Debugging information and Miscellaneous information. Specification Data Structures and Algorithms 63
Linking for Overlays 64
Loaders Types: Absolute Loaders: Can load only programs with load origin = linked origin. This is inconvenient when load address differ from the one specified for execution. Relocating loaders: Performs relocation while loading a program for execution. Permits program to be executed in different parts of memory. 65
Software Tools for Program Development Software tool is a system program which Interfaces a program with the entity generating its input data. Interfaces the results of a program with the entity consuming them. A schematic of a software tool: Originator Types of Software Tools: Tools for program development. User Interface Raw Program or data Software tools s Transforme d Program or data Consumer 66
Program Development The fundamental steps in program development: Program design, coding & documentation Preparation of program in machine readable form Program translation, linking & loading Program testing and debugging Performance tuning Source code management and versioning Reformatting the data and/or results of a program to suit other program. 67
Editors 68
Debug Monitors Provides the following facilities for dynamic debugging: Setting breakpoints in the program. Initiating a debug conversation when control reaches a breakpoint. Displaying values of variables. Assigning new values to variables. Testing user defined assertions & predicates involving program variables. 69
Programming Environments Provides Integrated facilities for program Creation, editing, execution, testing and debugging. Following components A syntax directed editor A language processor A debug monitor A dialog monitor 70
User Interfaces (UI) UI simplifies the interaction of a user with an application. Aspects of UI functionalities are: Issuing of commands. Exchange of data. Consists of two components: Dialog Manager: Manages the conversation between the user and the applications. Presentation Manager: Displays the data produced by the application in an appropriate manner on user s display. 71
Structure of UI 72