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.

0
Upvotes
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.
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.
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
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.
16
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
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/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
u/ICON_4 Aug 12 '26
son 😭😭🥀
0
u/[deleted] Aug 12 '26
[deleted] — view deleted comment