3
$\begingroup$

I've been trying to figure out what technically makes a tool or program a compiler.

For example, I know that gcc will compile source code to object files or assembly, hence transforming a programming language to a different form by breaking it down into "words" with some lexer and reading the "grammar" of the words with some parser, and finally compiling it.

But is the term compiler limited to transforming specifically programming languages?

For example, there's a tool called doxygen that will read all of the documentation from source code files, break them down, and generate output based on the documentation. Is this considered to be a compiler?

$\endgroup$

2 Answers 2

9
$\begingroup$

A compiler translates code written in one programming language into code in another language -- normally, with the semantics of the output code being the same as the input code (or with a strong relationship).

Personally, if you asked me to use the word strictly, I wouldn't call Doxygen a compiler. The output isn't executable code, and doesn't have anything like the same semantics as the input source code.

See also Wikipedia's definition/explanation.

That said, there are many situations where we use a word loosely, when from context it will be understood what we're referring to -- so I'm not sure how useful it will be to look for a super-precise definition of the word. If the specific definition is important in your writing, then it might be best to define how you plan to use the term.

$\endgroup$
4
  • $\begingroup$ Note that by compilers often only omit assembly code, not object files. Tools like gcc are actually a "driver" that call the compiler (cc1), assembler (as), and linker (ld) as needed. $\endgroup$
    – o11c
    Commented Apr 7, 2016 at 5:50
  • 3
    $\begingroup$ Hm. What would we call a tool that converts Markdown to HTML? For me, it would be a compiler but neither language is a programming one, nor do they have formal semantics. So both our answers miss the point? $\endgroup$
    – Raphael
    Commented Apr 7, 2016 at 19:46
  • $\begingroup$ @Raphael, good question! I probably wouldn't consider that a compiler, but rather would put it under the category of 'using the word loosely is fine as long as everyone will understand what we mean'.. but I have no idea if my usage is objectively correct or represents any kind of consensus. $\endgroup$
    – D.W.
    Commented Apr 7, 2016 at 22:57
  • $\begingroup$ There's also the term "transpiler". $\endgroup$
    – Vilx-
    Commented May 14, 2019 at 17:35
4
$\begingroup$

Say you have two (programming) languages $A$ and $B$. For the sake of simplicity, let the "effect" (output, side effects, ...) of a program be given by a language-specific functions $\operatorname{effect}$. Then, a function $c$ is a compiler from $A$ to $B$ if (and only if)

$\qquad \operatorname{effect}_A(p) = \operatorname{effect}_B(c(p))$

for all $p \in A$.

Note how this is more general than what D.W. proposes: I do not distinguish types of languages; I only require that languages have semantics, i.e. they are designed to compute something. I would call an algorithm that translates regular expressions to finite automata (or vice versa) a compiler, too.

Site note: the existence of compilers between any two Turing-complete languages has been established in computability theory; admissible numberings can be computably converted into one another.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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