stardance has been extended another month! the new deadline is october 31 :)

You are browsing as a guest. Sign up (or log in) to start making projects!

LME Luna Machine Executable

  • 5 Devlogs
  • 7 Total hours

My own compiler from scratch. Language: C++, Target: x86-64 assembly (NASM), Syntax Language: Turkish, File Extension: .lme, Name: LME (luna machine executable)

Ship #1 Pending review

Made my own compiler from scratch, called Luna Machine Executable (LME). Written in C++, compiles a tiny language with Turkish keywords into real x86-64 assembly, then assembles + links it with nasm/ld into an actual Linux binary.

Right now it handles one statement: cik ; compiles to a binary that exits with that code. Full pipeline: tokenizer -> parser -> generator -> asm -> nasm -> ld -> binary.

Hardest part was understanding how a parser turns tokens into a tree, and how the generator walks it. Never written a compiler before, so most time went into learning that.

Proudest of getting it to run end to end with zero hand-patching, “cik 42;” in, real binary that exits 42 out.

To test: download luna + test.lme, sudo apt install nasm binutils, chmod +x luna, ./luna test.lme && ./out && echo $?

  • 5 devlogs
  • 7h
Try project → See source code →
Open comments for this post

2h 57m 4s logged

LME My own Compiler Devlog #5

Finished the first real end-to-end version of Luna today.

Wrote generation.h - takes the parse tree from the parser and walks it to spit out x86-64 NASM assembly. Right now it just handles the one node type I have (NodeExit) and generates the mov/syscall pair for exiting with a given code.

Rewired main.cpp so it actually uses the tokenizer -> parser -> generator pipeline properly instead of skipping straight from tokens to asm like before. Cleaner flow now:

source -> tokens -> parse tree -> asm -> nasm -> ld -> binary

Tested it with:
cik 42;

Compiled clean, ran the output binary, echo $? gave 42. First time the whole pipeline worked end to end without me hand-patching anything.

Also wrote a proper README and a .gitignore so I can actually put this on GitHub without dumping build folders and .idea junk into the repo.

Still only supports one statement (cik ;), no variables or math yet. Next up: probably adding a second statement type so the parser/generator actually have to branch on something.

0
0
21
Open comments for this post

2h 0m 15s logged

DEVLOG #4
Took me allot to understand how a parse tree/Syntax tree works and how to programm it.
So I will be using the recursive descent technique and making nodes for each production.

0
0
10
Open comments for this post

1h 13m 54s logged

Cleaned up code, made another file for the tokenization(lexer) almost at parsing tree (

[ SOURCE CODE ]
│

  1. ▼ LEXICAL ANALYSIS (Tokenizer) ◄─── finished here
    [ TOKEN STREAM ]
    │
  2. ▼ SYNTAX ANALYSIS (Parser)
    [ ABSTRACT SYNTAX TREE (AST) ]
    │
  3. ▼ SEMANTIC ANALYSIS (Type Checker)
    [ DECORATED AST ]
    │
  4. ▼ INTERMEDIATE CODE GENERATION (IR)
    [ IR CODE ] (e.g., Three-Address Code, Bytecode)
    │
  5. ▼ CODE OPTIMIZATION
    [ OPTIMIZED IR ]
    │
  6. ▼ TARGET CODE GENERATION
    [ MACHINE CODE / ASSEMBLY ] (Final Executable)

“there are two types of programmers - those who have written a compiler and those who haven’t”
-Terry Davis

0
0
2
Open comments for this post

32m logged

LME My own Compiler Devlog #2
I got the basic compiler pipeline working for Luna.I implemented a tokenizer that converts Luna source code into tokens, including:cik → exit token integers → integer literals; → semicolon token then added code generation that converts the tokens into x86-64 NASM assembly using the Linux exit syscall.For example: cik 42; gets compiled into assembly that exits the program with status code 42.I also fixed a bounds-checking bug in the token parser and verified that the generated executable runs correctly under Linux/WSL.The basic pipeline is now:Luna source → tokenizer → tokens → x86-64 assembly → executable

Next step is the Parse Tree

0
0
4
Open comments for this post

24m 19s logged

Building my own compiler (vexa compiler) devlog #1
Semicolon based, whitespace does not matter.
File ending will be .tr so main.tr.
Syntax language will be turkish.
Now writing the tokenization stuff 🫩

0
0
5

Delete project?

Are you sure you want to permanently delete this project? This action cannot be undone.

All devlogs, followers, and associated data will be removed.

Followers

Loading…