Questions tagged [compilers]
Compilers are implementations of programming languages which convert source code into another format, such as a binary executable, bytecode, or another programming language. Use this tag for questions about the design or implementation of compilers. This contrasts with interpreters, which execute source code directly.
86 questions
1
vote
2
answers
210
views
How can I design a simple programming language from scratch? [closed]
want to design a simple programming language for educational purposes.
My goal is to understand the fundamentals of how a language works — defining syntax, grammar, and how code gets executed (...
3
votes
1
answer
486
views
How are C11 compilers calculating by how much to change the stack pointer before `goto` if the program uses variable-length arrays?
So, obviously, the C compiler, when compiling gotos, before inserting the jump instruction, needs to insert ...
2
votes
1
answer
159
views
Making datatypes for a programming language to translate (or compile) to an esoteric language
I'm making an "assembly language" called X that compiles from X to an esoteric language Y, but I encountered some problems with the data types for the variables.
I currently have three data ...
18
votes
4
answers
4k
views
What is the difference between a compiler "frontend" and "backend"?
I've seen the terms "frontend" and "backend" thrown around for compilers, but never got their precise meaning. I get that frontend encompasses parsing, and backend includes code ...
6
votes
0
answers
153
views
Function call in single pass compiler for B
I've been implementing a B compiler for x86 assembly for a while now and have been asking one or two questions in Retrocomputing.
My tools for implementing it is using flex/bison with C.
Recently I've ...
0
votes
1
answer
498
views
Are there any programming languages that operate solely via side-effects?
Out of curiosity I checked how Google AI would respond to a similar question. The bot seemed clever enough to understand the question, but responded that functions in this case would have no return ...
82
votes
2
answers
32k
views
How do modern compilers choose which variables to put in registers?
C has the register keyword, originally designed as a hint to the compiler that a variable should be placed in a register rather than on the stack. However this is ...
2
votes
2
answers
354
views
How does the GNU Assembler deal with the directives for changing the syntax from AT&T to Intel or vice versa if those directives are in if-branching?
GNU Assembler, when targetting x86, has directives .att_syntax and .intel_syntax for switching between Intel Syntax and AT&T ...
0
votes
1
answer
429
views
How might I implement a `typeid` operator (returning the type of its argument as something, presumably as a string) in my compiler?
So, here is how strings work in my AEC-to-WebAssembly compiler. After the program is parsed, all strings except inline assembly ones are gathered in a C++ ...
6
votes
3
answers
617
views
What design choices inform whether a whole-program optimizing compiler is possible?
What design restrictions inform a language having / having a useful whole-program optimizing compiler?
I'm aware that Standard ML has a whole-program optimizing compiler implementation in MLton. I ...
2
votes
1
answer
335
views
Handling two different ways to write `else if`?
In Universities, students spend a lot of time correcting syntax errors.
For purposes of a thought experiment, suppose that a new language was developed that supported multiple syntaxi.
For a simple ...
16
votes
7
answers
6k
views
How is clang able to evaluate loops without getting stuck in an infinite loop?
I recently saw this tweet.
And for posterity, this is the C++ code:
...
3
votes
3
answers
672
views
What to do when registers are used up in a register based VM?
I have some experience in writing stack based VM's and am now thinking about implementing an interpreter based on registers. I have not yet started anything and the project is still in planning phase. ...
50
votes
5
answers
18k
views
What are the ways compilers recognize complex patterns?
This answer is an example of a compiler recognizing that a complex expression is equivalent to a single operation:
...
5
votes
0
answers
162
views
SSA Construction: DFS of CFG vs Traversal of Dominator Tree
According to Engineering a Compiler Cooper, K. and Torczon, L. the SSA transformation algorithm is divided into two parts
Inserting $\phi$ functions. For each existing definition of a variable ...