Skip to content

cofffeen/itmoscript-interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ITMOScript Interpreter

A dynamically-typed interpreted programming language implemented in C++.

Overview

ITMOScript interpreter executes .is source files with features including first-class functions, lists, strings, and standard control flow constructs. The implementation follows a classic multi-pass architecture: Lexer -> Parser -> AST -> Tree-walking Evaluator.

Architecture

  • Lexer - Tokenizes source code (numbers, strings, identifiers, operators, keywords)
  • Parser - Recursive descent parser produces an AST with operator precedence
  • Interpreter - Tree-walking evaluator with dynamic typing and garbage collection via shared_ptr
  • Scope - Lexical scoping with parent chains for variable lookup and assignment

Language Features

  • Dynamic typing - Types checked at runtime, Python-like copy/value semantics
  • Data types - Numbers (double), strings, lists, booleans, nil, first-class functions
  • Operators - Arithmetic, comparison, logical (and/or/not), indexing/slicing
  • Control flow - if/else if/else, while, for-in loops, break/continue
  • Functions - First-class, higher-order, lexical closures, return statements
  • Comments - Single-line // comments

Standard Library

Math: abs, ceil, floor, round, sqrt, rnd, parse_num, to_string
Strings: len, lower, upper, split, join, replace
Lists: range, len, push, pop, insert, remove, sort
System: print, println, read, stacktrace

Building

cmake -B build
cmake --build build

Usage

#include "interpreter.h"

std::istringstream input("println(\"Hello, ITMOScript!\")");
std::ostringstream output;
interpret(input, output);

Requirements

  • C++17 or later
  • CMake 3.10+
  • Google Test (for unit tests)

Project Structure

File Description
lexer.h/lexer.cpp Tokenizer with keyword map
token.h/token.cpp/token_type.h Token types and values
ast.h AST node definitions (20+ node types)
parser.h/parser.cpp Recursive descent parser with precedence climbing
interpreter.h/interpreter.cpp Main evaluation loop and entry point
value.h Variant-based dynamic value type
scope.h/scope.cpp Lexical scope with parent chain
function.h User-defined function representation
standart_library_func.h/standart_library_func.cpp Built-in functions

Error Handling

All runtime errors (type mismatches, out-of-bounds access, undefined variables) throw exceptions caught by the interpreter, with stack trace support via stacktrace().

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors