-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: improve README.md formatting and content
- Loading branch information
Showing
1 changed file
with
16 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
 | ||
 | ||
|
||
***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!** | ||
|
||
|
@@ -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) | ||
|
||
|
@@ -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 | ||
|
@@ -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) | ||
|
||
|
@@ -69,7 +72,4 @@ Run with `lua tests/test.lua` | |
|
||
--- | ||
|
||
[](http://creativecommons.org/licenses/by/4.0/) | ||
[](https://opensource.org/) | ||
[](https://lgbt.foundation/) | ||
[](https://transequality.org/) | ||
[](http://creativecommons.org/licenses/by/4.0/) |