Questions tagged [compiler]

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

Filter by
Sorted by
Tagged with
1
vote
4answers
69 views

Ahead-of-time compilation to native machine code of dynamically typed languages

It is my understanding that: It's particularly difficult to compile ahead of time, to efficient native machine code, a dynamically typed language like Python. Largely as a result of the above, the ...
2
votes
3answers
461 views

Should compilers follow the defined language standard?

Why do some compilers violate the defined language standard? I don't understand, in ISO/IEC 10206:1990 Extended Pascal standard on 6.8.3.2 Arithmetic operators section, Page 86. It says that, A ...
-1
votes
1answer
86 views

Difference between direct and indirect function() calls

I am curious about the Difference between direct and indirect function() calls Could anyone help in the diff analysis ? The c source code could be found at subroutine_direct.c and ...
-4
votes
3answers
192 views

Is it really always easier to write an interpreter than a compiler?

I've read that generally it's easier to write an interpreter than a compiler. If that's true, what's the reason? Writing an interpreter seems to me equivalent in the level of difficulty as writing a ...
0
votes
1answer
102 views

How to design a system that can operate and replay its functions call stack?

I am writing a processor for the Citation Style Language (CSL) in JavaScript. Before I explain what my problem is, I must give some context first: CSL is an XML specification for describing how to ...
29
votes
5answers
108k views

Why doesn't Python need a compiler?

