Translator
The translator —
- the Program or the technical tool executing broadcast of the program.
- the Machine program which broadcasts from one language on another and, in particular, from one programming language on another.
- the Processing program intended for conversion of the initial program to object module.
Content |
The translator usually executes also diagnostics of errors, forirut dictionaries of identifiers, issues for printing texts of the program, etc.
Broadcast of the program — conversion of the program provided in one of programming languages to the program in other language and, in a sense, equivalent to the first.
Language in which the entrance program is submitted is called source language, and the program — the source code. The output language is called target language or the object code.
The concept of broadcasting relates not only to programming languages, but also to other computer languages, like the markup languages similar to HTML, and to natural languages, like English or Russian. However this article only about programming languages, about natural languages see: Transfer.
Types of translators
- Address. The functional device transforming a virtual address (Virtual address) to a real memory address (Memory address).
- Dialogue. Provides use of a programming language in time partitioned mode.
- Multipass. Creates object module for several viewings the initial program.
- The return. The same that decompiler. See Also: decompiler, disassembler.
- Single-pass. Creates object module for one consecutive viewing the initial program.
- Optimizing. Executes code optimization in the created object module.
- Syntax focused (syntax managed). Receives on an input the description of syntax and semantics of language and the text in the described language which is broadcast according to the set description.
- Test. A set of the macro instructions of language of the assembler allowing to set different debug procedures in the programs made in assembler language.
Implementations
The broadcasting purpose — to transform the text from one language on another which is clear to the addressee of the text. In case of programs translators, an addressee is the engineering device (processor) or the program interpreter.
Language of processors (machine code) usually is low-level. There are platforms using as machine language of the high level (for example, iAPX-432
Шаблон:Beginning of the quote It is possible to give some other examples in which the architecture of the developed series of computers was based or strongly depended on some model of structure of the program. So, the GE/Honeywell Multics series was based on a semantic model of accomplishment of the programs written in PL/1 language. In Шаблон:En is not translated B5500, B6700 … served B7800 as a prototype model of the program of a stage of accomplishment written in the expanded ALGOL language. …
The i432 processor, like these early architecture, is also based on a semantic model of structure of the program. However, unlike the predecessors, i432 is not based on model of some specific programming language. Instead, ensuring direct support at an accomplishment stage as for abstract data (i.e. programming with abstract data types), and for the domain focused operating systems was a main objective of developers. …
Language of Hell supports the object based programming, as caused the choice it as the main programming language for i432. Шаблон:The end of the quote</ref>), but they are an exception of the rule owing to complexity and high cost. The translator which will transform programs to the machine language accepted and performed directly by the processor is called the compiler.
Compile process as a rule consists of several stages: lexical, syntax and Шаблон:En is not translated, generation of the intermediate code, optimization and generation of the resulting machine code. In addition, the program as a rule depends on the services provided by the operating system and third-party libraries (for example, file input-output or the graphical interface), and the machine code of the program needs to be connected with these services. Linking with static libraries is executed by a link editor or the binder (who can be the separate program or to be a part of the compiler), and with the operating system and dynamic libraries binding is executed at the beginning of execution of the program by the loader.
Compiler advantage: the program is compiled once and at each accomplishment additional conversions are not required. Respectively, availability of the compiler by the target machine for which the program is compiled is not required. Shortcoming: the separate stage of compilation slows down writing and debugging and complicates execution of small, simple or single programs.
If source language is assembler language (the low-level language close to a machine language), the compiler of such language is called the assembler.
The opposite implementation method — when the program is performed using the interpreter in general without broadcasting. The interpreter programmatically models the machine which cycle of selection execution works with commands in languages of the high level, but not with machine instructions. Such software simulation creates the virtual machine implementing language. This approach is called net interpretation. Net interpretation is applied as a rule to languages with simple structure (for example, the nuclear submarine or Lisp). Interpreters of the command line process commands in scripts in UNIX or in batch files (.bat) in MS-DOS also as a rule in the mode of net interpretation.
Advantage of the net interpreter: the lack of intermediate actions for broadcasting simplifies sale of the interpreter and does it more convenient in use, including in a dialogue mode. The shortcoming — the interpreter should be available by the target machine where the program should be performed. And property of the net interpreter that errors in the interpreted program are found only in attempt of command execution (or lines) with an error, it is possible to recognize both as a shortcoming, and advantage.
There are options of implementation of programming languages, compromise between compilation and net interpretation, when the interpreter before execution of the program broadcasts it on an intermediate language (for example, in a bytecode or the p-code), more convenient for interpretation (i.e. it is about the interpreter with the built-in translator). Such method is called the mixed implementation. Perl can be an example of the mixed implementation of language. This approach combines as the advantage of the compiler and the interpreter (high speed of execution and convenience of using), and shortcomings (for broadcasting and storage of the program on an intermediate language additional resources are required; for execution of the program by the target machine the interpreter should be provided). Also, as well as in case of the compiler, the mixed implementation requires that before execution the source code did not contain errors (lexical, syntax and semantic).
In process of increase in resources of computers and expansion of the heterogeneous networks (including the Internet) connecting computers of different types and architecture the new type of interpretation at which initial (or intermediate) the code is compiled in machine code directly during execution, "on the fly" was selected. Already compiled code locations are cached that at the repeated address to them they received management, without recompilation at once. This approach received the name of dynamic compilation.
The advantage of dynamic compilation is that the speed of interpretation of programs becomes comparable with a speed of execution of programs in the normal compiled languages, at the same time the program is stored and extends in the only type independent of target platforms. A shortcoming is the big complexity of implementation and big resource requirements, than in case of simple compilers or net interpreters.
This method well approaches for web applications. Respectively, dynamic compilation appeared and supported to some extent in implementations Java Microsoft .NET Perl Python.
Mixing of concepts of broadcasting and interpretation
Broadcasting and interpretation — different processes: broadcasting is engaged in the translation of programs from one language on another, and interpretation is responsible for execution of programs. However, as the broadcasting purpose as a rule is preparation of the program for interpretation, these processes usually are considered together. For example, programming languages are often characterized as "compiled" or "interpreted", depending on that, prevails when using language compilation or interpretation. And practically all programming languages of the low level and third generation, like the assembler, Si or Moduly-2, are compiled, and more high-level languages, like Python or SQL — interpreted.
On the other hand, there is an interpenetration of processes of broadcasting and interpretation: interpreters can be compiling (including with dynamic compilation), and in translators interpretation for metaprogramming constructions can be required (for example, for macroes in language of the assembler, conditional compilation in Si or for templates in C ++).
Moreover, the same programming language can be broadcast and be interpreted, and at both cases there have to be general analysis stages and recognitions of constructions and directives of source language. It belongs also to program implementations, and to equipment rooms — so, x86 family processors before execution of instructions of a machine language execute their decoding, selecting in opkoda of a field of operands (registers, memory addresses, direct values), digit capacity, etc.