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
3
votes
1answer
220 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
459 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
1k 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
454 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
368 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
297 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
3k 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
9k 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
314 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
72 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
319 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). ...
-1
votes
2answers
282 views

What does syntactically legal string mean in compiler design?

In programming language theory semantics, semantic is the field concerned with the rigorous mathematical study of the meaning of programming languages. It does so by evaluating the meaning of ...
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,...
0
votes
2answers
119 views

How do interpreters and VM print?

While direct Language-Assembly compilers generate the code required to perform specific task for the given platform, how do interpreters do it? Abstract example The following pseudo-code... printf("...
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 ...
8
votes
3answers
3k views

How are variables stored in a language compiler or interpreter?

Say we set a variable in Python. five = 5 Boom. What I'm wondering is, how is this stored? Does the compiler or interpreter just put it in a variable like so? varname = ["five"] varval = [5] If ...
4
votes
2answers
563 views

Why don't all languages have the same efficiency?

I just finished my compilers course. One of the topics discussed was ways to make compilers more efficient. For example: tail recursion, inlining procedures, strength reduction, removing dead code, ...
23
votes
6answers
4k views

What is the common procedure used when compilers statically type check “complex” expressions?

Note: When I used "complex" in the title, I mean that the expression has many operators and operands. Not that the expression itself is complex. I've recently been working on a simple compiler to x86-...
0
votes
2answers
342 views

Automatically convert mutations in imperative code into functional actions?

I wonder if somebody tried creating a language where you can write mutations in a straightforward imperative style, and the compiler transforms the changes automatically to pure, Redux-style actions. ...
0
votes
1answer
269 views

In which way should I structure a compiler/Interpeter? [closed]

For a couple of months now Im writing a interpeter / compiler for a programming language in C#. I have encountered some issues recently which make the code feel incorrectly written Classes change a ...
79
votes
6answers
14k views

How does garbage collection work in languages which are natively compiled?

After browsing several answers an Stack Overflow, it is clear that some natively compiled languages have garbage collection. But it is unclear to me how exactly this would work. I understand how ...
3
votes
1answer
156 views

Use more dynamic dispatch could reduce compile time?

In swift the compilation time is really slow the amount of code in your project increases. So i was looking for ways to reduce that time. One approach maybe is to use language keywords like final or ...
0
votes
2answers
759 views

Implementing naive register allocation for x86 machines

I'm writing a toy compiler targeting on x86-64 machines. But I confront several problems when implementing register allocation with linear intermediate representation. I use NASM and GCC to generating ...
21
votes
2answers
1k views

Is it possible to create a “bootstrapped” interpreter independent of the original interpreter?

According to Wikipedia, the term "bootstrapping" in the context of writing compilers means this: In computer science, bootstrapping is the process of writing a compiler (or assembler) in the source ...
60
votes
10answers
11k views

Is it bad practice to use a C++ compiler just for function overloading?

So I am working on a software design using C for a certain processor. The tool-kit includes the ability to compile C as well as C++. For what I am doing, there is no dynamic memory allocation ...
3
votes
4answers
1k views

Does one have to write multiple “flavors” of C/C++ code for each intended platform?

I have designed what I think is a useful, reusable functionality that I'd like to: Implement in C/C++ as an open source library; and then Write different "native binding libraries" for it in various ...
-7
votes
1answer
82 views

Why we need compile PyQt before use it on Mac?

Why we need compile PyQt rather than simply using 'pip install' to put PyQt to my package repository? What happened during the compiling? Can I compiled PyQt once but allow many Macs through share ...
9
votes
3answers
700 views

Why do compilers typically only generate executables for the platform they are installed on?

I'm a C++ developer and in an attempt to better understand cross-platform development, I'm trying to get a better understanding of some implementation details of compilers and how exactly they create ...
17
votes
3answers
4k views

What exactly is a compile target?

I keep hearing the term and all google searches lead me to articles on compilers. I just wanna understand what the term compile target means :| UPDATE: To give some context: I've heard it said that ...
4
votes
2answers
939 views

C# Possible method name conflicts with optional parameters - why it is not forbidden? [closed]

Let's have a simple class, and main method: using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { ...
3
votes
3answers
369 views

How to create simulator for distributed algorithms written in simple language

I started development of simulator for simulation of distributed algorithms in language C. My work consist of creating simple language for algorithm description and simulator which takes the described ...
-7
votes
1answer
180 views

Is it true that Linux and Mac OS programs' source are interchangeable? [closed]

Is it true that most of the times source code for Linux programs can be compiled into Mac OS programs and vice versa?
2
votes
1answer
435 views

Turning an LR(1) an expression grammar into LL(1)

I have the following grammar for logical, relational, and arithmetic expressions which I need to make LL(1) compatible. E -> A | B A -> A op1 T | T T -> T op2 F | F F -> ( A ) | v B ->...
0
votes
2answers
1k views

Difference between assembly code and disassembly listing

Is the disassembly listing generated by a disassembler exactly the same as the assembly code listing that is optionally generated by a compiler during the compilation of C code?
3
votes
3answers
2k views

Should we compile and ship libraries with debug information whenever possible?

There is considerable cost (and pain) for developers to debug external libraries due to the fact that many libraries are distributed in two editions: one with debug information, other without. The ...
5
votes
2answers
829 views

How does a compiler know the machine language of targeted processor to which the source code has to be converted?

For ex: Two machines have the same compiler and the same operating system. But the two machines have different processors (different assembly instructions).As the compiler was downloaded with respect ...
4
votes
1answer
576 views

How can CLS compliant methods have non-compliant local variables?

The .NET CLS (Common Language Specification) allows a programmer to write code in one .NET language and confidently know that all other .NET languages can safely interact with and even utilize data ...
60
votes
14answers
13k views

Can we make general statements about the performance of interpreted code vs compiled code?

I'm comparing two technologies in order to reach a recommendation for which one should be used by a company. Technology A's code is interpreted while technology B's code is compiled to machine code. ...
5
votes
4answers
851 views

How does Java improve over C++ in the area of portability?

I was reading through a Java book by author Herbert Schildt and he writes how the advantage of Java over C++ in portabilaty is that while C++ can be run anywhere, it still requires each program to be ...
0
votes
2answers
233 views

Where to start when creating a programming language? [closed]

I'm actually a programmer on a few languages, but I realized I really didn't know much how the computer works on a deeper level. So I thought a good idea to discover and learn how does it work was to ...
1
vote
1answer
131 views

Is there a name for infered strong typing?

In JavaScript, you can have a loosely typed language. So doing the following is acceptable: var iterator = new TokenIterator(this.session, cursor.row, cursor.column); var matchType; var found = ...
3
votes
3answers
160 views

What is the general term for [function] names of which the value is fully known at compile time?

In certain programming languages, the meaning of certain names may be fully determined at compile-time (i.e. without running the program). Example: A function in C has global scope; when the name of ...
2
votes
3answers
167 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 ...
4
votes
3answers
434 views

Is SSA form worth it if code generating to a high level language?

I'm writing a compiler that compiles to C. This means that most of the time I piggyback on top of C for optimisations and generating code for multiple platforms. Right now I can think of a few ...
2
votes
3answers
532 views

Which programming languages support type inference from variable names? [closed]

Which programming languages support type inference from variable names? By 'type inference', I mean, for example, in Swift, how if you let x = 39 then the compiler knows x is an Integer, because 39 ...
2
votes
1answer
2k views

Understanding abstract syntax trees in compilers

I have attached the problem below with the answer. My problem is that I can't understand it. Can you provide an overall explanation in detail about parse trees and ETF grammar by deriving the first ...
0
votes
2answers
267 views

Is there such a thing as a 'pseudo-compiler' for proprietary software?

I'm interested in whether there is such a thing as a pseudo-compiler that can create a kind of binary or bytecode version of a plaintext script file, which can only be accessed by a proprietary piece ...
15
votes
2answers
2k views

How are generics implemented in a modern compiler?

What I mean here is how do we go from some template T add(T a, T b) ... into the generated code? I've thought of a few ways to achieve this, we store the generic function in an AST as Function_Node ...
6
votes
3answers
9k views

Why can't C# implicitly convert int to string?

C# allows implicit conversions of integers to strings when used in an expression. For example, this is completely valid: int myInt = 10; string concatenatedString = "myInt is " + myInt; string ...