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
135
votes
4 answers

How many GCC optimization levels are there?

How many GCC optimization levels are there? I tried gcc -O1, gcc -O2, gcc -O3, and gcc -O4 If I use a really large number, it won't work. However, I have tried gcc -O100 and it compiled. How many optimization levels are there?
neuromancer
  • 53,769
  • 78
  • 166
  • 223
133
votes
22 answers

C compiler for Windows?

I'm fine working on Linux using gcc as my C compiler but would like a Windows solution. Any ideas? I've looked at Dev-C++ from Bloodshed but looking for more options.
mario64
  • 1,517
  • 3
  • 12
  • 12
130
votes
4 answers

error: writable atomic property cannot pair a synthesized setter/getter with a user defined setter/getter

I recently tried to compile an older Xcode project (which used to compile just fine), and now I'm seeing a lot of errors of this form: error: writable atomic property 'someProperty' cannot pair a synthesized setter/getter with a user defined…
e.James
  • 116,942
  • 41
  • 177
  • 214
128
votes
3 answers

How to create a static library with g++?

Can someone please tell me how to create a static library from a .cpp and a .hpp file? Do I need to create the .o and the .a? I would also like to know how can I compile a static library in and use it in other .cpp code. I have header.cpp,…
linuxx
  • 1,487
  • 4
  • 16
  • 17
126
votes
8 answers

What's the difference between parse trees and abstract syntax trees (ASTs)?

Are they generated by different phases of a compiling process? Or are they just different names for the same thing?
124
votes
8 answers

Qt: can't find -lGL error

I just reinstalled QtCreator, created new project (Qt Application) an got this after compilation: /usr/bin/ld: **cannot find -lGL** collect2: error: ld returned 1 exit status make: *** [untitled1] Error 1 18:07:41: The process "/usr/bin/make"…
Hofmn
  • 1,343
  • 2
  • 9
  • 4
123
votes
13 answers

How to drive C#, C++ or Java compiler to compute 1+2+3+...+1000 at compile time?

In a recent interview, I was asked a really strange question. The interviewer asked me how can I compute 1+2+3+...+1000 just using compiler features. This means that I am not allowed to write a program and execute it, but I should just write a…
TonySalimi
  • 8,257
  • 4
  • 33
  • 62
121
votes
14 answers

What is compiler, linker, loader?

I wanted to know in depth meaning and working of compiler, linker and loader. With reference to any language preferably c++.
Sachin
  • 1,283
  • 3
  • 9
  • 4
119
votes
1 answer

Where to learn about VS debugger 'magic names'

If you've ever used Reflector, you probably noticed that the C# compiler generates types, methods, fields, and local variables, that deserve 'special' display by the debugger. For instance, local variables beginning with 'CS$' are not displayed to…
Gael Fraiteur
  • 6,759
  • 2
  • 24
  • 31
113
votes
4 answers

Meaning of Android Studio error: Not annotated parameter overrides @NonNull parameter

I'm trying out Android Studio. Upon creating a new project and adding a default onSaveInstanceState method to the create MyActivity class, when I try to commit the code to Git, I get a strange error I don't understand. The code is this: The error I…
Monomo
  • 1,193
  • 2
  • 7
  • 5
112
votes
14 answers

What is the difference between a token and a lexeme?

In Compiler Construction by Aho Ullman and Sethi, it is given that the input string of characters of the source program are divided into sequence of characters that have a logical meaning, and are known as tokens and lexemes are sequences that make…
user1707873
  • 1,307
  • 2
  • 10
  • 10
110
votes
9 answers

What is the difference between LR, SLR, and LALR parsers?

What is the actual difference between LR, SLR, and LALR parsers? I know that SLR and LALR are types of LR parsers, but what is the actual difference as far as their parsing tables are concerned? And how to show whether a grammar is LR, SLR, or LALR?…
Prasoon Saurav
  • 91,295
  • 49
  • 239
  • 345
107
votes
5 answers

Eclipse: enable assertions

I'm running Eclipse Galileo. How do I enable assertions in Eclipse? As suggested by other sites, I've tried adding the arguments: -ea. I have also tried changing the compiler compliance level to 1.4. Neither of those suggestions worked.
well actually
  • 11,810
  • 19
  • 52
  • 70
107
votes
6 answers

(A + B + C) ≠ (A + C + B​) and compiler reordering

Adding two 32-bit integers can result an integer overflow: uint64_t u64_z = u32_x + u32_y; This overflow can be avoided if one of the 32-bit integers is first casted or added to a 64-bit integer. uint64_t u64_z = u32_x + u64_a + u32_y; However, if…
Tal
  • 1,759
  • 1
  • 12
  • 22
105
votes
13 answers

Why is it impossible to build a compiler that can determine if a C++ function will change the value of a particular variable?

I read this line in a book: It is provably impossible to build a compiler that can actually determine whether or not a C++ function will change the value of a particular variable. The paragraph was talking about why the compiler is…
Cricketer
  • 2,391
  • 4
  • 24
  • 29