Questions tagged [compiler-construction]

The tag compiler-construction should be applied to questions concerning the programming of compilers or for questions about the detailed inner workings of compilers. DO NOT USE for questions about *using* specific compilers or compilation errors.

A compiler is a program which translates one language into another. Compiler construction is the process of creating a compiler.

The tag should be applied to questions concerning the programming of compilers or for questions about the detailed inner workings of compilers.

One language to another? I thought they made executables!

Few compilers do exactly that:

  • They mostly translate a human readable computer programming language (like Fortran, Cobol, Algol, PL/1, Pascal, C, C++, C#, etc.) into an object-code file which has to be subsequently linked.

  • Many real world compilers translate a high level language into assembly code which is subsequently assembled by a separate program and then linked.

  • The standard Java compiler translate Java code into JVM bytecode, which must be run by a dedicated program (the JVM) which may include a Just In Time (JIT) or HotSpot compiler that translates the bytecode into native machine instructions on the fly.
  • Early versions of Unix came with a Fortran-to-C compiler.
  • The earliest versions of the language that became C++ were compiled into C by a program called cfront.
  • Many other examples of source-to-source compilers exist.
  • Some languages such as JavaScript and many other 'scripting' languages don't have compilers at all, but are executed directly from source code.

Big List of Resources:

11618 questions
8
votes
6 answers

Interpreters and Dynamically Typed Languages

Why are programs that have dynamically typed languages usually interpreted rather than compiled?
8
votes
3 answers

What should I learn first before heading to C++?

I'm learning C, but after that or in the meanwhile, what should I learn first and subsequently before getting into C++ ? Compilers, Data Structures, UML or Design Patterns ?(also when start to learn Win32 API ?) I'm not in a hurry at all, so I can…
8
votes
1 answer

vtable: Underlying algorithm

My understanding of vtables is that, if I have a class Cat with a virtual function speak() with subclasses Lion and HouseCat, there is a vtable which maps speak() to the correct implementation for each Subclass. So a call cat.speak() Compiles…
Alex
  • 871
  • 7
  • 23
8
votes
3 answers

In Rust, is Option compiled to a runtime check or an instruction jump?

In Rust, Option is defined as: pub enum Option { None, Some(T), } Used like so: fn may_return_none() -> Option { if is_full_moon { None } else { Some(1) } } fn main() { let optional =…
Dai
  • 141,631
  • 28
  • 261
  • 374
8
votes
2 answers

Why does VC++ 2010 compiler crash when compiling simple code?

I encountered a very strange symptom. Who can tell me what the root cause is? My VC++ compiler version is latest: "Microsoft Visual C++ 2010 : 01019-532-2002102-70860" Steps to reproduce: Create an empty win32 console project Add a new cpp file…
xmllmx
  • 39,765
  • 26
  • 162
  • 323
8
votes
4 answers

Does it ever make sense for a compiler to pass a structure like this in a cpu register to a function?

I'd like to know if some kind of structure contains more than one primitive but its total size is less than or equal to size of a single cpu register like a 4-byte register, does it ever make sense for a compiler to put it in one of those 4-byte…
Pooria
  • 2,017
  • 1
  • 19
  • 37
8
votes
2 answers

What is the principle of "Time Travel Debugger"?

Hmm... My teacher, some of my classmates and I are going to build a Debugger project. We hope that our debugger is interactive, that is, when codes are typed in, the result will be displayed somewhere few seconds later, and the result changes while…
Stephen.W
  • 1,649
  • 13
  • 14
8
votes
1 answer

g++ how to check if it supports lambda functions?

So much talk about lambda functions... So I tried to write mine. :(. It did not work. Does g++ 4.3.2 support lambda functions? How to find out whether it supports a certain c++0x feature or not?
nakiya
  • 14,063
  • 21
  • 79
  • 118
8
votes
2 answers

How does the compiler know which catch block to take?

Suppose I have the following two files, main.cpp: #include class A {}; void foo(); int main(void) { try { foo(); } catch(const A& e) { std::cout << "Caught an A." << std::endl; } return 0; } and…
Witiko
  • 3,167
  • 3
  • 25
  • 43
8
votes
5 answers

Is there a library that can compile C++ or C

I came here to ask this question because this site has been very useful to me in the past, seems to have very knowledgeable users who are willing to discuss a question even if it is metaphysical at times. And also because googling it did not…
640KB
  • 91
  • 2
8
votes
1 answer

Left Associativity vs Left Recursion

I'm trying to write a compiler for C (simpler grammar though). There is something that I've been stuck on for a while. If I understated correctly, all binary operations are left associative. So if we have we "x+y+z", x+y occurs first and then…
Babak
  • 497
  • 1
  • 7
  • 15
8
votes
2 answers

Binding against LLVM 3.8.4 no getGlobalContext

I am attempting to follow the https://github.com/lsegal/my_toy_compiler, but even though it has been updated for LLVM 3.8.0, I am unable to get it to compile using LLVM 3.8.4 from brew with --with-clang --with-lld --with-jit --with-python.…
Mobius
  • 2,871
  • 1
  • 19
  • 29
8
votes
6 answers

Using adaptive grammars

I'm trying to implement a language (or family of languages) whose grammar can be changed dynamically. I have found no examples that serve as study cases. Can you give me some reference to any that are actually used in the real world (even from the…
amorales
  • 317
  • 3
  • 13
8
votes
1 answer

How is match implemented in a language like Rust?

I'm not a functional programmer. So I'm not very familiar with pattern matching, patterns, or any of that stuff. To me I only understand the concept of the good old switch statement. How would a compiler implement a match statement? What exactly is…
Jon Flow
  • 495
  • 3
  • 11
8
votes
1 answer

Relationship between LR(0), LL(0), LALR(1), etc?

I'm really struggling to unterstand the relationship between: LR(0) LL(0) LALR(1) SLR(1) LR(1) LL(1) I'm pretty sure LALR(1) and SLR(1) are subsets of LR(1), but I'm lost about the others. Are they all exclusive? Is LL(0) a subset of…