Skip to content

Latest commit

 

History

88 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tiper

Tiper (Tiny Interpreter) is a Rust-based interpreter implementation with lexical analysis, parsing, and evaluation capabilities. This project is an educational implementation of an interpreter in Rust.

Overview

Tiper is an interpreter that processes source code through multiple stages:

  • Tokenization - Converts source code into tokens
  • Parsing - Builds an abstract syntax tree (AST) from tokens
  • Evaluation - Executes the parsed expressions and statements

Features

Lexical Analysis

Tokenizes source code with support for:

  • Arithmetic operators (+, -, *, /)
  • Comparison operators (==, !=, >, <, >=, <=)
  • Logical operators (!, &&, ||)
  • Literals (numbers, strings, booleans, nil)
  • Identifiers and keywords
  • Comments (single-line)

Parsing

Implements recursive descent parsing with operator precedence for:

  • Arithmetic expressions
  • Comparison expressions
  • Logical expressions
  • Grouping expressions
  • Variable assignments

Execution

Evaluates expressions and executes statements including:

  • Print statements
  • Variable declarations
  • Block statements
  • Expression statements

Project Structure

src/
├── main.rs          # Entry point and CLI interface
├── tokenize.rs      # Lexical analysis (tokenizer)
├── parse.rs         # Parser and expression handling
├── types.rs         # Type definitions (tokens, expressions, statements)
├── evaluate.rs      # Expression evaluation
├── statement.rs     # Statement parsing and execution
└── scope.rs         # (Incomplete) Environment/scope management

Usage

# Tokenize a file
tiper tokenize filename.txt

# Parse and display AST
tiper parse filename.txt

# Evaluate expressions
tiper evaluate filename.txt

# Run the program
tiper run filename.txt

Supported Syntax

  • Variable declaration: var x = 5;
  • Print statements: print "Hello, world!";
  • Arithmetic: 1 + 2 * 3
  • Comparisons: a > b
  • Logical operations: !true
  • Grouping: (1 + 2) * 3
  • Blocks: { var x = 1; print x; }

Error Handling

The interpreter provides detailed error messages with line numbers for:

  • Syntax errors
  • Type errors
  • Undefined variables
  • Division by zero

Current Limitations

  • Basic variable scoping (scope.rs is marked as "TODO")
  • Limited control flow (no if/while statements implemented yet)
  • Basic function support

Building

cargo build
cargo run -- tokenize example.txt

License

DO WHAT YOU WANT

About

Tiny Rust-based interpreter implementation with lexical analysis, parsing, and evaluation

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages