Questions tagged [compiler]

A compiler is a computer program that transforms source code written in one programming language into another computer language.

Filter by
Sorted by
Tagged with
47 votes
5 answers
19k views

When does it make sense to compile my own language to C code first?

When designing an own programming language, when does it make sense to write a converter that takes the source code and converts it to C or C++ code so that I can use an existing compiler like gcc to ...
danijar's user avatar
  • 826
173 votes
11 answers
54k views

Is Ken Thompson's compiler hack still a threat?

Ken Thompson Hack (1984) Ken Thompson outlined a method for corrupting a compiler binary (and other compiled software, like a login script on a *nix system) in 1984. I was curious to know if modern ...
user avatar
32 votes
7 answers
10k views

Interpreted vs Compiled: A useful distinction?

A lot of questions get asked here about interpreted vs compiled language implements. I'm wondering whether the distinction actually makes any sense. (Actually the questions are usually about languages,...
Winston Ewert's user avatar
32 votes
9 answers
9k views

Why are self-hosting compilers considered a rite of passage for new languages?

I've heard in a number of places now that people expect languages to use, or at least have, a self-hosting compiler in order to deserve respect. I'm curious as to why this is. A compiler seems like a ...
Chris Cooper's user avatar
283 votes
7 answers
411k views

How to write a very basic compiler

Advanced compilers like gcc compile code into machine readable files according to the language in which the code has been written (e.g. C, C++, etc). In fact, they interpret the meaning of the code ...
Googlebot's user avatar
  • 3,183
51 votes
5 answers
37k views

How could the first C++ compiler be written in C++?

Stroustrup claims that Cfront, the first C++ compiler, was written in C++ (Stroustrup FAQ). However, how is it even possible that the first C++ compiler be written in C++? The code that makes up the ...
Pacerier's user avatar
  • 4,973
74 votes
5 answers
29k views

Why are there so few C compilers?

C is one of the most widely-used languages in the world. It accounts for a huge proportion of existing code and continues to be used for a vast amount of new code. It's beloved by its users, it's so ...
user avatar
9 votes
2 answers
3k views

How is it possible to write the compiler of a programming language with that language itself [duplicate]

Possible Duplicate: How could the first C++ compiler be written in C++? You probably heard that Microsoft released a new language called TypeScript which is a the typed superset of JavaScript. ...
tugberk's user avatar
  • 994
4 votes
3 answers
541 views

Which components/phases of a JIT compiler are different from a traditional ahead of time compiler?

Besides a faster register allocation algorithm and some trade-off in control and data-flow analysis for optimization purposes, which components/phases of a JIT compiler are different from a ...
Matthias's user avatar
  • 169
82 votes
5 answers
151k views

Is Python Interpreted or Compiled?

This is just a wondering I had while reading about interpreted and compiled languages. Ruby is no doubt an interpreted language since the source code is processed by an interpreter at the point of ...
crodjer's user avatar
  • 1,039
19 votes
4 answers
63k views

How do we go from assembly to machine code(code generation)

Is there an easy way to visualize the step between assembling code to machine code? For example if you open about a binary file in notepad you see a textually formatted representation of machine code....
user12979's user avatar
  • 345
2 votes
3 answers
3k views

Compiler/OS Design - Where to start [closed]

I have a fairly strong background in C and Assembly and I am starting to look into basic compiler and operating systems design, but my biggest problem is where I should really start, seeing as both ...
Jeff Langemeier's user avatar
48 votes
6 answers
15k views

Does an interpreter produce machine code?

I study the topics of compilers and interpreters intensively. I want to check if my base understanding is right, so let's assume the following: I have a language called "Foobish" and its keywords are ...
GrayFox's user avatar
  • 619
17 votes
10 answers
4k views

Compiler Warnings

Many compilers have warning messages to warn the programmers about potential runtime, logic and performance errors, most times, you quickly fix them, but what about unfixable warnings? How do you ...
Ming-Tang's user avatar
  • 856
15 votes
2 answers
5k views

Can and do compilers convert recursive logic to equivalent non-recursive logic?

I've been learning F# and it's starting to influence how I think when I'm programming C#. To that end, I have been using recursion when I feel the result improves readability and I can't envision it ...
Aaron Anodide's user avatar
11 votes
2 answers
623 views

How easy should a language development framework be to use?

This is part of a series of questions which focuses on a project called the Abstraction Project, which aims to abstract the concepts used in language design in the form of a framework. Another ...
Allen Clark Copeland Jr's user avatar
7 votes
1 answer
12k views

Understanding Application binary interface (ABI) [closed]

