A compiler is a computer program (or set of programs) that transforms source code written in a programming language (the source language) into another computer language (the target language, often having a binary form known as object code). The most common reason for wanting to transform source code is to create an executable program.
Questions tagged [compiler-theory]
201 questions
191
votes
13 answers
Why can't dead code detection be fully solved by a compiler?
The compilers I've been using in C or Java have dead code prevention (warning when a line won't ever be executed). My professor says that this problem can never be fully solved by compilers though. I was wondering why that is. I am not too familiar…

Learner
- 1,667
- 2
- 10
- 10
126
votes
8 answers
What's the difference between parse trees and abstract syntax trees (ASTs)?
Are they generated by different phases of a compiling process? Or are they just different names for the same thing?

Thomson
- 20,586
- 28
- 90
- 134
89
votes
9 answers
What programming languages are context-free?
Or, to be a little more precise: which programming languages are defined by a context-free grammar?
From what I gather C++ is not context-free due to things like macros and templates. My gut tells me that functional languages might be context free,…

n3rd
- 5,989
- 4
- 39
- 56
44
votes
9 answers
(When) Should I learn compilers?
According to this http://steve-yegge.blogspot.com/2007/06/rich-programmer-food.html article, I defnitely should.
Quote Gentle, yet insistent executive
summary: If you don't know how
compilers work, then you don't know
how computers work.…

Peter
- 47,963
- 46
- 132
- 181
36
votes
2 answers
Register allocation and spilling, the easy way?
I'm looking for a way to allocate local variables to registers. I'm aware of a couple of serious methods for doing it (namely, those mentioned on Wikipedia), but I'm stuck on how "spilling" is accomplished. Also, the relevant literature is quite…

Edmund
- 10,533
- 3
- 39
- 57
31
votes
4 answers
Are there such a thing as LL(0) parsers?
I saw a question somewhere asking the difference between LL(0) and LR(0) parsers. Is there such a thing as LL(0) parsers? If so, how do they parse without looking at any token?

Can't Tell
- 313
- 1
- 3
- 4
28
votes
5 answers
How do C compilers implement functions that return large structures?
The return value of a function is usually stored on the stack or in a register. But for a large structure, it has to be on the stack. How much copying has to happen in a real compiler for this code? Or is it optimized away?
For example:
struct Data…

Steve Hanov
- 11,316
- 16
- 62
- 69
27
votes
3 answers
Steps to creating an NFA from a regular expression
I'm having issues 'describing each step' when creating an NFA from a regular expression. The question is as follows:
Convert the following regular expression to a non-deterministic finite-state automaton (NFA), clearly describing the steps of the…

kiliki
- 287
- 1
- 4
- 7
26
votes
3 answers
Scala "<-" for comprehension
I have found that Scala always has a "natural explanation" to anything. Always something like "ohh, but that's just a function being called on this and that object with this and that parameter". In a sense, nothing is really compiler-magic as we…

Felix
- 8,385
- 10
- 40
- 59
24
votes
5 answers
Is there a way to compile C++ to C Code?
I have a program which is configured by the user by using C++ classes and
the same class should be used to configure a program which
can only use a subset of C99 (Open CL Language).
So my question is:
Is there a way to compile C++ to C-Code?
Open…

cl_progger
- 413
- 2
- 6
- 10
21
votes
1 answer
How are Lambda Expressions Translated Into Java Byte Code
I am trying to create an example using lambda expression in java and i am using offical JDK8. My example was run successfully. But when i trying to check how the compiler translate lambda expression into byte code, this makes me some…

Harmeet Singh Taara
- 6,483
- 20
- 73
- 126
19
votes
6 answers
Could C++ have not obviated the pimpl idiom?
As I understand, the pimpl idiom is exists only because C++ forces you to place all the private class members in the header. If the header were to contain only the public interface, theoretically, any change in class implementation would not have…

G S
- 35,511
- 22
- 84
- 118
18
votes
3 answers
What is the reason for the creation of LLVM?
What are the differences between an LLVM and a regular compiler?
Is it more dynamic and thus can be used to compile normally very dynamic languages (i.e. Javascript) into static binary code?
What are the principles behind creating one?
I know the…

the_drow
- 18,571
- 25
- 126
- 193
17
votes
2 answers
SLR(1) Parser and epsilon involved
Let's suppose I have the following grammar:
S → X
X → a | ϵ
If that grammar wouldn't have ϵ involved, I would construct the first state like:
S' → .S
S → .X
X → .a
but what about the ϵ symbol? Should I include:
X → .ϵ
too?
If so... when…

Oscar Mederos
- 29,016
- 22
- 84
- 124
16
votes
4 answers
Efficient way to recursively calculate dominator tree?
I'm using the Lengauer and Tarjan algorithm with path compression to calculate the dominator tree for a graph where there are millions of nodes. The algorithm is quite complex and I have to admit I haven't taken the time to fully understand it, I'm…

Dave Griffiths
- 1,962
- 19
- 22