DEV Community

Chad Windham
Chad Windham

Posted on

What Are Some Good Starting Points to Learn What I Need to Write My Own Toy Language?

image of scratch code in action
So, I asked this question in the comments section of somebody else's post. Then I realized, if I turn my question into a post it may reach a larger number of people! So below I have shamelessly copy pasted the question verbatim. LEND ME YOUR BOTTOMLESS WISDOM DEV.TO COMMUNITY!

So I'm pretty new to the development world. But ever since I started I've wanted to make a toy language of sort as a side project/learning experience. Do you have any advice on how to get started with that? I'm pretty limited on the computer science side of things. I'm an active web developer with experience of only high level languages (both interpreted and compiled). I plan on getting an Arduino simply to play with some Assembly code. I've read the book Code: the hidden language of computer hardware and software and more or less understood the information it presented. (Sometimes much closer to the less side of things...). I became a web developer via a boot camp. And while it was great and did give me the chance to acquire the skillset to jump directly into the workforce. There is SO MUCH MORE I WANT TO DO AND LEARN! The two primary things I want to accomplish in the near future are:

  1. - Write a toy language
  2. - Use relays to create a 4-bit adding machine called "The Nybbler" (get it?)

Learning how to do stuff Rick and Morty style

I'm not somebody who sits around with a bunch of pipe dreams. When I want to do something I go and I try to do it. So if anybody has some good starting point advice on making a toy language. It would be very, very appreciated.

Here is the article that inspired the question BTW...

Top comments (12)

Collapse
 
grahamlyons profile image
Graham Lyons

This isn't necessarily your own language but it might be good to get you started: buildyourownlisp.com/

It'll certainly be a good introduction to all the required parts and doubtless you could adapt and extend it once you've got a handle on it. Plus, Lisps are super cool.

Collapse
 
vitalcog profile image
Chad Windham

WOW! That looks borderline perfect actually! Thankyou

Collapse
 
davidszabo97 profile image
Dávid Szabó

Good. You are on the right path mate. I have my own toy language too: github.com/david-szabo97/DevLang
You might take a look at it how it works.
You can find comments,tests and examples in the Main.java

You get started by doing some Google searches. Keywords: interpeter, compiler, parser, lexer, opcode, virtual machine.

I used to read a blog series to put together my own language.
Maybe this one: aosabook.org/en/500L/a-python-inte...
But I am not sure anymore. It was 2 year ago :)

Good luck!

Collapse
 
davidszabo97 profile image
Dávid Szabó • Edited

I also have some special feature in my toy lanuage: (I have no idea how I did it, my lang contains some secrets.)


for (i = 0; i < 5; for (j = 0; j < 5; j = j+1) {print('j')} i=i+1) {print('i')}

Yes, that's a for in a for.

Collapse
 
vitalcog profile image
Chad Windham

Thanks! The link to the python interpreter is great actually! Also appreciate the keywords list

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y

Maybe I should write up my experiences with various languages, the ones that built to Leaf. Get some final value out of that project of mine.

Collapse
 
vitalcog profile image
Chad Windham

Seems legit. I for one would appreciate it. And I'm sure a ton of other up and coming devs would too.

Collapse
 
cjbrooks12 profile image
Casey Brooks

I just started down this road myself! There's some great links and advice here already, I'll definitely be following along for more!

I've started my journey in writing compilers by first understanding how to write a good parser. I'm writing it all in Kotlin as a combinatorial Recursive Descent Parser (inspired by Haskell's Parsec, and some work I did in college), and have the parser and base functionality of evaluating an AST complete. My next step is parsing complex expressions, and then putting it all together into a toy language.

copper-leaf / kudzu

A monadic (I think...) recursive-descent parser written in Kotlin

Kudzu


A monadic (I think...) recursive-descent parser written in Kotlin

Build Status Codacy Project Grade Code Coverage

Kudzu is a recursive-descent parser written in Kotlin, with the goal of immutability and simplicity. It is mostly an exercise for me to learn more about parsing algorithms, but should work reasonably-well enough to be used for small non-trivial parsers.

Why did I write it?

I've got several projects which require custom parsing, and after looking around at the various options available in Java and Kotlin, I've decided that I would just rather write my own. Most of the ones I found either require Java 8 (a deal-breaker if I want to use it on Android), or I found them to be very complex to use, being intended for writing full-blown, high-performance compilers. I needed something simple, and I also wanted to learn how parsers work, so I decided to make my own.

This library is a parser combinator like…

Collapse
 
k4ml profile image
Kamal Mustafa

I collected some links here metak4ml.blogspot.com/2017/06/how-...

Collapse
 
vitalcog profile image
Chad Windham

That is a really useful collection! Will take some time to read through but looks super helpful for what I need. I appreciate it!

Collapse
 
vitalcog profile image
Chad Windham

I'm really impressed with how helpful everyone has been on this. I went from not knowing where to start to having almost too much good info to sort through just from 3 responses! Thank you everyone for you help!

Collapse
 
liana profile image
Liana Felt (she/her)

It really should ping @mortoray right when the post is embedded. If only someone would have written that feature. 🤔