Source-to-Source Compiler
A Source-to-Source Compiler is a compiler that transforms source code written in one programming language into source code in another programming language, often maintaining the same level of abstraction.
- AKA: Transpiler.
- Context:
- It can (typically) transform source code from one programming language to another while preserving the original programming constructs and logic.
- It can (often) facilitate software development by enabling code to run on platforms where the original language is not supported or less efficient.
- It can range from translating high-level languages such as Python to JavaScript, to converting between dialects or versions of the same language.
- It can aid in software maintenance by translating legacy code to newer language versions or standards, thus extending the life and compatibility of older software systems.
- It can be used to optimize code by translating it into a form that performs better under specific circumstances or environments.
- ...
- Example(s):
- a transpiler that converts TypeScript code into JavaScript, helping developers use advanced features of TypeScript while targeting environments that support JavaScript.
- Emscripten, which translates C or C++ into JavaScript, enabling complex applications and games to run in web browsers.
- ...
- Counter-Example(s):
- Traditional compilers that translate high-level programming languages into machine code or lower-level languages, such as a C compiler generating assembly language.
- See: Emscripten, Translator (Computing), Source Code, Programming Language, Abstraction (Computer Science), Compiler, High-Level Programming Language, Low-Level Programming Language, Python (Programming Language), JavaScript (Programming Language), C (Programming Language), Assembly Language.
References
2024
- (Wikipedia, 2024) ⇒ https://en.wikipedia.org/wiki/Source-to-source_compiler Retrieved:2024-5-7.
- A source-to-source translator, source-to-source compiler (S2S compiler), transcompiler, or transpiler[1][2][3] is a type of translator that takes the source code of a program written in a programming language as its input and produces an equivalent source code in the same or a different programming language. A source-to-source translator converts between programming languages that operate at approximately the same level of abstraction, while a traditional compiler translates from a higher level programming language to a lower level programming language. For example, a source-to-source translator may perform a translation of a program from Python to JavaScript, while a traditional compiler translates from a language like C to assembly or Java to bytecode.[4] An automatic parallelizing compiler will frequently take in a high level language program as an input and then transform the code and annotate it with parallel code annotations (e.g., OpenMP) or language constructs (e.g. Fortran's
forall
statements).[2][5]Another purpose of source-to-source-compiling is translating legacy code to use the next version of the underlying programming language or an API that breaks backward compatibility. It will perform automatic code refactoring which is useful when the programs to refactor are outside the control of the original implementer (for example, converting programs from Python 2 to Python 3, or converting programs from an old API to the new API) or when the size of the program makes it impractical or time-consuming to refactor it by hand.
Transcompilers may either keep translated code structure as close to the source code as possible to ease development and debugging of the original source code or may change the structure of the original code so much that the translated code does not look like the source code.[6] There are also debugging utilities that map the transcompiled source code back to the original code; for example, the JavaScript Source Map standardallows mapping of the JavaScript code executed by a web browser back to the original source when the JavaScript code was, for example, minified or produced by a transcompiled-to-JavaScript language. Examples include Closure Compiler, CoffeeScript, Dart, Haxe, Opal, TypeScript and Emscripten.[7]
- A source-to-source translator, source-to-source compiler (S2S compiler), transcompiler, or transpiler[1][2][3] is a type of translator that takes the source code of a program written in a programming language as its input and produces an equivalent source code in the same or a different programming language. A source-to-source translator converts between programming languages that operate at approximately the same level of abstraction, while a traditional compiler translates from a higher level programming language to a lower level programming language. For example, a source-to-source translator may perform a translation of a program from Python to JavaScript, while a traditional compiler translates from a language like C to assembly or Java to bytecode.[4] An automatic parallelizing compiler will frequently take in a high level language program as an input and then transform the code and annotate it with parallel code annotations (e.g., OpenMP) or language constructs (e.g. Fortran's
- ↑ Cite error: Invalid
<ref>
tag; no text was provided for refs namedARC_1988_Transpiler
- ↑ 2.0 2.1 Cite error: Invalid
<ref>
tag; no text was provided for refs namedPountain_1989
- ↑ Cite error: Invalid
<ref>
tag; no text was provided for refs namedSector7_1993_Transpiler
- ↑ Cite error: Invalid
<ref>
tag; no text was provided for refs namedDevopedia_Transpiler
- ↑ Cite error: Invalid
<ref>
tag; no text was provided for refs namedCompiler_Types
- ↑ Cite error: Invalid
<ref>
tag; no text was provided for refs namedFowler_2013
- ↑ Cite error: Invalid
<ref>
tag; no text was provided for refs namedEpic_Games