Skip to main content

Questions tagged [compiler]

For reviews of code which implements any part of a compiler - lexing, parsing, code generation and optimization, etc. Also for any plugin for an existing compiler. Don't use this tag for code which is input to a compiler - tag it with the correct language instead.

Filter by
Sorted by
Tagged with
40 votes
2 answers
2k views

Brainfuck to x86 Assembly Compiler

After my Brainfuck Interpreter written in x86 Assembly I decided that it was time to get to the next step, writing a Brainfuck Compiler in Java that generates x86 Assembly and compiles that to an ...
skiwi's user avatar
  • 10.6k
17 votes
1 answer
674 views

Brainfreeze: A Brainfuck compiler in C

BrainFreeze This is my implementation of a brainfuck compiler in C. The instruction to build/run the project (GitHub repo) can be found here. I am first converting the brainfuck source to x86 ...
Gnik's user avatar
  • 882
16 votes
3 answers
2k views

Reverse Polish notation based compiler

Description Very small subset of Forth This is a proof of concept level compiler, no optimizations or over/underflow checking See the embedded POD for more information NASM is used as assembler gcc ...
JaDogg's user avatar
  • 4,531
14 votes
4 answers
3k views

Compiler Tokenizer implementation in C#

I'm writing a compiler for a couple of months now, this is the tokenization part of the lexer. I would like a code review to improve my coding style and learn new techniques to pretty up my code and ...
downrep_nation's user avatar
14 votes
3 answers
1k views

Interpreting Brainfuck code to C#, then compiling to a .exe

This is a C# programme to convert Brainfuck to C#, then convert that C# to a .exe. So basically, it's a Brainfuck to Windows exe file converter/compiler. This requires any of: .NET 2.0 in C:\Windows\...
Der Kommissar's user avatar
14 votes
3 answers
517 views

BF#: Round 2 (Fight!)

So I've completely changed how BrainfuckSharp does things, and added some features. This is obviously a follow up to: Interpreting Brainfuck code to C#, then compiling to a .exe It now features an <...
Der Kommissar's user avatar
13 votes
1 answer
307 views

Brainfuck to NASM compiler in Haskell

After reading this article on writing a Brainfuck interpreter in Haskell and achieving awful performance with it (for example, mandelbrot generating 37.5 minutes on an old Intel Atom powered laptop) I'...
atmostmediocre's user avatar
12 votes
4 answers
2k views

Simple C99 Lexer

I'm building a compiler for fun, and this is my first pass at the lexer for it. It should handle all tokens for C99, with the exception of the preprocessor tokens. It's very minimal, only grabbing the ...
User319's user avatar
  • 1,132
12 votes
2 answers
2k views

Abstract syntax tree for simple Lisp-like interpreter

A week or so ago, I wrote a binary expression calculator with the hope of better understanding how interpreters and compilers work. In the same vein, I've tried to write a lisp like language ...
rookie's user avatar
  • 1,233
12 votes
1 answer
1k views

Jack compiler in C