I am trying to understand the concept of Application binary interface (ABI). From The Linux Kernel Primer: An ABI is a set of conventions that allows a linker to combine separately compiled ...
Tim's user avatar
  • 5,415
5 votes
4 answers
6k views

Can someone provide a short code example of compiler bootstrapping? [closed]

This Turing award lecture by Ken Thompson on topic "Reflections on Trusting Trust" gives good insight about how C compiler was made in C itself. Though I understand the crux, it still hasn't sunk in. ...
Jatin's user avatar
  • 819
3 votes
6 answers
2k views

Should I use a source-to-source or a traditional compiler in order to develop my own Programming Language?

I'm really interested in writing my own general-purpose high-level programming language, but I'm somewhat confused. I know that Python and Ruby were written in C, which makes me wonder that if I want ...
Ericson Willians's user avatar
87 votes
6 answers
18k views

How does garbage collection work in languages which are natively compiled?

After browsing several answers an Stack Overflow, it is clear that some natively compiled languages have garbage collection. But it is unclear to me how exactly this would work. I understand how ...
Christian Dean's user avatar
74 votes
19 answers
13k views

How come compilers are so reliable?

We use compilers on a daily basis as if their correctness is a given, but compilers are programs too, and can potentially contain bugs. I always wondered about this infallible robustness. Have you ...
57 votes
9 answers
44k views

Are Intel compilers really better than the Microsoft ones? [closed]

Years ago, I was surprised when I discovered that Intel sells Visual Studio compatible compilers. I tried it in particular for C/C++ as well as fantastic diagnostic tools. But the code was simply not ...
user avatar
13 votes
3 answers
10k views

Isn't there a chicken-and-egg issue since GCC is written in C++ itself?

Since 4.8 release, the C++ compiler GCC (the G++ part of it) is written not in C anymore, but in C++ itself. I have a hypothetical question on this. I wonder how to compile the C++ code of GCC on a ...
danijar's user avatar
  • 826
12 votes
3 answers
2k views

What are the challenges related to typing in writing a compiler for a dynamically typed language?

In this talk, Guido van Rossum is talking (27:30) about attempts to write a compiler for Python code, commenting on it saying: turns out it's not so easy to write a compiler that maintains all the ...
syntagma's user avatar
  • 309
102 votes
12 answers
37k views

Should I use a parser generator or should I roll my own custom lexer and parser code?

What specific advantages and disadvantages of each way to working on a programming language grammar? Why/When should I roll my own? Why/When should I use a generator?
Maniero's user avatar
  • 10.8k
85 votes
11 answers
23k views

Why is software OS specific?

I'm trying to determine the technical details of why software produced using programming languages for certain operating systems only work with them. It is my understanding that binaries are specific ...
user139929's user avatar
61 votes
14 answers
14k views

Can we make general statements about the performance of interpreted code vs compiled code?

I'm comparing two technologies in order to reach a recommendation for which one should be used by a company. Technology A's code is interpreted while technology B's code is compiled to machine code. ...
EpicSam's user avatar
  • 870
36 votes
3 answers
34k views

Why isn't there a python compiler to native machine code?

As I understand, the cause of the speed difference between compiled languages and python is, that the first compiles code all way to the native machine's code, whereas python compiles to python ...
user2986898's user avatar
30 votes
5 answers
17k views

Are C++ templates just a kind of glorified macros?

From different comparisons among C++ templates and C#/Java generics like this one- https://stackoverflow.com/questions/31693/what-are-the-differences-between-generics-in-c-and-java-and-templates-in-c/...
Gulshan's user avatar
  • 9,412
27 votes
10 answers
4k views

Can compilers and interpreters have bugs, and what can we (as users) do to deal with them? [closed]

If a compiler's work is essentially translating source code into machine level code, can there be any glitch in a compiler, i.e. a faulty "translation?" The same goes for an interpreter: can it fail ...
Witch-King's user avatar
26 votes
2 answers
1k views

What semantic features of Python (and other dynamic languages) contribute to its slowness?

I don't know very well Python. I'm trying to understand more precisely what exact features of dynamic languages (à la Python, Lua, Scheme, Perl, Ruby, ....) are forcing their implementations to be ...
Basile Starynkevitch's user avatar
26 votes
5 answers
25k views

What is the history of the C compiler?

When we say that "Dennis Ritchie developed C language", do we mean that he has created a compiler (using an 'already' developed other language) which can compile the source code written in C language? ...
KawaiKx's user avatar
  • 550
22 votes
3 answers
17k views

Do compilers utilize multithreading for faster compile times?

If I remember my compilers course correctly, the typical compiler has the following simplified outline: A lexical analyzer scans (or calls some scanning function on) the source code character-by-...
8protons's user avatar
  • 1,369
