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 votes
0 answers
107 views

JSON Parsing via Compiler construction techniques

I have already done JSON parsing through a naive approach, i.e., iterating through character by character, looking for punctuators like braces, commas, and quotes to get tokens, and returning them to ...
Source's user avatar
  • 1
1 vote
1 answer
67 views

How to approach converting to and from kafka messages?

I would like to have a series of small stand-alone services that would either consume a Kafka topic and output the data into a different system or the reverse: receive data from a system and produce ...
mparada's user avatar
  • 11
12 votes
6 answers
6k views

C# and C++ Inheritance and Performance - Shouldn't Compilers Handle this Issue?

In C# and C++, an apparent trend is in place to reduce / avoid inheritance: C#: "Sealing types can improve performance." https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/...
user avatar
0 votes
1 answer
160 views

How do function inlining and Tail Call Optimization affect call stack?

I've just accidentally came across this answer about inlined functions and I'd like to know how this affects call stack. But I can't add comments because I don't have enough rep so I decided to ask ...
b3rry's user avatar
  • 3
1 vote
0 answers
79 views

How can I represent a transformed AST between compilation stages?

I'm writing a compiler in Rust. I've reached the point where I have an AST and am ready to do symbol resolution, type-checking, etc. But, I'm unsure of how to represent an AST as containing "...
gmdev's user avatar
  • 119
0 votes
1 answer
133 views

What lessons can be learned from the architecture/combination of ESLint and Prettier for linting and code formatting?

I was looking through the prettier docs and the prettier source code. It essentially has those defined helper functions to layout the text, given an AST. It operates on the level of the whole file, on ...
Lance's user avatar
  • 2,585
0 votes
1 answer
206 views

Implementing heap-allocated closures in LLVM

I'm writing my own F#-esque language and I'm using LLVM for code generation. I want my language to support continuation passing style and I think I've got TCO figured out but I cannot figure out how ...
Gabriel's user avatar
  • 11
0 votes
2 answers
118 views

Modular Design affects compilation time

Does modular design decrease compilation time in cpp? My professor said so, but I don't understand how, because the build and compilation time depend on the amount of code, right? Also, wouldn't ...
happy's user avatar
  • 11
-3 votes
3 answers
194 views

why do we need instructions set for processor or controller?

Why is it necessary to have an instruction set for processors and controllers? Can't we simply convert high-level language programs, like those written in C, directly into binaries without the need ...
Harshith Gowda's user avatar
-1 votes
1 answer
96 views

Debugging miscompile [closed]

Recently I encountered an issue at work where a unit test written in C++ would crash only when being compiled with MSVC 2017 (MSVC 2019 and up are fine). I tried to debug this issue and it seems like ...
yijiem's user avatar
  • 107
0 votes
1 answer
201 views

Is it true that variable type before name makes compiler work easier? [closed]

I have seen information that at least one of reasons why type placed before variable name is that it allows compiler easier evaluate size and type of variable. If so then how (what way) it eases this ...
Ya Y's user avatar
  • 29
-1 votes
2 answers
170 views

When writing a tokenizer, what is the standard practice for handling aliased language keywords?

When writing a tokenizer, what is the standard practice for handling aliased language keywords? For example, notethat signed short int is a language keyword in C++ and several aliases might be allowed....
Samuel Muldoon's user avatar
0 votes
1 answer
314 views

Custom #pragma directives

I'm creating a language parser on a microprocessor in C++. For the tables of keywords and commands, rather than maintaining a single curated file (alphabetically sorted, etc), I'd prefer to declare ...
SteveG's user avatar
  • 33
0 votes
1 answer
116 views

Are indirect implicit type declerations dangerous?

In the case of kotlin, rust and many other programming languages... There are variables with direct implicit type declarations... Where you can see the type of a variable at the same line where it's ...
user avatar
-1 votes
1 answer
176 views

Better way to represent grammar symbols in C

I'm trying to build a simple compiler for a subset of the C language in C. To achieve this, I needed to figure out a way to represent the grammar symbols. Basically, each symbol can either be a "...
Mehdi Charife's user avatar
-1 votes
3 answers
139 views

How to propagate lexical scope in a compiler, specifically around step-by-step functions?

I am working on a compiler in TypeScript, and currently am focused on how to pass around the "lexical scope" to the relevant objects. Essentially every time there is a conceptual major ...
Lance's user avatar
  • 2,585
13 votes
8 answers
6k views

How do compilers work in a language that doesn't allow recursion?

I'm recently learning the programming language, and I wonder how compilers work when the language itself does not allow recursion, like how the compiler or the runtime checkers makes sure that there ...
csxyyyyy's user avatar
  • 151
5 votes
3 answers
707 views

How does a JIT compiler actually emit and then call the emitted native code?

