redfloyd

redfloyd

Writing an interpreter in Elixir

Greetings fellow alchemists !

I have started to write an open-source interpreter in Elixir (https://github.com/nicolasdilley/dwarf-interpreter) one week ago and I decided to write some tutorials on each stage of the development of my new language. I have finished the first one on the lexer. If you are interested in interpreters or even compilers these tutorials would give you a good practical approach to write your own !

You can find these tutorials on my website : http://nicolasdilley.com/?p=1 I would love to have your opinion !

The language is called “Dwarf” and has already lots of functionalities. The next steps are implementing loops, a type system and a good stdlib. If you want to contribute on it feel free to pm me

Most Liked

OvermindDL1

OvermindDL1

Yay another person making interpreters on the beam! We are getting quite a collection, from a couple of lisps to a multitude of typed languages to a beam native Lua to others. I love seeing blogs about the actually design though, looking forward to updates! :smile:

OvermindDL1

OvermindDL1

Yep, recursive decent split lexical parsing steps is very classical, PEGs became more popular about 15 years ago, but they are not taught in schools or anything yet so few know about them, even though they are significantly better designs in my opinion, they can act as a lexer, a parser, both, an AST builder, an AST runner, any mix thereof, all with near the same code, while if implemented properly will run circles around the classical methods in speed while being far easier to read. :slightly_smiling_face:

redfloyd

redfloyd

Thanks @Qqwy !
I am actually writing this language just to be a very simple and small language ( hence the name :smiley: ). The aim is not to make anything new or fancy but to show a practical way of writing an interpreter. I found that when I wanted to learn how to build one, I could not find many practical advice and examples. In addition, I wanted to put in practice the theory that I am learning :slight_smile: My area of interest is concurrency so I might use it to test some ideas in the future. For the syntax rules, you can see a definition in BNF form of the language in the README. There are also examples of source program in the benchmarks folder.

OvermindDL1

OvermindDL1

I know, but PEGs remove the need for the lexical analyzer entirely while making everything far more readable and faster as well. :slightly_smiling_face:

OvermindDL1

OvermindDL1

What kind of reference are you wanting? The Wikipedia article (I’m on phone or is be giving substantially more direct links) talks about the basics well enough, but actual implementations are a bit different. C++'s Spirit PEG library is easily the fastest one in the world and will not be best due to its unique code generation, but it is easily the most powerful form out too with the most abilities except streaming parsing (but you can implement that yourself via a custom iterator or a thread anyway, it can even reverse a custom format back to strings too, or parse binary, or whatever, its PEG engine can parse back and forth between streams of anything to custom data structures of anything). There is one standalone generator it somewhere that can generate PEGs via a custom PEG language that compile to a whole host of languages, forgot it’s name but it’s been around for a long long time and it’s decently fast. There are many blogs about it as well and a few papers. What do you prefer? Or can Google for Parsing Expression Grammers. :slightly_smiling_face:

Where Next?

Popular in Guides/Tuts Top

njwest
Greetings: I just wrote a step-by-step guide on building a Phoenix 1.3 JWT Auth API with Guardian JWTs and Comeonin password hashing. I ...
New
marcelo
I wrote a small article on how to use current_user with coherence on Phoenix. There are already a couple of blogposts about it but I thin...
New
jshprentz
Geoffrey Lessel’s 2019 book, Phoenix in Action, was written for Phoenix 1.4. I found that the book’s code examples did not match the cur...
New
kokolegorille
Hello dear alchemists, There was this question some days ago here about the deployment to a VPS. As I was in the process of deploying t...
New
wfgilman
I'm writing up this quick "How to" because what I thought was going to be an easy implementation of a Plug to validate a webhook request ...
New
dogweather
I just finished a long process of configuring and debugging a Docker Compose-based dev environment. Several late-night hours! I think I’v...
New
Eiji
Hey, today I give amnesia library a try and found a few problems. I would like describe how to setup it properly and solve problems which...
New
AstonJ
This was originally posted on my blog, but since my I’ve taken it down (I hadn’t posted anything on it for a while and since it was runni...
New
bluegene
Hi guys, I’ve been on a personal journey to learn Elixir for the past two years. During this journey I’ve been using the spaced repetiti...
New
dennisreimann
I wrote a guide for implementing Passwordless Authentication a.k.a. "Magic Login Links": Feedback welcome!
New

Other popular topics Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement