Skip to content

dcstone09/interpreter

Repository files navigation

KekoLang Interpreter

A Ruby implementation of a programming language interpreter based on Thorsten Ball's "Writing An Interpreter In Go".

Overview

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.

Development Setup

Prerequisites

  • Ruby 3.4.4 or higher
  • Bundler

Installation

# Clone the repository
git clone https://github.com/dcstone09/interpreter.git
cd interpreter

# Install dependencies
bundle install

Running Tests

# 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"

Code Quality

# Run RuboCop linter
bundle exec rubocop

# Auto-fix RuboCop violations
bundle exec rubocop -A

Project Structure

interpreter/
├── 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

Language Features (Planned)

  • Variables and assignment
  • Integer arithmetic
  • Functions
  • Conditionals (if/else)
  • Basic built-in functions

Token Types

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

Example Code (Planned)

let x = 5;
let y = 10;
let add = fn(a, b) {
  a + b;
};
add(x, y);

Contributing

This is a learning project. Feel free to experiment and extend the language with new features!

License

This project is for educational purposes.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages