Skip to content

Commit

Permalink
docs: improve README.md formatting and content
Browse files Browse the repository at this point in the history
  • Loading branch information
bytexenon committed Oct 4, 2024
1 parent 185d7a7 commit 7163166
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![Untitled](https://github.com/ByteXenon/TinyLua/assets/125568681/41cf5285-e31d-4b27-a8a8-ee83a7300f1f)
![Banner](https://github.com/ByteXenon/TinyLua/assets/125568681/41cf5285-e31d-4b27-a8a8-ee83a7300f1f)

***originally inspired by [The Super Tiny Compiler](https://github.com/jamiebuilds/the-super-tiny-compiler)***
***originally inspired by Jamie Kyle's [The Super Tiny Compiler](https://github.com/jamiebuilds/the-super-tiny-compiler) written in JavaScript***

**Welcome to The Tiny Lua Compiler!**

Expand All @@ -9,8 +9,9 @@ written in easy to read Lua code.

## Features

- **Self-compiling**: This compiler can compile itself!
- **Zero dependencies**: This compiler is written in pure Lua and has no dependencies.
- **Educational**: Reading through the guided code will help you learn about how *most* compilers work from end to end.
- **Self-compiling**: This compiler can compile itself!

### [Want to jump into the code? Click here](the-tiny-lua-compiler.lua)

Expand All @@ -22,6 +23,12 @@ That's fair, most people don't really have to think about compilers in their day
jobs. However, compilers are all around you, tons of the tools you use are based
on concepts borrowed from compilers.

### Why Lua?

Lua is a simple programming language that is easy to learn and use. It doesn't
have complex syntax or a lot of features, which makes it a great language to
make a compiler for.

### But compilers are scary!

Yes, they are. But that's our fault (the people who write compilers), we've
Expand All @@ -34,28 +41,24 @@ the nerds are able to understand.
Awesome! Head on over to the [the-tiny-lua-compiler.lua](the-tiny-lua-compiler.lua)
file.

### I'm back, that didn't make sense

Ouch, I'm really sorry. Let me know how it can be improved, by emailing me at [email protected] or opening an issue on this repo.

### Example usage?

Currently, the compiler only supports Lua 5.1. Here's an example of how you can use it:

```lua
local tlc = require("the-tiny-lua-compiler")

-- Compile the input code
local inputCode = [[
for index = 1, 10 do
print(index)
end
print("Hello, World!")
]]
local tokens = tlc.Tokenizer.tokenize(inputCode)
local ast = tlc.Parser.parse(tokens)
local proto = tlc.InstructionGenerator.generate(ast)
local bytecode = tlc.Compiler.compile(proto)

local tokens = tlc.Tokenizer.tokenize(inputCode)
local abstractSyntaxTree = tlc.Parser.parse(tokens)
local prototype = tlc.InstructionGenerator.generate(abstractSyntaxTree)
local bytecode = tlc.Compiler.compile(prototype)

local compiledFunction = loadstring(bytecode)

Expand All @@ -69,7 +72,4 @@ Run with `lua tests/test.lua`

---

[![cc-by-4.0](https://licensebuttons.net/l/by/4.0/80x15.png)](http://creativecommons.org/licenses/by/4.0/)
[![Open Source](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://opensource.org/)
[![LGBTQ+ Friendly](https://pride-badges.pony.workers.dev/static/v1?label=lgbtq%2B%20friendly&stripeWidth=6&stripeColors=E40303,FF8C00,FFED00,008026,24408E,732982)](https://lgbt.foundation/)
[![Transgender Flag](https://pride-badges.pony.workers.dev/static/v1?label=trans%20rights&stripeWidth=6&stripeColors=5BCEFA,F5A9B8,FFFFFF,F5A9B8,5BCEFA)](https://transequality.org/)
[![cc-by-4.0](https://licensebuttons.net/l/by/4.0/80x15.png)](http://creativecommons.org/licenses/by/4.0/)

0 comments on commit 7163166

Please sign in to comment.