Hey! I'm willing to create a programming language using nim.

It's an educational project. Been reading about compilers for weeks now and I started using tools like flex and bison for lexer and parser. I know nim have a parsing library but nowhere near that level.

There is an old post (2014) with a similar question so I'm bringing that back a few years later. Is there anything anyone know that could speed up the process of developing a programing language using nim? (I can have c code if needed ofc)

2018-05-07 18:44:38

Wow, I was just reading about the compilation pipeline today!

I suppose you could use at least the lexing part from a generator like flex, not so sure about using AST generators easily (it's possible).

Is your language complicated enough to warrant a parser generator or could you just use a custom parser?

2018-05-08 01:29:02

For educational project, parse it by hand

Parser for s-expression like Lisp families are easy to write

Afaik, there's no lib in Nim specifically for that tho.

2018-05-08 06:44:17

Here are a few resources:

The JSON module: https://github.com/nim-lang/Nim/blob/master/lib/pure/json.nim#L150

The lexbase module: https://nim-lang.org/docs/lexbase.html

Spry-lang, a Smalltalk/Rebol like language written in Nim. It leverages Nim lexer and operates directly on Nim AST.

PMunch also has a lot of parsers in his repo but I think binary parsers only: https://github.com/PMunch?tab=repositories

Basically Nim object variant (kind objects) are your best friends.

2018-05-08 07:31:10
I have been using Nim to write an interpreter for a toy language named "Lox". Its been a fun project so far. https://github.com/cabhishek/nimlox
2018-05-08 23:22:54

For educational project, parse it by hand

For educational and serious project, parse it by hand (Nim parser is handwritten, as is GCC, Clang, MSVC, FPC, OpenJDK, Golang and many others). Use tools only for quick and dirty one 😉

2018-05-11 19:28:03

Is it really that worth to lex and parse by hand?

I've sent you an email @cabhishek!

2018-05-15 10:03:08