A Ruby implementation of a programming language interpreter based on Thorsten Ball's "Writing An Interpreter In Go".
KekoLang (named after "keko", meaning monkey in Hawaiian) is an interpreted programming language designed to explore language implementation concepts. This project follows the structure of Ball's book but implements the interpreter in Ruby to deepen understanding of Ruby's features and idioms.
- Ruby 3.4.4 or higher
- Bundler
# Clone the repository
git clone https://github.com/dcstone09/interpreter.git
cd interpreter
# Install dependencies
bundle install# Run all tests
bundle exec rspec
# Run specific test file
bundle exec rspec spec/keko_lang/token_spec.rb
# Run tests matching a pattern
bundle exec rspec -e "Token"# Run RuboCop linter
bundle exec rubocop
# Auto-fix RuboCop violations
bundle exec rubocop -Ainterpreter/
├── lib/
│ └── keko_lang/
│ ├── lexer.rb # Tokenizes source code
│ └── token.rb # Token types and definitions
├── spec/
│ ├── keko_lang/
│ │ ├── lexer_spec.rb # Lexer tests
│ │ └── token_spec.rb # Token tests
│ └── spec_helper.rb # RSpec configuration
├── .gitignore # Git ignore rules
├── .overcommit.yml # Git hooks configuration
├── .rspec # RSpec options
├── .rubocop.yml # RuboCop linting rules
├── .ruby-version # Ruby version (3.4.4)
├── Gemfile # Ruby dependencies
├── Gemfile.lock # Locked dependencies
├── Rakefile # Build tasks
└── README.md # This file
- Variables and assignment
- Integer arithmetic
- Functions
- Conditionals (if/else)
- Basic built-in functions
The lexer recognizes the following token types:
- Literals:
INT,IDENT - Operators:
ASSIGN(=)PLUS(+)MINUS(-)BANG(!)ASTERISK(*)SLASH(/)LT(<)GT(>)EQ(==)NOT_EQ(!=)
- Delimiters:
COMMA,SEMICOLON,LPAREN,RPAREN,LBRACE,RBRACE - Keywords:
FUNCTION(fn)LET(let)TRUE_VAL(true)FALSE_VAL(false)IF(if)ELSE(else)RETURN(return)
- Special:
EOF,ILLEGAL
let x = 5;
let y = 10;
let add = fn(a, b) {
a + b;
};
add(x, y);
This is a learning project. Feel free to experiment and extend the language with new features!
This project is for educational purposes.