Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

Questions tagged [compiler]

A compiler is a computer program that transforms source code written in one programming language into another computer language.

1
vote
2answers
138 views

What are the bottlenecks for the Java build speed?

Which underlying system parameters have most influence on how fast a typical Java project (say dozens of classes and dependencies) builds? There is a lot information on JIT (bytecode to CPU ...
2
votes
2answers
208 views

What is the difference between a static library and an archive library?

In the comments of a recent answer, I equated a static library with an archive of compiled object files. The response was that they are not the same, so what is the difference? To clarify - gcc ...
1
vote
1answer
61 views

How function parameters are compiled in JavaScript

I am trying to understand how functions -- which could have dozens of parameters that could themselves be functions or complex objects (I'm thinking JavaScript) -- get passed the arguments when ...
0
votes
3answers
59 views

Resolving function calls as function arguments using a stack

After doing a bit of reading, I have a vague understanding of the use of a stack in calling functions when one function calls another, where the arguments are placed on the stack for the called ...
-1
votes
2answers
138 views

Relationship between the C standard libraries and Java standard libraries

Which is the relationship between the standard libraries of C language and the standard libraries of other software platforms, e.g. Java, .NET, Python? Do the Java (.NET and Python) standard libraries ...
4
votes
2answers
202 views

How can one interpret an Abstract Syntax Tree without recursion?

I am busy building an interpreter for a Rebol-like language. I have previously built a Lisp interpreter where I used recursion, but now I just want to use a stack and not rely on the recursion ...
3
votes
3answers
357 views

How does a compiler work when it's not directly compiling to machine code

I know the compilation process goes with this flow: source -> parse -> AST -> intermediate code -> assembly -> machine code and in the case of Java you will have bytecode which is ...
-1
votes
1answer
114 views

What happens when loops are compiled or interpreted?

I have came across a concept in recursion which says that when loops are compiled or interpreted then they get converted to recursive functions. If it is true how it takes place ?
3
votes
3answers
241 views

In c++, is there a way inside a function block, to execute cleanup code after the value has been returned?

Backstory (You can skip) I am building an API for managing Files and Directories in a consistent manner across a project. This is for deduplication and consistency when performing a task, and in this ...
0
votes
4answers
136 views

Is it better to use the linker to compile multiple C++ files or better to include them as a header file

Assume we have two files a.cc #include <iostream> int timesTwo(int in); int main(){ std::cout << timesTwo(5) << std::endl; return 0; } b.cc int timesTwo(int in){ return in*2;...
2
votes
3answers
349 views

GCC or Clang to output bytecode for a VM?

Long story short, I wanted to use C as a scripting language and in a portable manner so I created a register-based, JITless VM to accomplish this. I've formalized the VM's ISA, script file format, ...
0
votes
0answers
58 views

Results of testing different compiler optimizations of GNU GCC are confusing

I tested out a few different compiler optimizations on GNU GCC, in the CodeBlocks IDE. With each different optimization I ran the same test: I let my program try to build as big of a tree as it could ...
0
votes
1answer
112 views

Is there a way to use and ignore blocks of code, caused by events during runtime?

I'm working in C++14 and trying to figure out a way to put two classes (with the same name) inside the same header file. In this scenario one class would always be ignored as a result of something ...
4
votes
3answers
424 views

How to optimize a mixed stack/register bytecode with control flow and side effects?

I'm trying to figure out a technique to optimize bytecode for the following virtual machine: Bytecode is a flat list of instructions, with execution starting from the first instruction. Stack ...
0
votes
4answers
162 views

Should my lexer allow what is obviously a syntax error?

This is kinda like a concrete version of the question Coming up with tokens for a lexer. I'm writing a lexer for a small subset of HTML. I'm wondering what should I do when the input stream ends and ...
-5
votes
1answer
53 views

LL(K) grammer generation for postfix expressions [closed]

I have a problem in formulating LL(K) grammar for this postfix expression problem, given (4 3 / 2 * 4 5 / +) as an input must output 52/12
5
votes
3answers
283 views

Does the output of a compiler depend on the OS you are using?

In the company I am working in we have a management software, written by an external programmer. Let's call the software PK. PK was initially written in the 90s using C++. Since then it was regularely ...
0
votes
2answers
260 views

Understanding Context Free Grammar using a simple C code

I'm trying to understand the difference between terminal and non-terminal values in a real language. I wasn't able to find enough examples on real language CFGs on the internet, most examples are ...
-2
votes
1answer
118 views

What is the minimum set of operations a language implementation must provide for it to be usable for all applications?

As a fun hobby project, I'm writing a simple bytecode VM and a compiler from a basic high-level language to the said bytecode. (Offtopic: the compiler is inspired by Jack Crenshaw's awesome tutorial -...
-6
votes
1answer
190 views

Why does the C compiler use memory for simple arithmetic operations

Assume the following C code: #include <stdio.h> int main() { int a = 5; int b = 15; return a + b; } Compiling it using gcc creates an assembly code which includes the following: ...
-4
votes
1answer
39 views

Writing an application that calls another application for some tasks: how it works?

I have written a C++ code that calls a solver called CPLEX to solve an integer linear optimization problem (under Ubuntu 18.04). I have three sets of data and I use make command to create 3 ...
3
votes
1answer
487 views

Why am I advised to not inline functions that are called only once?

I understand inlining as the following: A separate function which is marked as "inline" (assuming the compiler really does inline) will be "merged" into the function it is called. i.e. (pseudo code)...
1
vote
1answer
182 views

Is it feasible to write an IR-to-assembly compiler as opposed to an LLVM backend?

I've made a virtual processor with a simple instruction set and memory model as a learning exercise (and mostly just for fun). I can write programs in its assembly language, assemble them with my ...
0
votes
2answers
189 views

How does Gamemaker Create Executables?

How does a Program that is already compiled create standalone .exe files without an apparent compiler? Example game making software like GameMaker that lets you create a game, add all the resources, ...
2
votes
1answer
186 views

What is the difference between writing in assembly vs converting high level language into assembly using compiler?

So i heard that in modern operating systems and device drivers, some parts of them are still written in assembly for better memory optimisation and speed but do developers actually write it in ...
0
votes
2answers
221 views

How can I test generated assembly?

I'm working on a C compiler for Linux for the purpose of personal curiosity/fun. How can I test the generated assembly before the compiler is complete enough to do anything useful? For example, if I ...
0
votes
2answers
223 views

Why don't variables in TypeScript implicitly infer literal typing?

Given a literal type, for instance 1 | 2, assigning a value to a variable that correctly corresponds to the literal type will fail. interface SomeInterface { foo: (1 | 2); } class SomeClass ...
1
vote
1answer
288 views

Would Cython-like “Cypescript” be a feasible idea?

Cython is a superset of Python that can be complied into C modules that can be imported and used normally in Python code. This can be used to speed up parts of a Python program. In a recent project, I ...
0
votes
1answer
187 views

What does the 'emulation' do in the Linker?

I am looking into assembler and I am trying to understand the whole compilation process. During the linking step I use: ld -m elf_i386 -s -o hello hello.o Everything works fine, but I do not ...
1
vote
3answers
416 views

Does the Perfect Compiler trump source differences

Is it theoretically possible to create a perfect compiler for a language (for example C) meaning that if two different persons make two different implementations of the same algorithm then the ...
8
votes
2answers
517 views

Only one number type in language design

I am currently learning about compiler construction and language design and I am thinking about what native datatypes I want to support in my language. Now there is a whole lot of languages that make ...
10
votes
2answers
366 views

Why does Forth's flexibility make a grammar inappropriate for it?

I've recently undertaken the task of writing a stack-based programming language. Before I started designing my language however, I thought it'd be a good idea to read and experiment with existing ...
0
votes
1answer
279 views

AST design: Call is both expression and statement?

I'm designing the AST for a compiler and found that I don't actually know how to represent the Call node. Currently, the relevant part of the AST looks like this (where the arrows denote inheritance):...
2
votes
1answer
203 views

Whole-program optimization

I just asked about the Polyhedral Model, and have looked into other compiler optimizations (Loop unrolling, Constant folding and propagation, Dead code elimination etc.). But I haven't seen anything ...
2
votes
4answers
562 views

Why use Java as a server-side language over an interpreted language?

Web pages are usually tested by refreshing the page, clicking some UI component, then either writing to a debug log or adding some breakpoints in the IDE... in larger applications, unit tests are ...
5
votes
0answers
117 views

Why does GHC represent recursion in Haskell with recursive binders instead of a fixpoint operator?

GHC's Core data type represents recursion with recursive binders in the Let constructor; as I understand it, all let expressions in Haskell are effectively let rec expressions. Why does GHC use this ...
2
votes
1answer
68 views

Rough explanation of Control-Flow Graph navigation algorithm

Wondering at a high level how you are supposed to go about navigating a Control-Flow Graph (CFG) to perform operations such as dead code elimination. This diagram shows a dead-code elimination problem,...
3
votes
1answer
51 views

Compiler Optimizations before IR/CFG phase

I understand Control-Flow Graph (CFG) optimizations and that they typically operate on SSA Intermediate Representations (IR). I am wondering though if the compiler optimizes the AST in any way before ...
4
votes
1answer
171 views

Circular dependency problem

"Single item in a set depends on the whole set. Set depends on that item." I'm creating a compiler (https://github.com/SuperJMN/Plotty). In the last stage, the Intermediate Code is converted to ...
-1
votes
1answer
378 views

How to make compiler portable?

I am writing a simple compiler. I have written lexer and parser and it now generates assembly code from given code. Now I need to write an assembler which generates machine code. But the problem is ...
4
votes
4answers
1k views

Rely on compiler to remove unused code or #ifdef out?

I am working on a USB stack in C. This stack will be open source and used in various different projects. Various configuration options are available, which enable or disable large chunks of code and ...
-3
votes
2answers
550 views

What does it mean, “Php doesn't have its own runtime”?

Speaking of php. It doesn't really have its own runtime in compare to python, ruby or go. Php is jsut a text preprocessor. What exactly does it mean by, Php doesn't have runtime?
0
votes
2answers
316 views

Is 'call site' compiler generated auto code?

Is 'call site' some auto code generated by compiler - I come across this term frequently and it sounds like calling method is simply referred as 'call site' - which literally sounds fine but I believe ...
1
vote
2answers
291 views

Representing a structure/tuple type with Hindley Milner Type Inference

I'm writing a really simple interpreted object oriented programming language with a C-like syntax. I've been looking into type inference and I've found a few implementations of the 'Hindley-Milner ...
1
vote
2answers
169 views

How is a compiler related to the runtime system?

A quick search on the role of compiler brings up the following: A compiler is a special program that processes statements written in a particular programming language and turns them into machine ...
6
votes
1answer
2k views

Is there any use case for using 'L' letter after a number literal in C?

I know that in C code using L after a number tells the compiler that the respective number is L. However I do not see any practical use for this. Do modern compilers still have a use for this ...
8
votes
2answers
6k views

Why C allows multiple global declarations of the same variable but NOT multiple local declarations?

I noticed that if I declare a global variable multiple times the compiler does not even output a warning. However if I declare a local variable in a function multiple times, for example, the gcc ...
0
votes
4answers
296 views

Regarding a variable in C, is an assignment always equivalent to a definition of that variable? [closed]

Is there a difference between defining a variable in C and assigning a value to a variable in C? I know that declaring a variable simply means telling the name and its type like int a. On the other ...
1
vote
1answer
62 views

How are global and local names disambiguated by the compiler in three-address code?

In the book Compilers: Principles, Techniques, and Tools (2nd Edition), Appendix A, the authors offer a implementation of a compiler front-end that generates three-address code for a very simple ...
0
votes
2answers
236 views

What is the meaning of the line - “the compiler is self-compiling if it is written in P”? [duplicate]

According to compiler definition, the compiler is a program that translates a program written in a programming language P (source code) into a program written in a machine language M (machine code). ...