Questions tagged [compiler-theory]

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.

200 questions
193
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,677
  • 2
  • 8
  • 10
95
votes
5 answers

What's the difference between parse tree and AST?

Are they generated by different phases of a compiling process? Or are they just different names for the same thing?
74
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,669
  • 4
  • 35
  • 55
39
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
  • 44,153
  • 43
  • 129
  • 175
33
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,070
  • 1
  • 36
  • 52
31
votes
12 answers

Learning Resources on Parsers, Interpreters, and Compilers

I've been wanting to play around with writing my own language for a while now (ostensibly for the learning experience) and as such need to be relatively grounded in the construction of Parsers, Interpreters, and Compilers. So: Does anyone know of…
28
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
  • 283
  • 1
  • 3
  • 4
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
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
  • 10,263
  • 15
  • 56
  • 63
25
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
  • 7,999
  • 10
  • 37
  • 58
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
  • 405
  • 2
  • 5
  • 10
21
votes
1 answer

How Lambda Expressions Are Translate In 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
  • 5,855
  • 16
  • 64
  • 119
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…
Frederick The Fool
  • 31,355
  • 20
  • 78
  • 112
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
  • 17,134
  • 23
  • 116
  • 185
16
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
  • 26,873
  • 20
  • 76
  • 120
1
2 3
13 14