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
213
votes
8 answers

Compiling vs Transpiling

While searching about the difference, I came across these definitions: Compiling is the general term for taking source code written in one language and transforming into another. Transpiling is a specific term for taking source code written in one…
Nishi Mahto
  • 2,261
  • 2
  • 10
  • 6
212
votes
14 answers

Parse a .py file, read the AST, modify it, then write back the modified source code

I want to programmatically edit python source code. Basically I want to read a .py file, generate the AST, and then write back the modified python source code (i.e. another .py file). There are ways to parse/compile python source code using standard…
Amandasaurus
  • 58,203
  • 71
  • 188
  • 248
204
votes
4 answers

Reading GHC Core

Core is GHC's intermediate language. Reading Core can help you better understand the performance of your program. Someone asked me for documentation or tutorials on reading Core, but I couldn't find much. What documentation is available for reading…
tibbe
  • 8,809
  • 7
  • 36
  • 64
203
votes
11 answers

"No newline at end of file" compiler warning

What is the reason for the following warning in some C++ compilers? No newline at end of file Why should I have an empty line at the end of a source/header file?
LeChuck2k
201
votes
2 answers

How are GCC and g++ bootstrapped?

This has been bugging me for a while. How do GCC and g++ compile themselves? I'm guessing that every revision gets compiled with a previously built revision. Is this true? And if it is, does it mean that the oldest g++ and GCC versions were written…
user1010005
  • 2,617
  • 5
  • 22
  • 20
197
votes
9 answers

Compiling with g++ using multiple cores

Quick question: what is the compiler flag to allow g++ to spawn multiple instances of itself in order to compile large projects quicker (for example 4 source files at a time for a multi-core CPU)?
bsofman
  • 2,105
  • 2
  • 14
  • 7
193
votes
6 answers

How was the first compiler written?

I heard about the chicken and the egg and bootstrapping. I have a few questions. What wrote the first compiler that converted something into binary instructions? Is assembly compiled or translated into binary instructions? ...I'd find it hard to…
Shawn Mclean
  • 56,733
  • 95
  • 279
  • 406
179
votes
2 answers

What is difference between sjlj vs dwarf vs seh?

I can't find enough information to decide which compiler should I use to compile my project. There are several programs on different computers simulating a process. On Linux, I'm using GCC. Everything is great. I can optimize code, it compiles fast…
sorush-r
  • 10,490
  • 17
  • 89
  • 173
169
votes
4 answers

How does the C# compiler detect COM types?

EDIT: I've written the results up as a blog post. The C# compiler treats COM types somewhat magically. For instance, this statement looks normal... Word.Application app = new Word.Application(); ... until you realise that Application is an…
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
166
votes
6 answers

Why is the .bss segment required?

What I know is that global and static variables are stored in the .data segment, and uninitialized data are in the .bss segment. What I don't understand is why do we have dedicated segment for uninitialized variables? If an uninitialized variable…
Whoami
  • 13,930
  • 19
  • 84
  • 140
164
votes
4 answers

In which language is the C# compiler written?

I looked at the source code at http://referencesource.microsoft.com/, and it appears all the source code is in C#. I also looked at the source code for the new C# compiler platform (Roslyn), and it is also in C#. How is that possible? Is C# language…
CriketerOnSO
  • 2,600
  • 2
  • 15
  • 24
157
votes
9 answers

Can a recursive function be inline?

inline int factorial(int n) { if(!n) return 1; else return n*factorial(n-1); } As I was reading this, found that the above code would lead to "infinite compilation" if not handled by compiler correctly. How does the compiler decide whether…
Ashwin
  • 1,613
  • 2
  • 11
  • 8
145
votes
1 answer

What does the -ObjC linker flag do?

I have an app that works with and without the linker flag. However, without the linker flag, I get a very different behaviour when adding data to a view.
bsarrazin
  • 3,990
  • 2
  • 18
  • 31
144
votes
4 answers

how does array[100] = {0} set the entire array to 0?

How does the compiler fill values in char array[100] = {0};? What's the magic behind it? I wanted to know how internally compiler initializes.
Priyanka Mishra
  • 10,400
  • 18
  • 62
  • 75
141
votes
1 answer

TargetedPatchingOptOut: "Performance critical to inline across NGen image boundaries"?

Been going through some framework classes using reflector and noticed a number of the methods and properties have the following attribute [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")] I'm pretty sure I…
Maxim Gershkovich
  • 45,951
  • 44
  • 147
  • 243