Questions tagged [compilers]

Questions about programs that read code in one language (source language) and translate it into an equivalent program in another language (target language).

A compiler is a program that transforms source code written in a programming language (the source language) into another language (the target language).

Example: A C++ compiler transforms your C++ code into equivalent Assembly Language or Machine Code.

A rough sketch of working of compilers

Source Program (or Code) → Compiler → Target Program (or executable code)


Compilers are more generally used to translate high-level code (like C#, C++, Java) into low level or machine code.

672 questions
193
votes
10 answers

How can a language whose compiler is written in C ever be faster than C?

Taking a look at Julia's webpage, you can see some benchmarks of several languages across several algorithms (timings shown below). How can a language with a compiler originally written in C, outperform C code? Figure: benchmark times relative to…
StrugglingProgrammer
  • 1,973
  • 3
  • 12
  • 10
94
votes
7 answers

Why are some programming languages "faster" or "slower" than others?

I have noticed that some applications or algorithms that are built on a programming language, say C++/Rust run faster or snappier than those built on say, Java/Node.js, running on the same machine. I have a few question regarding this: Why does…
evil_potato
  • 1,372
  • 2
  • 12
  • 11
74
votes
9 answers

What properties of a programming language make compilation impossible?

Question: "Certain properties of a programming language may require that the only way to get the code written in it be executed is by interpretation. In other words, compilation to a native machine code of a traditional CPU is not possible. What are…
69
votes
10 answers

Can a dynamic language like Ruby/Python reach C/C++ like performance?

I wonder if it is possible to build compilers for dynamic languages like Ruby to have similar and comparable performance to C/C++? From what I understand about compilers, take Ruby for instance, compiling Ruby code can't ever be efficient because…
Ichiro
  • 815
  • 1
  • 7
  • 5
69
votes
12 answers

Why don't compilers automatically insert deallocations?

In languages like C, the programmer is expected to insert calls to free. Why doesn't the compiler do this automatically? Humans do it in a reasonable amount of time(ignoring bugs), so it is not impossible. EDIT: For future reference, here is another…
Milton Silva
  • 845
  • 1
  • 7
  • 8
57
votes
4 answers

Time complexity of a compiler

I am interested in the time complexity of a compiler. Clearly this is a very complicated question as there are many compilers, compiler options and variables to consider. Specifically, I am interested in LLVM but would be interested in any thoughts…
superbriggs
  • 695
  • 5
  • 6
41
votes
8 answers

What determines the "speed" of a programming language?

Suppose a program was written in two distinct languages, let them be language X and language Y, if their compilers generate the same byte code, why I should use language X instead of the language Y? What defines that one language is faster than…
Rodrigo Valente
  • 549
  • 1
  • 4
  • 7
34
votes
5 answers

How do computers remember where they store things?

When a computer stores a variable, when a program needs to get the variable's value, how does the computer know where to look in memory for that variable's value?
MCMastery
  • 451
  • 1
  • 4
  • 6
32
votes
5 answers

Proof that dead code cannot be detected by compilers

I'm planning to teach a winter course on a varying number of topics, one of which is going to be compilers. Now, I came across this problem while thinking of assignments to give throughout the quarter, but it has me stumped so I might use it as an…
thomas
  • 421
  • 4
  • 3
31
votes
6 answers

Why are ambiguous grammars bad?

I understand that if there exist 2 or more left or right derivation trees, then the grammar is ambiguous, but I am unable to understand why it is so bad that everyone wants to get rid of it.
Turing101
  • 1,230
  • 2
  • 16
  • 32
29
votes
2 answers

What is a batch compiler?

I have the following quotation from my compiler's course (in the context of graph coloring): Because it is slow, graph coloring tends to be used in batch compilers, while linear scan tends to be used in JIT compilers. I couldn't find a clear…
user1868607
  • 2,224
  • 14
  • 23
29
votes
6 answers

Are there programs that can 'translate' source code between any two languages?

Are there programs that can 'translate' source code between any two languages (assuming the translator has access to the requisite libraries)? If there are, how do they work (techniques used, knowledge required, etc)? How would they feasibly be…
Tobi Alafin
  • 1,647
  • 4
  • 17
  • 22
24
votes
4 answers

Why is left recursion bad?

In compiler design, why should left recursion be eliminated in grammars? I am reading that it is because it can cause an infinite recursion, but is it not true for a right recursive grammar as well?
user56833
24
votes
2 answers

Why is static-single assignment preferred over continuation passing style in many industry-used compilers?

According to the Wikipedia page on static-single assignment (SSA), SSA is used by large and well-known projects such as LLVM, GCC, MSVC, Mono, Dalvik, SpiderMonkey, and V8 while the page on projects using continuation-passing style (CPS) is a bit…
CinchBlue
  • 614
  • 4
  • 16
23
votes
11 answers

Would it be wrong to say that the processor (and hardware) is the implementation of an interpreter for machine language?

The question is basically in the title. I know that a computers hardware is of course some physical object, where as the interpreter is some abstract thing that does something abstract with the code it is given. Yet, can we say that the way the…
1
2 3
44 45