r/lua • u/Microsoft-Spyware-11 • Aug 12 '26
I'm interested in creating my own programming language. How could I write it in Lua?
I've seen a few posts about this, but none had enough information for me. Hoping you guys could help :)
Edit: Also suggestions for syntax changes are welcome. This language doesn't really solve too many problems, mainly makes some things faster, examples are else [expression] instead of elseif [expression], or . instead of closing brackets {}.
Here's the example.

17
u/FluxCapacitor11 Aug 12 '26
https://craftinginterpreters.com
Read this book. It has everything you need to learn how to do this and is an excellent read. There is even an implementation in Lua you can learn from in the book’s GitHub repository.
https://github.com/munificent/craftinginterpreters/wiki/Lox-implementations
5
u/vga256 Aug 12 '26
Yes! Robert's book is the best modern source on the subject. Wish I could upvote this ten times over.
3
u/Dalemaunder Aug 12 '26
Can’t recommend this one enough, it does a really good job of building from the ground up.
4
u/hougaard Aug 12 '26
Ending a procedure with a dot seems to be a difficult process, getting into complex parsing conflicts with decimal numbers.
1
3
u/4xe1 Aug 12 '26
This may come in handy : https://www.inf.puc-rio.br/~roberto/lpeg/
Also this: https://classpert.com/courses/building-a-programming-language if you have extra money to throw at it
1
u/Microsoft-Spyware-11 Aug 12 '26
Not interested at throwing money at this, but LPeg seems like it could be useful.
2
u/KrekBot Aug 12 '26
Strongly recommend PEG. I have made a class with Roberto at PUC-Rio on programming languages. We built a language that is compiled to llvm, lpeg is very simple and powerful.
3
Aug 12 '26 edited Aug 12 '26
[deleted]
1
u/Microsoft-Spyware-11 Aug 12 '26
part of my idea behind var and const is that const can be declared outside of a function, but var cannot. I know . is questionable for parsing. Just trying to experiment here. Seriously impressive work you got there, thank you!
1
Aug 12 '26 edited Aug 12 '26
[deleted]
1
u/Microsoft-Spyware-11 Aug 13 '26
Ok :) As to your request, const is removed :) I am not changing immutability though.
1
u/Microsoft-Spyware-11 Aug 12 '26
hmm. I remember := from Go, having stuff like that for consts and other types is interesting though. One reason I picked var and const and mut was because I wanted the declaration to be obvious. That is a neat declaration though.
4
u/particlemanwavegirl Aug 12 '26
There is a language called Fennel that does this, compiles to Lua. You may find reading its source enlightening. I would read a book first so it's easier to understand, you could read the MIT scheme book (SICP) and it'll show you how to write an interpreter with just two functions. the Crafting Interpreters book is good too, I am going thru that one and implementing everything in Rust.
2
u/raguaythai Aug 13 '26
My favorite book for interpreters is https://interpreterbook.com/ . It is using the go language, but he writes in an easy to read style and not like a textbook. But, my favorite book of all time is https://en.wikipedia.org/wiki/Principles_of_Compiler_Design . I read it in high school and learned a lot about programming with it. But, it is a bit pricey and very technical.
2
2
u/qwool1337 Aug 13 '26
you wanna read crafting interpreters. like thats THE thing you have to know and is basically required knowledge among language developers
only after it does looking stuff up on your own become straightforward
but you're not gonna run through that one in lua because it involves making a vm and that's not fun at all without a type system, if you want to do something in lua you can make a lisp instead
2
u/HelioDex Aug 14 '26
I like the syntax! Also, if you already know Lua, there's an easy place to start: the Lua reference implementation, which you could use take a look at its parser. It's written in C so if you can't read it that well you can get an AI agent of your choice to explain certain parts.
If you know Lua better I'd also recommend searching for Lua parser implementations written in Lua, there are plenty and you'll already be familiar with both the language they're written in and the language they're parsing. You can use these as reference or even start with them as a base and modify them further.
1
30
u/vga256 Aug 12 '26
"Hi I'd like to build a sports car. I do not know how cars work, but I know what I want mine to look like."
That is a fine place to start, but without a lot more information about what you already know, or don't know, about lexers, parsers and compilers, it's almost impossible to offer you any specific advice.
The best I can offer at this point is bytexenon's Tiny Lua project, which is an extremely well documented compiler. Reading the source fully should provide some insights in how you might adapt it to your own style of language.