Questions tagged [compiler-theory]

A compiler is a computer program (or set of programs) that transforms source code written in a programming language (the source language) into another computer language (the target language, often having a binary form known as object code). The most common reason for wanting to transform source code is to create an executable program.

200 questions
9
votes
3 answers

complexity of parsing C++

Out of curiosity, I was wondering what were some "theoretical" results about parsing C++. Let n be the size of my project (in LOC, for example, but since we'll deal with big-O it's not very important) Is C++ parsed in O(n) ? If not, what's the…
Cpa
  • 293
  • 1
  • 2
  • 6
9
votes
8 answers

Why can't the compiler just compile my code as I type it?

Why can't the compiler just compile my code as I type it? From the user's point of view, it could work as smoothly as syntax colouring does today. If you stop typing for long enough (maybe a couple of seconds) the compilation (not linking) would…
Rocketmagnet
  • 4,787
  • 7
  • 30
  • 43
9
votes
6 answers

What are the key design choices to make a wicked fast compiler?

I want to know how to design a compiler that compiles very, very quickly. First, let me head off some obvious misunderstandings of my question: I am not talking about the speed of the code produced by the compiler. There are already many resources…
Thom Boyer
  • 497
  • 2
  • 12
8
votes
1 answer

Which programming languages have a regular grammar?

I'm curious about which (if any) real-world programming languages have a regular grammar (i.e. the set of all syntactically correct programs is regular). See also this question: What programming languages are context-free?.
Giovanni Funchal
  • 8,295
  • 12
  • 54
  • 103
8
votes
7 answers

Example compilers

I'm searching for the source code of a compiler capable of creating Win32 programs from an input program in a programming language (It doesn't matter which, maybe the simpler the better) Yet I can't find anything right for me and huge compilers like…
saf
  • 99
  • 1
8
votes
1 answer

Code generation for expressions with fixed/preassigned register

I'm using this (see below) algorithm(take idea from this answer) to code generation from a tree. I'm targeting x86 arch, now I need to deal with mul/div instructions which uses registers eax/ebx as argument. My question is: How do I modify this to…
The Mask
  • 15,697
  • 36
  • 104
  • 172
8
votes
2 answers

Unit testing a compiler

What is considered the best approach to unit test a complex unit such as a compiler? I've written a few compilers and interpreters over the years, and I do find this kind of code quite hard to test in a good way. If we take something like the…
Roger Johansson
  • 20,991
  • 14
  • 87
  • 174
8
votes
5 answers

What language features are required in a programming language to make a compiler?

Programming languages seem to go through several stages. Firstly, someone dreams up a new language, Foo Language. The compiler/interpreter is written in another language, usually C or some other low level language. At some point, FooL matures and…
Matthew Scharley
  • 115,776
  • 51
  • 189
  • 215
8
votes
2 answers

What is an Abstract Syntax Tree/Is it needed?

I've been interested in compiler/interpreter design/implementation for as long as I've been programming (only 5 years now) and it's always seemed like the "magic" behind the scenes that nobody really talks about (I know of at least 2 forums for…
7
votes
3 answers

How to make a Side-by-Side Compiler for .NET

Nikhil Kothari's Script# is quite possibly one of the most amazing concepts I've seen in the JavaScript arena for quite some time. This question isn't about JavaScript, but rather about language compilation in the .NET runtime. I've been rather…
TheXenocide
  • 978
  • 6
  • 19
7
votes
1 answer

Putting nodes into the parse tree which shouldn't be there

I am writing a parser for a language, and the scanner is designed to either also return unneeded terminals (e.g. whitespacing) OR not to do so based on a boolean flag. Now, in the parser, I don't want to clutter the grammar with all those…
Flavius
  • 12,501
  • 13
  • 76
  • 118
7
votes
5 answers

Why are C and C++ different even after compilation?

I guessed it but was still surprised to see that the output of these two programs, written in C and C++, when compiled were very different. That makes me think that the concept of objects still exist at even the lowest level. Does this add overhead?…
ArturPhilibin
  • 902
  • 2
  • 12
  • 25
7
votes
2 answers

Inlining Algorithm

Does anyone know of any papers discussion inlining algorithms? And closely related, the relationship of parent-child graph to call graph. Background: I have a compiler written in Ocaml which aggressively inlines functions, primarily as a result of…
7
votes
1 answer

What is the precise definition of a lookahead set?

I'm toying around with writing compilers and learning about the theory behind syntax analysis. I've found that even though it's a key concept for understanding recognition algorithms, information about it on the net is fairly poor. It seems…
Lyudmil
  • 1,153
  • 2
  • 13
  • 21
7
votes
4 answers

Compilation vs translation, "compiling" Java to bytecode?

My understanding is like this, definitions: Translation - having code in some language, generating code in some other language. Compilaton - translation to a machine code. Machine code - direct instructions for CPU. Now, from docs.oracle.com: javac…
Adam Stelmaszczyk
  • 18,835
  • 4
  • 63
  • 104
1 2
3
13 14