Anda di halaman 1dari 12

System Programming

Chapter-1

Language Processors

Chapter-1:

Language Processors

Introduction of System Programming


System programming (or systems programming) is the activity of programming system software. The primary distinguishing characteristic of systems programming when compared to application programming is that application programming aims to produce software which provides services to the user (e.g. word processor), whereas systems programming aims to produce software which provides services to the computer hardware (e.g. disk defragmenter). It requires a greater degree of hardware awareness. Examples of system Software: 1. Text Editor: that is used to create and modify the program. 2. Compiler: Translate the High level language program into machine language program. 3. Loader: That loads the machine language program into memory for execution. 4. Debugger: It detects the errors in the program. 5. Translator: Translate the assembly language program into machine language program. It is also known as assembler.

Introduction of Language Processors


Language Processor: A language processor is software which creates a bridge between specification gaps or execution gap. Now we will discuss on specification and execution gap. Semantic gap: Semantic gap is the gap between two domains. In following fig. it is the gap between Application domain and Execution domain.

Jignesh Patel/Computer Department/Sardar Patel Institute of Technology, Piludara

Page 1

System Programming

Chapter-1

Language Processors

Application domain consist required information of High level language statements. Execution domain consist required information of Assembly language statements. Ex: High level language statement: x= x + 3 may consist of number of assembly language statements like: Load memory location 24 into accumulator Add a constant 3 to the accumulator Store accumulator in memory location 24 The number of executable statement expands greatly during the translation process from a high level language into assembly language so there will be a gap and it is known as semantic gap. A semantic gap is tackled using software engineering steps like 1) Specification, design and coding 2) PL implementation steps. The software implementation using the PL domain introduces the new domain called the PL domain which comes between the application domain and the execution domain.

Specification gap: - It is the semantic gap between the two specifications of the same task. Execution gap: - The gap between the semantics of programs written in the different programming languages. Language processors: - It is software which bridges a specification or execution gap. The input program of a language processor is a source program and the output program is the target program. The different types of language processors are 1. 2. 3. 4. 5. Language translators:- Bridges an execution gap to the machine language assemblers- A language translator whose source language is assembly language compiler- A language translator whose source language is a high level language Detranslator:-converts machine language to assembly level language. Preprocessor:- Which bridges an execution gap and is not a language translator.
Page 2

Jignesh Patel/Computer Department/Sardar Patel Institute of Technology, Piludara

System Programming

Chapter-1

Language Processors

Example of Language Processor:

In fig.(a) C++ preprocessor is a language processor that translates the C++ program into C program. Here C++ program is a source program and C program is a target program. In fig.(b) C++ translator is a language processor that translates the C++ program into machine language program. Here C++ program is a source program and machine language program is a target program.

Language Processing Activities


Language Processing Activities: The Language processing activities can be divided into those that bridge the specification gaps and those that bridge execution gaps. We named these activities as : 1. Program generation activities : It automatic generates the program 2. Program execution activities: It organizes the execution of a program written in PL on a computer system. 1. Program generation:

The program generator is a software system that accepts the specification of the program to be generated and generates the target PL. So, it introduces a new domain between the PL and application domains program generator domain.

Jignesh Patel/Computer Department/Sardar Patel Institute of Technology, Piludara

Page 3

System Programming

Chapter-1

Language Processors

Specification gap is now the gap between the application domain and the program generation domain. This gap is smaller than the gap between application and PL domains. This reduction in gap increases the reliability of the program and since the generator is closer to application domain, it is easier to write the specification of the program to be generated. 2. Program execution: Program execution includes two methods to execute the program: 1) Program Translation 2)Program Interpretation 1. Program Translation: It bridges the execution gap by translating the source program into target program.

The main characteristics are: Program must be translated before execution. The translated program may be saved in a file for repeated execution. A program must be retranslated following modifications. 2. Program Interpretation: It reads the source program and store whole program into memory. From memory, Interpreter fetches the statements one by one and then translates.

Jignesh Patel/Computer Department/Sardar Patel Institute of Technology, Piludara

Page 4

System Programming

Chapter-1

Language Processors

As shown in above figure, the interpreter contains PC-Program Counter that contains the address of next instruction in memory for further execution. The instruction follow the instruction execution cycle consisting following phases: 1. FETCH: Fetch the instruction from memory 2. DECODE: decode the instruction to determine the operation to be performed, and also its operands. 3. EXECUTE: Execute the instruction as per operation(meaning).

Fundamental of Language processing


Language Processing = Analysis of SP + Synthesis of TP (SP-Source Program, TP- Target Program) Analysis-Synthesis Model: It consists two phases: 1) Analysis phase 2) Synthesis phase

1. Analysis Phase: In analysis phase the source program is read and perform following steps: 1. Identifies the identifiers from source program 2. Find the syntax of the source program 3. Determine the meaning of source program

Analysis phase is divided into three sub-parts: 1. Lexical Analysis: Here the source program is read and indentifies the tokens of source program. Token: identifiers, operators, symbol, keywords 2. Syntax Analysis: Here the tokens are arranged into hierarchical structure to find the syntax of the source program. 3. Semantic Analysis: It determines the meaning of source program. 2. Synthesis Phase: Synthesis of SP is known as Synthesis phase of language processor. Synthesis phase consists of two main activities: 1. Creation of data structures in target program 2. Generation of target code