20 votes
2 answers
11k views

What exactly is a compile target?

I keep hearing the term and all google searches lead me to articles on compilers. I just wanna understand what the term compile target means :| UPDATE: To give some context: I've heard it said that ...
BadgerBadgerBadgerBadger's user avatar
20 votes
4 answers
39k views

Writing a lexer in C++

What are good resources on how to write a lexer in C++ (books, tutorials, documents), what are some good techniques and practices? I have looked on the internet and everyone says to use a lexer ...
user avatar
19 votes
2 answers
13k views

How do Java AOT compilers work?

There are a few number of tools out there (Excelsior JET, etc.) that claim to transform Java app's into native executables (*.exe). However it is my understanding that these tools are really just ...
smeeb's user avatar
  • 4,830
15 votes
12 answers
6k views

Are there any compilers that attempt to fix syntax errors on their own? [closed]

I heard a while back that there used to be a compiler that attempted to fix syntax errors by analyzing context and inferring what was intended. Does such a compiler really exist? Obviously it has ...
Nathan Osman's user avatar
15 votes
5 answers
6k views

Why isn't the overloading with return types allowed? (at least in usually used languages)

I don't know about all programming languages, but it's clear that usually the possibility of overloading a method taking into consideration its return type (assuming its arguments are the same number ...
user2638180's user avatar
15 votes
1 answer
4k views

Are there any podcasts (not lectures) about compiler development?

There are several podcasts with lectures from universities. I am looking for "other" podcasts. So are there any non-lecture podcasts about compiler development?
Christian Neverdal's user avatar
15 votes
5 answers
13k views

Compilation to bytecode vs machine code

Does compilation that produces an interim bytecode (like with Java), rather than going "all the way" to machine code, generally involve less complexity (and thus likely take less time)?
Julian A.'s user avatar
  • 253
14 votes
2 answers
8k views

Are (C) object files created with different compilers binary-compatible?

I understand that C++ compilers are not compatible with each other. However, I was unable to find anything on this topic for C in particular. I know that the C standard leaves a lot of room for ...
Doval's user avatar
  • 15.3k
14 votes
3 answers
812 views

How compilers know about other classes and their properties?

I'm writing my first programming language that is object orientated and so far so good with create a single 'class'. But, let's say I want to have to classes, say ClassA and ClassB. Provided these ...
OnResolve's user avatar
  • 421
11 votes
3 answers
8k views

Why does Python need both a compiler and an interpreter?

I can understand the fact that Java needs both a compiler and an interpreter. It compiles source code to bytecode and then a virtual machine (on Windows, on Linux, on Android, etc.) translates that ...
aris's user avatar
  • 119
11 votes
1 answer
1k views

How to use BDD to unit test a compiler?

My team is writing a compiler for a domain-specific language (DSL) which will be integrated into an IDE. Right now, we are focused on the analysis phase of the compiler. We are not using any existing ...
cm007's user avatar
  • 227
11 votes
3 answers
2k views

How is type checked in a dynamic language interpreter/compiler, such as JavaScript?

In dynamic languages, such as JavaScript or Python, the type of a variable is determined at runtime. This is one reason why they are slower than typed languages such as Java. How is type checking ...
user avatar
11 votes
3 answers
2k views

Why do compilers typically only generate executables for the platform they are installed on?

I'm a C++ developer and in an attempt to better understand cross-platform development, I'm trying to get a better understanding of some implementation details of compilers and how exactly they create ...
Jason's user avatar
  • 459
10 votes
4 answers
2k views

Writing a Compiler Compiler - Insight on Use and Features

This is part of a series of questions which focuses on the sister project to the Abstraction Project, which aims to abstract the concepts used in language design in the form of a framework. The ...
10 votes
6 answers
8k views

What is the advantage of learning about and understanding compiler construction?

I'm a undergraduate in my 3rd year of a Software Engineering degree. From this year on, my university has introduced a new course called 'Compiler Constructions', which teaches you the basics of the ...
Nipuna's user avatar
  • 1,306
7 votes
2 answers
774 views

What is the minimum practical definition for the Scheme language?

What is the smallest practical set of primitives that can be used to define the Scheme language? For example, map can be defined as (define (map proc lis) (cond ((null? lis) '()) ...
Robert Harvey's user avatar
6 votes
4 answers
6k views

How can I implement an 'if' statement in an interpreter?

If I were writing a compiler (say for a stack-based VM), the code for an if statement: if (<some_expression>) { <some_instructions> } Would be translated to the following psuedo-...
Aviv Cohn's user avatar
  • 21.2k