Language Processing
Language Processing
System software is computer software designed to operate and control the computer hardware and to provide a platform for running application software.[
Application Domain
Execution Domain
Consequences of semantic gap large development times, large development efforts, poor quality of s/w Can be tackled by Programming Languages (PLs). Software engineering steps aimed at the use of a PL can be grouped into 1. Specification, design and coding steps. 2. PL implementation steps.
Application Domain
Shorter Gap
Definition Language Processor : A language processor is a software which bridges a specification or execution gap. Language Processing is the activity performed by a language processor. Source program: Input to language processor. Target program : Output of language processor. The language are respectively called source language and target language.
Program Generation
Program generation activities -It aims at automatic generation of a program.
Program Specification
Application Domain
Target PL Domain
Execution Domain
Program Execution
Two popular models are 1. Translation 2. Interpretation Program Translation It bridges the execution gap by translating a program written in a PL, called source Program (SP), into an equivalent program in the machine or assembly language, called target program. Characteristics of the program translation model: A program must be translated before it can be executed. The translated program may be saved in a file. The saved program may be executed repeatedly. A program must be retranslated following modifications.
-i.e. After interpretation, source program is retained in the source form itself, means, no target program form exists.
Analysis Phase
Input of SP Analysis phase -> Specification of the source language Specification consists of 3 components: 1. Lexical rules 2. Syntax rules 3. Semantic rules Lexical Rules : governs the formation of valid lexical units in the SL Syntax Rules : governs the formation of valid statements in the SL Semantic Rules : associate meaning with valid statements
Example : Analysis Phase Consider the statement : Percent_profit := (profit * 100) / cost_price; Lexical analysis identifies : :=, *, / as operators 100 as constant Others as identifiers Syntax analysis identifies: Statement as an assignment statement with percent_profit on LHS and (profit * 100) / cost_price; on RHS. Semantic analysis identifies: Meaning of the statement is profit * 100/cost_price and assign it to percent_profit
Synthesis Phase
The phase is concerned with the construction of target language statement, which have the same meaning as a source statement.
Consist of 2 activities: -Creation of data structures in the target program = memory allocation -Generation of target code = code generation
Errors
Errors
-It is not feasible to analyse a source statement immediately followed by synthesis of eqnt target statements.
-Because : - Forward Reference (Definition ): A forward reference of a program entity is a reference to the entity which precedes its definition in the program. - Example: Defn of variable is given before declaration of variable. - Issues concerning memory reqnt & organization of a language processor. Language Processor Pass (Definition): A language Processor pass is the processing of every statement in a SP, or its equivalent representation, to perform a language processing function.
Source Program
Front End
IR
Back End
Target Program
Symbol table :
Id 1 2 3 4 5 Symbol i a b i* temp Type int Real Real Real real Length address
Intermediate Code 1. Convert (Id, #1) to real, giving (Id, #4) 2. Add (Id, #4) to (Id, #3), giving (Id, #5) 3. Store (Id, #5) in (Id, #2)
Semantic Analysis
-IC from Syntax analysis is passed to Semantic analysis to determine the meaning of the statement. -Example:
Back End
-Back end performs memory allocation and code generation.
-Memory allocation
-Memory allocation is a simple task given the presence of the symbol table. - Memory reqnt of an identifier is computed from its type, length and dimensionality, and memory is allocated to it. - Address of memory is entered into symbol table. Symbol 1 2 3 i a b Type Int Real Real Length address 2000 2001 2002
Source program in L
Syntax specification
IR / Target Code
Using LEX and YACC