https://github.com/shime/tiny-ruby-compiler
Super tiny compiler, written in Ruby, using TDD.
https://github.com/shime/tiny-ruby-compiler
Last synced: 7 months ago
JSON representation
Super tiny compiler, written in Ruby, using TDD.
- Host: GitHub
- URL: https://github.com/shime/tiny-ruby-compiler
- Owner: shime
- License: mit
- Created: 2018-01-10T19:52:17.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-10T19:56:41.000Z (over 8 years ago)
- Last Synced: 2024-12-27T15:26:20.640Z (over 1 year ago)
- Language: Ruby
- Size: 19.5 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Tiny Ruby Compiler
Super tiny compiler, written in Ruby, using TDD.
100% covered with tests.
Converts Lispy expressions to C-like expressions like so:
| Operation | Lisp | C |
| ----------------| -----------------------|------------------------|
| 1 + 1 | (add 1 1) | add(1, 1) |
| 4 - 2 | (subtract 4 2) | subtract(4, 2) |
| 2 + (4 - 2) | (add 2 (subtract 4 2)) | add(2, subtract(4, 2)) |
Compilers generally consist of 3 main parts:
* Parsing
* Transformation
* Code Generation
## Description
### Parsing
Parsing consists of two parts:
* Lexical Analysis - takes raw code and splits it apart into tokens (check out `Tokenizer`)
* Syntactic Analysis - takes the tokens and reformats them into AST (check out `Parser`)
### Transformation
Transformation consists of two parts:
* Traverser - traverseres the original AST and operates on it (check out `Traverser`)
* Transformer - transforms the original AST to another, suited for destination lanaguage (check out `Transformer`)
### Code Generation
Code generation consists of:
* Code Generator - converts the destination AST to runnable destination code (check out `Generator`)
## Development
Install dependencies
```
bundle install
```
Run tests with
```
rake
```
## Attributions
This repo is basically a port of [thejameskyle/the-super-tiny-compiler](https://github.com/thejameskyle/the-super-tiny-compiler) to Ruby.
Definitely check it out for more thorough deep dive into compilers.
## License
MIT