Jignesh Patel/Computer Department/Sardar Patel Institute of Technology, Piludara

Page 5

System Programming

Chapter-1

Language Processors

Phases:

[Fig. Phases of Compiler]


As shown in above figure, There are six phases but they are categorized into main two phases: Analysis phase: It consists first three phases Lexical analysis, Syntax analysis & Semantic analysis Synthesis phase: It consists last two phases optimization and code generation. Example: total = count + rate * 10 1. Lexical Analysis (Scanning): It reads above statements and identifies tokens from above statement as follows: total, count, rate identifiers = -- assignment operator + -- Arithmetic plus operator * -- Arithmetic multiplication operator 10 Constant
Jignesh Patel/Computer Department/Sardar Patel Institute of Technology, Piludara Page 6

System Programming

Chapter-1

Language Processors

2. Syntax Analysis (Parsing): The tokens are arranged into hierarchical structure as follows: =

total

count

rate

10

Fig. Parse tree of total = count + rate*10 This is also known as parse tree or syntax tree.

3. Semantic Analysis : It determines the meaning above string and determine which conversion is required as follows: =

total

count

rate

Int to float

10

Now all above three analysis phases completed, and after these phases Intermediate codes gets generated.

Jignesh Patel/Computer Department/Sardar Patel Institute of Technology, Piludara

Page 7

System Programming

Chapter-1

Language Processors

4. Intermediate code generation: This code is generated from source code in analysis phase and the target code can easily generated from this code during synthesis phase. It uses the above tree of semantic analysis to generate intermediate code. The intermediate code of example total = count + rate *10 generated as follows:

t1 = int to float (10) t2 = rate * t1 t3 = count + t2 total = t3 1. 2. 3. Properties of Intermediate code generation: Each instruction has at most two operators including assignment operator. There must be the temporary variables to hold intermediate results. Some instructions have fewer than three operands like t1 = int to float (10) total = t3 5. Code optimization: This is the next phase of Intermediate code generation and it is try to optimize the above intermediate code to improve running time.

6. Code Generation: It generates the final target code from intermediate code as follows : MOV rate, R1 MUL #10.0, R1 MOV count, R2 ADD R2, R1 MOV R1, total

Jignesh Patel/Computer Department/Sardar Patel Institute of Technology, Piludara

Page 8

System Programming

Chapter-1

Language Processors

Example: a = b + c*60

Jignesh Patel/Computer Department/Sardar Patel Institute of Technology, Piludara

Page 9

System Programming

Chapter-1

Language Processors

Symbol Table management: The symbol table stores identifiers used in the program. It also stores the attributes of each identifier. (Attributes type, scope, address of identifier, memory requirement.) It also stores information about the sub-routines used in the program. And also contains the details of arguments like types of arguments, number of arguments, and method of passing these arguments whether by reference or value. Using symbol table, the compiler or assembler can find the record of each identifier quickly, so the storage and retrieve operation performs quickly. In symbol table, the lexical analyzer determines the identifiers from source program and makes entry of each of them into symbol table. But the entry of attributes of each identifier proceed into remain phases. For example, during semantic analysis & intermediate code generation phases, make entry of types of each identifier. And during code generation, make entry of storage size for allocation. Error Detection and handling: During processing of phases, each phase detects errors and reported to error handler. Error handler handles the errors, so compilation can proceed. Role of phases in error detection: Lexical Analyzer: Detect errors when input is not match with token operations. Syntax Analyzer: Detects errors when the syntax of program statements is wrong. Semantic Analyzer: Detects errors like type mismatch

Language Processor Pass: A language processing pass is the processing of every statement in a source program, or its equivalent representation to perform a language processing function. There are two passes of language processor which is divided by analysis phase and synthesis phase: Pass I : Perform analysis of source program and gather equivalent information. Pass II : Perform synthesis of target program. percent_profit = (profit*100)/cost_price . . . long profit In above example, during Pass I, all information of variable profit is gathered (like data type of profit) and then the generation of code is proceeding in Pass II.

Jignesh Patel/Computer Department/Sardar Patel Institute of Technology, Piludara

Page 10

System Programming

Chapter-1

Language Processors

Intermediate Representation (IR): It is representation of source program and target program but not all. Intermediate Representation is used in Language processor pass

Fig. IR As shown in above figure, Pass I perform analysis of source program and reflects its results in Intermediate representation. Pass II reads the IR instead of source program and perform synthesis of target program. This avoids repeated processing of source program. The Pass I is concern with source program, so it is known as Front end and Pass II is concern with target program, so it is known as Back end of language processor.

Fundamental of Language Specification

Jignesh Patel/Computer Department/Sardar Patel Institute of Technology, Piludara

Page 11

System Programming

Chapter-1

Language Processors

As shown in above figure, the source program written in high level language enters into compiler and that converts into target assembly language. Then the Assembler takes the assembly language code as input and produces the relocatable machine code as output. Then the loader loads this re-locatable machine code into memory at proper location. Then the linker creates a link between current file and all referenced files. These files can be header files, library files. And in this process, the re-locatable machine code converts into executable machine code.

**********************************************************

Jignesh Patel/Computer Department/Sardar Patel Institute of Technology, Piludara

Page 12

Anda mungkin juga menyukai