DEV Community

aiocat
aiocat

Posted on

5 1

I made a programming language without any knowledge.

Hello folks! I decided to make a minimal programming language... without any knowledge...

Starting

For this challenge, I chosed C++ because its fast. I would chose rust but i will rewrite with rust later.

And i started to searching about making a programming language, and i got some basics about lexers, compilers etc... and I started with reverse polish notation and stack based language. Because they are easy to implement.

Writing a Lexer

Lexer is the simplest part of writing a language, just tokenizing the keywords.

Lexer

I didn't use any lexer generator (like lex) because its better to make it from zero for me. But the worst part of it, I DON'T KNOW C++. And thats why it was a bit torture to me. I still think the lexer i wrote sucks because i made it without any C++ knowledge. But, atleast it works :D

50 100 + put
Enter fullscreen mode Exit fullscreen mode

=> (pseudo)

[
    {token: NUMBER, value: "50"},
    {token: NUMBER, value: "100"},
    {token: ADD, value: ""},
    {token: PUT, value: ""}
]
Enter fullscreen mode Exit fullscreen mode

Compiler? Transpiler?

After writing a lexer, i need to make a compiler/transpiler for my project. (i skipped AST since it doesn't need.) I checked LLVM but its really deep project to dive in so i tried with assembly. And another problem, i don't know assembly too! and i decided to make a C++ transpiler for my language.

It transpiles the code into C++ and runs g++ to compile the C++ source.

Trying the Language

I wanted to test the limits of the language, So i made a brainfuck compiler in my language. I think its best project to test your language too.

Features

After some days, i added tons of things to my language. It was really fun!

Features

Documentation

And the most boring thing in programming scenario... Writing a documentation! Well, i think nobody likes that but everyone needs that too. So i wrote a simple language reference for my programming language.

Finishing

So, that was my adventure about creating a minimal programming language. If you liked the project, you can star on GitHub page!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (1)

Collapse
 
ivanbozhkov profile image
Ivan Bozhkov

Ok

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay