1
$\begingroup$

Wikipedia:

In computing, a compiler is a computer program that translates computer code written in one programming language (the source language) into another language (the target language).

This implies that the compiler can also convert from a low-level language to a high-level language. But this has also got a specific name decompiler.

So what should be the definition for a compiler? 1) or 2)?

  1. In computing, a compiler is a computer program that translates computer code written in one programming language (the source language) into another language (the target language).

  2. A compiler is a computer program that translates computer code written in a high-level programming language into a low-level language.

$\endgroup$
4
  • 2
    $\begingroup$ Compiler is an informal term. It doesn't have a formal definition. $\endgroup$ Nov 3 '20 at 20:10
  • $\begingroup$ The very next sentence after the excerpt you quote addresses your concern, and basically implicitly answers the question you are asking. I think it would have been helpful to mention that and use that to improve your question. $\endgroup$
    – D.W.
    Nov 3 '20 at 20:45
  • $\begingroup$ @Yuval Filmus So if software converts a low-level language to a high-level language, is it a compiler or a decompiler? I am confused by the definitions. $\endgroup$
    – Niraj Raut
    Nov 4 '20 at 4:37
  • $\begingroup$ @D.W.♦ So if software converts a low-level language to a high-level language, is it a compiler or a decompiler? I am confused by the definitions. $\endgroup$
    – Niraj Raut
    Nov 4 '20 at 4:37
2
$\begingroup$

As the comment points out, there's not a formal definition for "compiler", instead it's understood to be that program which translates source code into the target language. Both definitions given are adequate. The definition in Wikipedia is a good one:

In computing, a compiler is a computer program that translates computer code written in one programming language (the source language) into another language (the target language). The name "compiler" is primarily used for programs that translate source code from a high-level programming language to a lower level language (e.g., assembly language, object code, or machine code) to create an executable program.

$\endgroup$
4
  • $\begingroup$ So if it converts a low-level language to a high-level language, is it a compiler or a decompiler? I am confused by the definitions. $\endgroup$
    – Niraj Raut
    Nov 4 '20 at 4:36
  • $\begingroup$ Isn't the second definition missing something that the Wikipedia definition has? How are they both adequate? $\endgroup$
    – Niraj Raut
    Nov 4 '20 at 4:39
  • $\begingroup$ Are "decompilers" and "transpilers" types of compilers? $\endgroup$
    – Niraj Raut
    Nov 4 '20 at 8:39
  • $\begingroup$ Decompilers come up less frequently than compilers; a decompiler is understood to be a program which takes the executable (or object code or other lower-level code) and outputs a higher level source code which would if compiled compile into that given input. In other words, it's the reverse of a compiler. Note though that the source code that comes out of decompilers is typically not very "well-written" and is unlikely to match the actual source code used. $\endgroup$
    – C8H10N4O2
    Nov 5 '20 at 16:25
0
$\begingroup$

Mr Raut. I did some research on your question and here is what I found:

“[A compiler is ] Computer software that translates (compiles) source code written in a high-level language (e.g., C++) into a set of machine-language instructions that can be understood by a digital computer’s CPU. [...] Some compilers translate high-level language into an intermediate assembly language, which is then translated (assembled) into machine code by an assembly program or assembler. Other compilers generate machine language directly. ”

I found this on Encyclopaedia Britannica (https://www.britannica.com/technology/compiler). This implies that #2 is the preferred answer.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.