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
2 answers

Clang and the default compiler in OS X Lion

In OS X Snow Leopard (10.6) I used the following lines in ~/.bashrc to force compilation with clang instead of standard gcc: # Set Clang as the default compiler for the system export CC=clang export CFLAGS=-Qunused-arguments export…
Bryson
  • 1,186
  • 2
  • 13
  • 26
8
votes
7 answers

What does casting do at compiler/machine level?

I have often wondered what exactly does casting do at compiler or machine level. What does it do with the 0 and 1s in memory? Can anyone point me at some good literature.
uriDium
  • 13,110
  • 20
  • 78
  • 138
8
votes
2 answers

Why are dynamic constructs difficult for php compilers (HPHP)?

I was reading up on Paul Bigger's http://blog.paulbiggar.com/archive/a-rant-about-php-compilers-in-general-and-hiphop-in-particular/ and he mentions that HPHP doesn't fully support dynamic constructs. He then states, "Still, a naive approach is to…
blacktie24
  • 4,985
  • 6
  • 41
  • 52
8
votes
3 answers

What instruction set is used by Tilera microprocessors?

Is there any documentation on this? I'm trying to get a handle on the feasibility of writing a compiler for the Tilera architecture.
8
votes
1 answer

Java compiler tree API - how do I set it up?

I wish to use the Java compiler tree in Eclipse. I have come across the API itself on the Oracle web site here, however I cannot find the JAR file for the library. Am I missing something?!
Joeblackdev
  • 7,217
  • 24
  • 69
  • 106
8
votes
3 answers

C++ - Constructor overloading - private and public

Can you tell me why the following code is giving me the following error - call of overloaded "C(int)" is ambiguous I would think that since C(char x) is private, only the C(float) ctor is visible from outside and that should be called by converting…
Happy-Go-Lucky
8
votes
7 answers

What does it mean when a numeric constant in C/C++ is prefixed with a 0?

Ok... So I had a silly idea and tried putting the value 0123 into an int, just curious to see what would happen, I assumed that when I printed the value I'd get 123, but instead I got 83... Any ideas why? what happens inside the compiler/memory that…
CurtisJC
  • 680
  • 3
  • 9
  • 23
8
votes
1 answer

Is this stack frame I produced right?

For a question paper i'm doing I got a question on stack frames: Consider the following function in Nada (a made up language), the language used in the lectures: function f(x,y) begin var z z := y - x; return z * z; end; Such a function might be…
Mr Teeth
  • 1,269
  • 5
  • 19
  • 23
8
votes
0 answers

Why is x/10 optimized with an unnecessary shift when x has a restricted range?

I have this function long long int divideBy10(long long int a){ return a / 10; } it's compiled to: mov rax, rdi movabs rcx, 7378697629483820647 imul rcx mov rax, rdx shr rax, 63 …
8
votes
1 answer

How do I create mutually callable MethodInfos from MethodBuilders created from LambdaExpressions?

I'm currently working on an compiler in C#, where the behaviour is defined by LambdaExpressions, and then using CompileToMethod, transformed into MethodBuilders and saved to DLL. All functions are public and static. However, I could not find a way…
Kravaros
  • 222
  • 3
  • 8
8
votes
1 answer

Using the DLR for (primarily) static language compilation

I'm building a compiler that targets .NET and I've previously generated CIL directly, but generating DLR trees will make my life a fair amount easier. I'm supporting a few dynamic features, namely runtime function creation and ducktyping, but the…
Serafina Brocious
  • 30,433
  • 12
  • 89
  • 114
8
votes
2 answers

Is it required for me to add a _REENTRANT macro during compile time to make my errno thread safe?

Is it required for me to add a _REENTRANT macro during compile time to make my errno thread safe? If no, is it the case for all versions of gcc / linux / solaris or is it required for certain old versions? I recently tested a piece of code where…
Jay
  • 24,173
  • 25
  • 93
  • 141
8
votes
1 answer

PIC (Position Independedent Code)

Is there any way to check if an object file(.o file) is PIC-enabled?
Raj
  • 4,342
  • 9
  • 40
  • 45
8
votes
2 answers

Sum types - Why in Haskell is `show (Int | Double)` different than `(show Int) | (show Double)`

Why are these not equivalent? show $ if someCondition then someInt else some double and if someCondition then show someInt else show someDouble I understand that if you isolate the if ... else part in the first example to an expression by itself…
8
votes
3 answers

Java compiler API ClassLoader

I am trying to use Java Compiler API to compile some java class. That class imports some packages from the jar files which can be loaded by context ClassLoader, let's call him X, which is NOT the system classloader. When I run the compilation, the…
Pavel S.
  • 11,892
  • 18
  • 75
  • 113