Why do we need a language processor
LANGUAGE PROCESSORS activities arise due to the differences between the manner in which a software designer describes the ideas concerning the behavior of software and the manner in which these ideas are implemented in a computer system.
The designer expresses the ideas in terms related to the application domain of the software. To implement these ideas, their description has to be interpreted in terms related to the execution domain.
Language Processors have two types of Gap.
- Semantic Gap
- Specification and Execution Gaps
1. Semantic Gap
Semantic Gap has many consequences
- Large development time
- Large development effort
- Poor quality of software
2. Specification and Execution Gaps
The software engineering steps aimed at the use of a PL can be grouped into
- Specification, design and coding steps
- PL implementation steps
Specification and Execution Gaps
It is the semantic gap between the two specifications of the same task.
It is the gap between the semantics of programs (that perform the same task) written in different programming languages.
A language processor is a software which bridges a specification or execution gap
The program form input to a language processor as the source program and to its output as the target program.
The languages in which these programs are written are called source language and target language, respectively
Types of Language Processors
A language translator bridges an execution gap to the machine language (or assembly language) of a computer system. E.g. Assembler, Compiler.
A DE translator bridges the same execution gap as the language translator, but in the reverse direction.
A pre-processor is a language processor that bridges an execution gap but is not a language translator.
A language migrator bridges the specification gap between two PLs.
OVERVIEW OF LANGUAGE PROCESSORS
- Why do we need a language processor
- Language Processors
- Language Processing Activities
- Fundamentals of Language Processing
- Phases and Passes of LP
- A Two-Pass Schematic for LP
Language Processors – Examples
Language Processing Activities
1. Program Generation Activities
This activity generates a program from its specification. Thus program generation bridges the specification gap.
An example is Form Filling Program
2. Program Execution Activities
This activity aims at bridging the execution gap by organizing the execution of a program written in PL.
An example is Translation or Interpretation of the program.
Two popular models for program execution are translation and interpretation.
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.
Fundamentals of Language Processing
Language Processing = Analysis of SP + Synthesis of TP
Collection of LP components engaged in analysis of a source program as the analysis phase and components engaged in synthesizing a target program constitute the synthesis phase.
1. Analysis Phase
The specification consists of three components:
- Lexical rules which govern the formation of valid lexical units in the source language.
- Syntax rules which govern the formation of valid statements in the source language.
- Semantic rules which associate meaning with valid statements of the language.
Consider the following example:
percent_profit = (profit * 100) / cost_price;
- Lexical units identifies =, * and / operators, 100 as constant, and the remaining strings as identifiers.
- Syntax analysis identifies the statement as an assignment statement with percent_profit as the left-hand side and (profit * 100) / cost_price as the expression on the right-hand side.
- Semantic analysis determines the meaning of the statement to be the assignment of profit X 100 / cost_price to percent_profit.
The synthesis phase is concerned with the construction of target language statements which have the same meaning as a source statement.
It performs two main activities:
- Creation of data structures in the target program (memory allocation)
- Generation of target code (code generation)
- MOVER AREG, PROFIT
- MULT AREG, 100
- DIV AREG, COST_PRICE
- MOVEM AREG, PERCENT_PROFIT
- PERCENT_PROFIT DW 1
- PROFIT DW 1
- COST_PRICE DW 1
Phases and Passes of LP
Analysis of source statements cannot be immediately followed by the synthesis of equivalent target statements due to the following reasons:
- Forward Reference Issue (Multi-pass organization of LP)
- Issues concerning memory requirements and organization of an LP
- percent_profit = (profit * 100) / cost_price;
- Long profit;
A Two-Pass Schematic for LP
- PASS I: Perform analysis of the source program and note the deduced Information
- PASS II: Perform Synthesis of the target program.