Just wondering (now that I've started with C++ which needs a compiler) why Python doesn't need a compiler? I just enter the code, save it as an exec, and run it. In C++ I have to make builds and all ...
0
votes
1answer
110 views

Are parser generators useful for parsing a shell language?

From my understanding, parser generators accept as input some form of context-free grammar description. The context-sensitive features are handled during semantic rather than syntactic analysis (...
2
votes
3answers
168 views

How are namespaces used in the stack during scope lookups?

I'm taking a comparative programming languages course and have learned the bare basics of variable scopes with respect to stack frames -- e.g. static and dynamic links, offsets, etc. as in the image ...
-1
votes
1answer
226 views

Do C# compilers optimize away the facade pattern?

In C#, if I hide away implementation behind a facade, or the "pimpl" pattern, does the compiler optimize away the intermediate function call if all it's doing is calling an equivalent method from ...
19
votes
6answers
13k views

Is there a language that transpiles to C, with better syntax? [closed]

CoffeeScript is a language that transpiles to JavaScript, with a clean syntax, inspired by Ruby. Is there a similar language that transpiles to C, allowing for more readable code without compromising ...
4
votes
1answer
852 views

Writing a Compiler - .reloc section of the COFF

I'm looking for a little bit of direction in writing a compiler. I've written in Common Intermediate Language, C#, and various other .NET languages; I've written my own Metadata Parser and now I'm ...
2
votes
0answers
78 views

Windows: Have a dedicated MS Visual C/C++ toolchain

For a CI system and the developers in our team, I'd like to be able to use a specific version of a MSVC toolchain for native Windows builds. The goal is to have a well-defined consistent build-...
14
votes
11answers
6k views

How do I know if the compiler broke my code and what do I do if it was the compiler?

Once in a while C++ code will not work when compiled with some level of optimization. It may be compiler doing optimization that breaks the code or it may be code containing undefined behavior which ...
2
votes
0answers
72 views

Is it dangerous to link together -mno-red-zone and regular code?

I know that in x86_64, there exists a 128 byte red zone above (or below, address-wise) the stack pointer that functions can use without subtracting from rsp. This sounds to me like the only things ...
2
votes
3answers
242 views

Is a literal out of range a syntax error or a semantic error?

I am reading more about the differences between syntax and semantics, but I am still wondering about this one. Let's assume that we have a language that only allows integers to be in the range of 0-...
9
votes
5answers
2k views

Why isn't the overloading with return types allowed? (at least in usually used languages)

I don't know about all programming languages, but it's clear that usually the possibility of overloading a method taking into consideration its return type (assuming its arguments are the same number ...
1
vote
1answer
134 views

Switching out implementation source files in C project

For simplicity, let's say I have the following C project structure: src/ utils/ logger.c logger.h main.c secondary_component.c main.c starts with: #include "utils/logger.h" I would ...
4
votes
5answers
3k views

Is there something that prevents a multithreaded C# compiler implementation?

The C/C++ language family apparently has multithreaded compiler implementations that work on file level parallelism, but the Microsoft C# compiler (csc.exe) is single-threaded only. MSBuild supports ...
0
votes
1answer
154 views

Why do new language versions typically use an early compiler version for the bootstrap compiler?

Wikipedia describes a bootstrap compiler to have these properties: An initial core version of the compiler A minimal subset of the language to be used by successive compiler versions Everything I've ...
0
votes
1answer
69 views

How is a function in execute only space compiled?

I don't quite understand, how the following typedef is parsed by a compiler to call code at a specific address. I guess I understand that a function is just a pointer and we're typedefing such a ...
2
votes
1answer
127 views

C++ design pattern for template instantiation based on run time information?

Say I want to be able to create objects for a range of template parameter template<int a> class Myclass : public MyclassSuper{...}; And I want to create objects like Myclass<...
218
votes
5answers
276k views

How to write a very basic compiler

Advanced compilers like gcc compile codes into machine readable files according to the language in which the code has been written (e.g. C, C++, etc). In fact, they interpret the meaning of each codes ...
5
votes
3answers
377 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 ...
3
votes
2answers
771 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 ...
2
votes
2answers
247 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
3answers
13k views

How to reduce size of jar file?

I dont know how to reduce the size of jar file. When we normally code in Java Swing the jar file is created, is there any way to reduce the size of jar file? I can't remove the images and other stuff ...
6
votes
2answers
6k views

Is Objective-C an Interpreted or Compiled language?

I want to know if Objective-C is an interpreted or a compiled language.
1
vote
1answer
141 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
102 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
vote
1answer
413 views

Desired pattern for expression parsing into RPN

I'm writing a interpreter/compiler I have encountered a problem which I have solved before, but not optimally perhaps. The problem goes like this, expressions can express a lot of things like scopes,...
-1
votes
2answers
155 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
321 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 ...
15
votes
10answers
2k views

Compiler Warnings

Many compilers have warning messages to warn the programmers about potential runtime, logic and performance errors, most times, you quickly fix them, but what about unfixable warnings? How do you ...
3
votes
3answers
752 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 ...
2
votes
3answers
580 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, ...
-1
votes
1answer
171 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 ?
2
votes
3answers
274 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
248 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;...
5
votes
7answers
1k views

How can a compiler be written for a language that allows rewriting code at runtime (such as Lisp macros)?

There are some programming languages, like the many dialects of Lisp, that allow for macro-metaprogramming: rewriting and altering sections of code before the code is run. It is relatively trivial to ...
15
votes
2answers
7k views

Do compilers utilize multithreading for faster compile times?

If I remember my compilers course correctly, the typical compiler has the following simplified outline: A lexical analyzer scans (or calls some scanning function on) the source code character-by-...
80
votes
5answers
144k views

Is Python Interpreted or Compiled?

This is just a wondering I had while reading about interpreted and compiled languages. Ruby is no doubt an interpreted language since the source code is processed by an interpreter at the point of ...
72
votes
5answers
23k views

Why are there so few C compilers?

C is one of the most widely-used languages in the world. It accounts for a huge proportion of existing code and continues to be used for a vast amount of new code. It's beloved by its users, it's so ...
0
votes
0answers
69 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 ...
14
votes
1answer
2k views

Why does LLVM have an assembly-like IR rather than a tree-like IR? Or: why do projects target LLVM IR instead of clang's AST?

Why is LLVM's intermediate representation (LLVM IR) assembly-like rather than tree-like? Alternatively, why do language implementations target LLVM IR rather than clang's AST? I'm not trying to ask ...
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
465 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
311 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
98 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
48
votes
4answers
27k views

How could the first C++ compiler be written in C++?

Stroustrup claims that Cfront, the first C++ compiler, was written in C++ (Stroustrup FAQ). However, how is it even possible that the first C++ compiler be written in C++? The code that makes up the ...
65
votes
19answers
10k views

How come compilers are so reliable?

We use compilers on a daily basis as if their correctness is a given, but compilers are programs too, and can potentially contain bugs. I always wondered about this infallible robustness. Have you ...