A language processor is a processor that processes a language and translates it into another language. In system programming, a language processor processes a program in the source language and translates it into the target language. Usually, the source language is a programming language, and the target language is a machine language. While translating, it even identifies the error present in the source language program.
This content will discuss the fundamentals of language processors. How it analyzes the program provided as input? How it further synthesizes this input program into a form that the computer can understand.
Content: Language Processor
What is Language Processor?
If you have to describe computation, in what language will you do it? Obviously, in a language that is convenient for you. But the computer doesn’t understand the language in which you describe the specifications. Neither every user is able to describe the computation in machine language that the computer understands.
So, to overcome this gap between the user and the computer, we introduced a language processor. It handles converting the computation written in your language into the computer language.
A language processor is a system program that a computer uses to implement a user’s computation. The language processor ultimately bridges the gap between:
- How a user specifies a particular computation?
- How the computer further executes the computation?
The ease of specification of a computation depends on the language in which the user has written the specification. Although there are two ways to write a specification of a computation:
- Problem-Oriented Programming
Here, the user can specify a computation using data and operations. The used data and operations should be meaningful for the computation. - Procedure-Oriented Programming
Here, some standard methods exist to create data and perform operations. Here, the user has to specify computation using these standards.
Of the above two languages, problem-oriented is much more convenient. As it is easy for users to specify their intended computation.
Now we know that a language processor converts the user-written program into machine language. But do you know it identifies the errors in the input program during this conversion? It even aborts the conversion if there is any error in the input program.
In simple words, a language processor bridges a semantic gap between the user specification and its execution in a computer. But what exactly the semantic gap is?
What is a Semantic Gap?
A semantic gap is a gap between the application domain and the execution domain. Here application domain represents the program written in a high-level language. However, the execution domain represents the program written in machine language.
Simply, the semantic gap bridges a gap between a user and a computer.
The semantic gap is further classified into two:
Specification Gap
It is the gap between the application domain and the programming language domain. This gap describes the gap between two different specifications describing the same task. However, the semantic gap has to be bridged by the software designer.
Execution Gap
It is a gap between the programming language domain and the execution domain. This gap is between the two programs written in different programming languages. Where one of the programs is in the languages closer to machine language. The language processor, such as a compiler or interpreter, bridges the execution gap.
Now let us also learn about the different types of domains between which these gaps exist.
- Application Domain – The specification language here is just a language convenient to the user.
- Programming Language Domain – The specification language here is any programming language.
- Execution Domain – The specification language here is the machine language.
A client wants a specific software. So he approaches a software designer and specifies his requirements to him in a language (specification language of application domain) that is convenient to him.
Now the software designer would convert (bridges specification gap) the user’s specifications into a program using the programming language (specification language of programming language domain).
Next, the compiler will compile the program designed by the software designer and convert (bridges execution gap) it to machine language (specification language of execution domain) that the computer understands. Knowing this much about the language processor, now let us discuss the activities performed by the language processor.
Language Processor Activity
Language processing is the term we use to refer to the activities performed by the language processor. The language processor performs two activities while converting a specification from one domain to another domain:
Program Generation Activity
The program generation activity bridges the specification gap. Thus, this activity generates a program in a procedure-oriented programming language of the programming language domain out of the specifications described in the specification language of the application domain.
Program Execution Activity
The program execution activity bridges the execution gap. Thus, this activity organizes the execution of a program written in a programming language of the programming language domain by converting it to the machine language of the execution domain.
Examples
- Compilers – C, C++, C#, and Java
- Interpreter – Perl, Python, and MATLAB
- Assembler
Fundamentals of Language Processor
The fundamentals of language processors are the basic principles that form the basis of language processing. It involves two phases:
- Analyzing the source program
- Synthesizing the target program
The components of the language processor involved in analyzing the source program constitute the analysis phase. The components of the language processor involved in synthesizing a target program constitute the synthesis phase.
Analysis Phase
The analysis phase consists of three components.
- Lexical Rule – It analyzes the formation of valid tokens in the source program.
- Syntax Rule – It identifies whether the statements in the source program are in a well-defined format.
- Semantic Rule – It associates meaning with each valid statement in a source program.
Synthesis Phase
The synthesis phase constructs a target language statement for each valid source language statement. However, the meaning of the target language statement is the same as that of the source language statement.
The synthesis phase involves two crucial tasks.
- Memory Allocation – Create a data structure in the target program.
- Code Generation – Generate a target program.
So, the cycle goes like a source program is provided as input to a language processor. Where the analysis phase lexically, syntactically and semantically analyzes the source program. However, the synthesis phase generates a target code.
Language Processor Types
Now there are two different kinds of language processors in the computer.
- The program generator converts the user-specified program into a procedure-oriented programming language.
- A compiler or interpreter helps to convert the program written in a programming language to the machine language or a language close to it.
The compiler is responsible for converting the program written in a programming language into the machine language or a language close to the machine language. However, the interpreter is a little bit different from the compiler. It analyzes the program written in a programming language and starts performing the computations specified in the program with the help of the computer.
The use of compiler and interpreter depends on the need for different programming environments.
So, this is all about the language processor. We have learned how it converts the source program into a target program that is either in machine language or a language close to it. We have also discussed the activities and fundamentals of the language processor.
Leave a Reply