I have been doing projects from the book The Elements of Computing Systems. Under the scope of project 10 and project 11, I had to implement a compiler for a (toy) programming language called Jack (...
almaveln's user avatar
  • 123
11 votes
3 answers
5k views

Fastest possible text template for repeated use?

While reviewing Sending templatized e-mail to a million contacts, I wrote this implementation to illustrate an alternate approach. It is designed to be the fastest possible way to generate templated ...
200_success's user avatar
11 votes
1 answer
585 views

Assembler for CPU

I recently put together an assembler for a CPU I designed. I'm looking for feedback on my program structure, formatting, or anything else. I'm self taught on all of this so I don't have opportunities ...
user avatar
10 votes
3 answers
3k views

Heavily limited premature compiler translates text into excecutable python code

My goal is to write a smaller compiler-like program, which allows me to draw geometric shapes into a 3D Diagram. There is no need for turing-completeness and the program should only be viewed as an ...
TVSuchty's user avatar
  • 595
10 votes
1 answer
275 views

A BrainF*ck-ish compiler in C

-ish because I removed the input functionality from the compiler. And, the compiler does not support nested loops I've been recently reading up on compilers and how they work. Although this doesn't ...
SirPython's user avatar
  • 13.3k
10 votes
1 answer
647 views

PEG.js grammar for a simple programming language

I'm trying my hand at developing a compiler and have written a peg.js grammar for a simple programming language. A sneak peak at the grammar: ...
Logarytm Całkowy's user avatar
10 votes
0 answers
1k views

Cyther: The Cross Platform Cython/Python Compiler (Take 2)

I recently posted an earlier version of this code on Code Review, and now with the given suggestions and many other improvements, I am back. I included the description of exactly what Cyther is ...
Nick Pandolfi's user avatar
9 votes
1 answer
295 views

Is possible to use script for dependencies in c++?

I wanted to make a script that would parse a main file (with int main()) look in its #include "..." local headers, and ...
milanHrabos's user avatar
8 votes
3 answers
8k views

Lexer for C# source code

This code reads a .cs source file in the \bin folder and parses the C# code in it. The program outputs keywords, identifiers, separators and numerical constants. How could it be improved? ...
Andrei's user avatar
  • 131
8 votes
1 answer
290 views

C++ - Lexer for the Monkey Programming Language from the book "Writing An Interpreter In Go"

Below is a C++ version of a lexer for the Monkey programming language, originally written in Go, as presented in the book Writing An Interpreter In Go. LOC: 262. (Excluding the tests.) Language: Copy ...
Harith's user avatar
  • 9,038
8 votes
2 answers
298 views

Compiler for a minimal LISP dialect to run on the Java Virtual Machine

As the title states, this is a compiler written in C with a ruby build script that translates a minimal LISP dialect and spits out an executable jar file. I designed this LISP dialect and named it ...
user avatar
7 votes
4 answers
2k views

Lexer for C++ in python

I wrote a simple C++ lexer in python. Although it already works but I kinda feel I didn't follow the pythonic way. Any suggestion for improvements? Sample C++ Code Sample output Here's my code: ...
nitwit's user avatar
  • 501
7 votes
3 answers
4k views

Building abstract syntax tree for markargs

Roadmap I'm trying to follow usual compiler design: Lexical analysis (1, 2) Syntactical analysis <---- you're here Semantic analysis User input Code generation + execution Background I think I ...
Incomputable's user avatar
  • 9,504
7 votes
2 answers
3k views

Cyther: The Cross Platform Cython/Python Compiler

The newer version of this question is located here: Cyther: The Cross Platform Cython/Python Compiler (Take 2) I am currently writing a Python library (soon to be published)that automatically compiles ...
Nick Pandolfi's user avatar
7 votes
2 answers
449 views

Program that generates brainfuck code that outputs given text

I created program that generates brainfuck code that outputs given text. Arguments for the program are input file with the text and ...
DeBos's user avatar
  • 525
7 votes
2 answers
92 views

Pseudoportable C script pattern - follow-up

See the initial/previous iteration. I have rewritten the script following the answer of @200_success. Now it looks like this: ...
coderodde's user avatar
  • 28.7k
7 votes
1 answer
148 views

Nothing compiler/interpreter, Part 2

Part 1 I've followed some of the suggestions: Adding newlines to error messages Implementing options (I decided to use boost instead of getopt) Using strerror for fstream failure Allow multiple ...
user82726's user avatar
6 votes
1 answer
3k views

Runtime compiler for getting/setting runtime property values

I've been playing about with runtime compilation to allow me to get/set runtime property values in C#, and so far I have come up with a class. This allows me to write code like the following which ...
James South's user avatar
6 votes
2 answers
191 views

Programming Language Source Lexer

I have a lexer (program that turns source code into tokens) written in Go that I am re-writing in Rust. The lexer should take in a sequence of tokens, generally different special characters, integers, ...
John Allison's user avatar
6 votes
2 answers
321 views

Brainf*ck to NASM converter written in C

I have made a very simple Brainfuck to NASM converter, that is usable for practically all programs. It has one trivial optimisation (to subsitute ADD for ...
user avatar
6 votes
1 answer
88 views

Pseudoportable C script pattern

(See the next iteration.) From time to time, while working with a command line in *nix family of operating systems, we have to write those scripts doing a rather specific task. Usually we use ...
coderodde's user avatar
  • 28.7k
6 votes
2 answers
7k views

Make compiler obfuscate strings

I'm looking at a task to obfuscate strings in my application like URLs, paths and queries at compile time. This is not for encrypting ...
Ogglas's user avatar
  • 185
6 votes
1 answer
7k views

Creating data objects dynamically at runtime from an interface

Sometimes when I write objects for holding data (not real DTOs, no serialization involved) I also create an interface for it. The class that implements it can also perform some null checks. I don't ...
t3chb0t's user avatar
  • 44.3k
6 votes
1 answer
1k views

Brainfuck to Java converter

Similar to the previous post Brainfuck Interpreter: Slower than a Snail?, it runs BF in java. The only difference is that the converter will convert the BF code into a compilable and fairly readable ...
TheCoffeeCup's user avatar
  • 9,444
6 votes
1 answer
789 views

Programming language lexer in Rust

I'm working through Crafting Interpreters and trying to apply what I've learned in Rust. I've got the lexer working in what feels like a reasonably idiomatic way (hooray!), but I have a feeling it ...
Joe Clay's user avatar
  • 218
6 votes
1 answer
240 views

Logic Prolog compiler

I'm actually doing my own Prolog compiler just like SWISH one with Java. Prolog is a logic language that is particularly suited to programs that involve symbolic or non-numeric computation. Prolog ...
Revolucion for Monica's user avatar
6 votes
0 answers
399 views

Creating a new language: FreezeFlame

Where it shines FreezeFlame shines in readibility while still maintaining most of the C-like syntax. It also implements a few (Planning on several) operators that are still in testing for other ...
FreezePhoenix's user avatar
5 votes
2 answers
468 views

Brainfuck to Python compiler

So this is (I think) a premiere for python. A function that translates brainfuck code to python code. It does a few optimizations (It chains +,...
MegaIng's user avatar
  • 413
5 votes
1 answer
672 views

Simple BASIC to Simpletron Machine Language compiler in C

I implemented a compiler that compiles a dialect of BASIC known as SimpleBASIC into Simpletron Machine Language to be run by the Simpletron simulator. I wrote the manual for the SimpleBASIC compiler ...
phillbush's user avatar
  • 864
5 votes
1 answer
224 views

Compiler Tokenizer implementation in C# - follow-up

I have posted this question 2 days ago and got amazing feedback on it. Hands back to the keyboard, I believe I took the suggestions into account and improved the classes drastically. In this question,...
downrep_nation's user avatar
5 votes
1 answer
200 views

JavaCC Android port User Interface (Activity) class

I have been working on a port of JavaCC for Android. It is mainly an interface. I needed only to modify the original source to redirect output to a TextView. The point of this project is to rekindle ...
motoku's user avatar
  • 2,521
5 votes
0 answers
224 views

tbf - An Optimizing Brainfuck Interpreter and Transpiler in C

Language: The Brainfuck programming language consists of eight commands: ...
Harith's user avatar
  • 9,038
4 votes
2 answers
2k views

Compiling and throwing simple dynamic exceptions at runtime for JVM

I've been using my Dynamic Exception with C# for quite some time already and it saved me a lot of time. This means, I don't have to create a new exception ...
t3chb0t's user avatar
  • 44.3k
4 votes
1 answer
1k views

Simple flex-based lexer

I am trying to learn flex and have created this simple program. The rule for comments works correctly for single line comments such as: // this is a comment and ...
Setu Kumar Basak's user avatar
4 votes
2 answers
113 views

Python command line tool for compiling py files to exec files on Mac

When I used to use a PC I was familiar with py2exe, the mac equivalent I saw most people talking about was py2app — which compiles python to .app files, not .exec files. I was familiar with compiling ...
Shui's user avatar
  • 173
4 votes
2 answers
178 views

Build script for an operating system written in C++

I recently started following the James M Kernel Dev tutorials and was able to create an operating system in C++. Here is the source on GitHub. I have a couple of questions: Is my coding style ok? ...
aswin mohan's user avatar
4 votes
1 answer
176 views

AEC-to-WebAssembly compiler in C++

Now that my new compiler is capable of compiling programs such as the Analog Clock in AEC, I've decided to share the code of that compiler with you, to see what you think about it. File ...
FlatAssembler's user avatar
4 votes
1 answer
459 views

Is this a good way to write a lexer?

I don't know whether if this is the right place to ask this. I am semi-beginner in C. I always wanted to build my own Programming Language. Here I have built a lexical analyser completely myself. ...
rsonx's user avatar
  • 143
4 votes
1 answer
230 views

A Brainfuck compiler that creates a small x86_64 Linux executable from scratch

This program compiles Brainfuck source code to an x86_64 ELF executable. It doesn't rely on any backend, just raw binary stream to a functional executable. In the implementation, each cell holds an 8-...
xiver77's user avatar
  • 421
4 votes
1 answer
400 views

Assembler made in assembly

I made an assembler for the "hack" assembly language, here's an example of what it looks like: ...
elonma1234's user avatar
4 votes
1 answer
109 views

C99 - Lexer for the Monkey Programming Language from the book "Writing An Interpreter In Go"

Below is a C version of a lexer for the Monkey programming language, originally written in Go, as presented in the book Writing An Interpreter In Go. LOC: 371. (Excluding the tests.) Language: Copy ...
Harith's user avatar
  • 9,038