Assuming that a VM runs a JIT compiler on otherwise "interpreted" code, such as a line by line interpreter or some form of bytecode/IL code and determines that it can create optimised native ...
AIWalker's user avatar
  • 1,287
-1 votes
1 answer
1k views

Why is Java AOT compilation (using graalvm native-image) so much slower than golang compilation?

I followed the guide here https://quarkus.io/guides/building-native-image to set up a minimal quarkus webservice graalvm native image. Ran command 'time quarkus build --native' to compile the example. ...
vancan1ty's user avatar
  • 109
1 vote
1 answer
91 views

Can we reliably use unaligned scalars on contemporary hardware?

Processors have come a long way in their handling of unaligned data - from crashing at the very notion of it, through suffering severe penalties, all the way to having almost no impact. I suppose it ...
dtech's user avatar
  • 713
0 votes
1 answer
1k views

Java: Is there a performance difference between variable assignment vs. inline usage?

Is there any performance detriment to assigning variables vs using them inline. I'm guessing this WOULD be worse if a method was returning primitive and I was 'boxing' it (e.g. method returning int, ...
nanotek's user avatar
  • 301
-3 votes
3 answers
71 views

How to Validate Output Binary During/After Compilation on Platform without ECC Memory [closed]

On a platform with ECC memory, you can assure the compiled binary is 100% legit with EDAC daemon. (single-bit error will be corrected automatically, and multi-bit error will be logged so you can just ...
hurryman2212's user avatar
0 votes
1 answer
128 views

How to manage concurrent build & test toolchains in (embedded) software development?

TL;DR: How do you manage the complex development toolchain in different (embedded) projects? In our company we are discussing the toolchain setups in different development teams and how to work ...
ThePMO's user avatar
  • 109
0 votes
1 answer
115 views

Parsing complex data type names

How do compilers parse complex data types names like function pointers. The type has to be somehow put into the AST or it has to be processed during parsing. What are the pros and cons of different ...
Wojak2121's user avatar
-3 votes
1 answer
329 views

When making a compiler, what's the best way for compiling to machine code in the backend? [closed]

I know that a lot of compilers use an assembler to compile to machine code, to make an executable (compiled program). Some people even made their own assemblers, or they just use an existing assembler,...
Jack Murrow's user avatar
-2 votes
2 answers
282 views

Isn't OS dependent on machines, can anyone briefly explain how it is achieved? [closed]

Certain OS in it's system requirement doesn't specify anything peculiar like in case of ubuntu it asks only for "2 GHz dual core processor or better". If yes, how does it compares with ...
D J's user avatar
  • 107
0 votes
3 answers
302 views

How to deal with forward references in a compiler?

I'm creating a very simple compiler PoC that only has Procedures Calls to procedures. The syntax of the language is really simple: Main { Call("Proc1"); } Proc1 { // Empty } I ...
SuperJMN's user avatar
  • 423
1 vote
2 answers
465 views

Is there a simple algorithm for generating unit tests given a function's code? [closed]

Given the abstract syntax tree (AST) of each line of a function's code, I am asked to generate code for that function's corresponding unit tests, similar to what Microsoft's IntelliTest tool does here:...
David Johnson's user avatar
0 votes
3 answers
718 views

Is it possible to make a compiler for any dynamic/script/interpreter language

Logically, not based on how cost we will spend or how much we will hire programmers to do it. Can we (Is it possible to) make a compiler for any dynamic/script/interpreter language, like Lua, Python, ...
Zaher Dirkey's user avatar
-5 votes
2 answers
145 views

Archival-quality future-proof pseudo-CPU architecture

Suppose we maintain a massive electronic library of texts/photos/videos etc., and want to ensure that these files are readable indefinitely long in the future. [Update] one of the major problems with ...
Ilya Zakharevich's user avatar
1 vote
0 answers
246 views

How to practically implement a symbol table during compiler design?

I was trying compiler design with flex and bison. This is my first attempt in that sense. For my compiler, I wanted to build a symbol table which would help in building a proper compile-time type-...
Sourav Kannantha B's user avatar
-2 votes
3 answers
416 views

Why `struct` unconstrained method fails to accept `null` as `T?` parameter

Considering example below, one observe that for reference type argument is successfully understood as nullable parameter. For value type conversion to T?/Nullable<T> fails. T Method<T> ( T?...
Yarl's user avatar
  • 288
5 votes
5 answers
2k views

How does code work without getting compiled or interpreted?

I recently started researching about coding, but there are a few things that made me confused. I chose Visual Studio Code to start coding in C and Python (I was using IDLE for Python before), but ...
Burcu Avcu's user avatar
4 votes
1 answer
2k views

In C++, If a member function can be made static with no change to functionality, are there any performance or memory benefits from doing so?

A very straightforward question. When I think about many of the member functions I create for my classes, many of them can be made static without affecting any functionality whatsoever. If I do so; ...
Anon's user avatar
  • 3,593
0 votes
1 answer
285 views

Benefits of using a tokenizer/lexer before parsing for recusive descent parser

I am trying to build a static program analyzer for a proprietary progamming language for a school project, and am currently trying to implement the parser from scratch. I was wondering, what are the ...
Meowmi's user avatar
  • 101
0 votes
2 answers
97 views

Small confusion about time complexity

Suppose we have a code: for(int i=0;i<n;i++) sum+=i; We say the time function here is: f(n) = n+1+n = 2n+1. The order of the time function is 1. So, our time complexity becomes O(n). But, for the ...
Md Mosleh Uddin's user avatar
2 votes
3 answers
243 views

Where is the boundary between things which can be statically typechecked, and those which must be typechecked dynamically?

I am brain storming on how to create a type system for a programming language, and what the compiler will do with the typing information. Here is what I have found, followed by the main question, ...
Lance's user avatar
  • 2,585
2 votes
1 answer
1k views

Do C++ compilers optimize/pack small data types (e.g. boolean values)?

This occurred to me when looking at stencil computations in numpy. This python library compiles compute-intensive components, so I believe that it's a valid example. Here making selections on an array ...
Daniel Krajnik's user avatar
-2 votes
1 answer
349 views

Which non-standard C features can I use? [closed]

C and C++ have standards, but support isn't perfect, the only available copies on the internet are drafts, and there are immensely useful things that aren't standard, such as __attribute__((cleanup)). ...
Dan's user avatar
  • 123
-1 votes
3 answers
495 views

What happens in terms of call stacks when 10000 setTimeouts are called?

Say we call 10000 setTimeouts, each with a random time, each with a few nested timeouts too. What happens in terms of the 1 call stack, or are there multiple call stacks? How does that work? So for ...
Lance's user avatar
  • 2,585
1 vote
4 answers
331 views

Why Java, C# and the like needs to be managed code

As far as I know the big argument for C#, Java and other high level languages having to be memory managed by a runtime environment is that the programmer does not take care of garbage collection or ...
stevie's user avatar
  • 225
0 votes
2 answers
710 views

Template argument type exclusion: Would this make for a useful C++ feature?

When using templates we can have T be any type upon class instantiation. If T is a specific type that needs to be handled differently or in a special way we can specialize or partial specialize that ...
Francis Cugler's user avatar
26 votes
4 answers
6k views

Do compilers optimise in concurrency?

Presuming that I have written some sequential code where it can be broken down into multiple isolated tasks, it seems it might be efficient for concurrency to be introduced. For example print(...
Ben's user avatar
  • 369
1 vote
3 answers
1k views

How do binary numbers interact with the CPU and cause some action to take place? [duplicate]

EDIT: Perhaps what I am misunderstanding is that when it is said that the code we type gets turned into machine code of 0s and 1s. If these 0s and 1s are the abstracted representation of their ...
steez's user avatar
  • 31
1 vote
1 answer
109 views

is the relocatable machine code essentially the text segment of the virtual address?

Sorry if this is a basic question, I'm studying for my operating systems class and compiler theory class at the same time and this is confusing me. From what I do understand, virtual memory is larger ...
qwerty_99's user avatar
  • 163
-2 votes
1 answer
1k views

How to write a very basic compiler (with modern approaches) [closed]

For sure, there is a well-known topic here on SE, however, it is almost 10 years old, and answers that were excellent by then, might be obsolete now and there could be modern easier ways (but I don't ...
T.Todua's user avatar
  • 145
2 votes
4 answers
617 views

C++ - Is it bad practice to use compiler specific functions?

My requirement is simple, I want to be able to count the number of bits in a number. With a little bit of research, I found that MSVC has __popcnt, GCC has __builtin_popcount and so on. At this stage,...
user avatar
1 vote
0 answers
95 views

Is there a easy and useful error handling algorithm for bottom-up based parser?

My English skill is poor because I'm not a native English speaker. Please understand. I wonder that there is a error handling algorithm easy and useful in LR parser. LR Parser is bottom up based so it ...
jjw's user avatar
  • 217
8 votes
3 answers
4k views

What are the 'practical' advantages of LR parser over LL parser 'in today'?

My English skill is poor because I'm not a native English speaker. Please understand. I write this article because want to discuss about this topic. I think LR parser has no 'practical' advantages ...
jjw's user avatar
  • 217
0 votes
1 answer
80 views

Structuring a Compiler in a Dynamic Language (JavaScript)

For learning purposes, I'm trying to build a compiler in JavaScript for a tiny custom language and turn it into WASM. So far, I've got a lexer and parser, that turn my code into an AST, my question is ...
Pandawan's user avatar

1
2 3 4 5
10