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

Where should I use 'volatile'?

I read about the volatile keyword, but I don't know in what situations I should use it. Is it when the memory (variable) is getting updated and the process is not aware of that? In what cases should drivers use 'volatile' variables?
8
votes
1 answer

How is standard library for programming language implemented?

I have problem understanding how are standard libraries for programming languages, other than C, written. As far as i understand, C standard libraries can be implemented in mixture of C and assembler, where assembler is needed so system calls can be…
8
votes
2 answers

Mono Compiler as a Service (MCS)

I'd like to consume Mono's compiler as a service from my regular .NET 3.5 application. I've downloaded the latest bits (2.6.7), created a simple console application in Visual Studio and referenced the Mono.CSharp dll. Then, in my console app…
Jeff
  • 35,755
  • 15
  • 108
  • 220
8
votes
2 answers

evaluate expression at compile time

I know this has been asked a lot, but only for C/C++ and Java. The question is related to the performance benefits of using constant expressions: When I call a static function with only constants as arguments, is there a way to tell the compiler…
Reinski
  • 153
  • 1
  • 6
8
votes
2 answers

PHP operator precedence bug?

The result of: var_dump(null != $a = 15); var_dump($a); is: bool(true) int(15) Why is this script not triggering an error? Since != (not equal operator) has a higher precedence than = (assignment operator), $a should be compared to null first?
Baptiste Costa
  • 1,044
  • 1
  • 12
  • 24
8
votes
1 answer

Assigning a value to a constant syntax or semantic error?

Is the second line of code considered as a syntax error or a semantic error in C++? int a = 7; 3 = a; In standard C++ context-free grammar I found this statement syntactically valid.
Abdul Rehman
  • 1,687
  • 18
  • 31
8
votes
6 answers

C++ int a[n] working in g++ but not with vs2008

I have the following code: ... int n; cin >> n; int numbers[n]; ... It compiled with NetBeans on Mac using g++ (I think) and it didn't compile using VS2008 on Windows. Why is it so hard to make it work with every compiler? The size of the array is…
gyozo kudor
  • 6,284
  • 10
  • 53
  • 80
8
votes
11 answers

Is C inefficient compared to Assembly?

This is purely a theory question, so, given an "infinite" time to make a trivial program, and an advanced knowledge of C and Assembly, is it really better to do something in Assembly? is "performance" lost when compiling C into Assembly (to machine…
Manux
  • 3,643
  • 4
  • 30
  • 42
8
votes
3 answers

difference between compiler and compiler driver in LLVM?

Can someone explain what is the difference between compiler and compiler driver in LLVM? Any help is appreciated.
flashburn
  • 4,180
  • 7
  • 54
  • 109
8
votes
4 answers

Objective C on Windows or Linux

I would like to learn objective-c, but don't have a Mac. How would I compile obj-c on Windows or Linux? I would prefer Windows, but Linux would be OK.
Joe
  • 181
  • 1
  • 5
8
votes
2 answers

C: Compiler info at runtime

Is there a way to print the name of the compiler and the version that was used to compile a program, something like; printf("This is compiled with %s version %s\n", COMPILER, COMPILER_VERSION); ?
Suugaku
  • 2,667
  • 5
  • 31
  • 33
8
votes
1 answer

Integrating antlr4 with LLVM

I am developing a compiler using ANTLR and LLVM. I have already implemented a lexer and a parser using ANTLR 4's Eclipse IDE. I want to implement a semantic analyzer and a code generator using LLVM. For this I want to know how to integrate the…
NewGirl
  • 101
  • 1
  • 4
8
votes
2 answers

Do most compilers transform % 2 into bit comparison? Is it really faster?

In programming, one often needs to check if a number is odd or even. For that, we usually use: n % 2 == 0 However, my understanding is that the '%' operator actually performs a division and returns its remainder; therefore, for the case above, it…
8
votes
3 answers

Fast Standard ML compiler or bytecode interpreter, with read-eval-print loop, for Linux?

For use with a class I'll be teaching, I'm looking for a fast compiler or bytecode interpreter for Standard ML. I'm looking for fast compile times; any reasonable run time will do. Bonus if the compilation model is simple and clear. Students in…
Norman Ramsey
  • 198,648
  • 61
  • 360
  • 533
8
votes
2 answers

Intentional compiler warnings for Visual C++ that appear in Error List?

How can you create a compiler warning (in the model of #error, except as a warning) on purpose in Visual C++ that will show up on the Error List with the correct file and line number? GCC and other compilers offer #warning, but the MSVC compiler…
1 2 3
99
100