Skip to content

erenworld/interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐟 Karp

Go Version License: MIT Dependabot Enabled

Karp is an interpreter for the Karp programming language, implemented in Go (Golang).

Karp is a small, expressive, C-like language built for learning and experimentation.
It is inspired by the book "Writing an Interpreter in Go".

Example code

let add = fn(x, y) { x + y };
add(2, 3);          // => 5

let makeAdder = fn(x) {
  fn(y) { x + y };
};

let addTwo = makeAdder(2);
addTwo(5);          // => 7

let result = !false;  // => true

let nums = [1, 2, 3, 4];
len(nums);            // => 4

let person = {"name": "Karp", "type": "fish"};
person["name"];       // => "Karp"

Architecture

Component Description
Lexer Converts raw source code into tokens
Parser Builds an AST using Pratt Parsing
Evaluator Interprets and executes the AST
Environment Stores variables and function scopes
Objects Defines data types like integers, booleans, strings, arrays, hashes

A program in Karp is a sequence of statements, such as:

  • let statements
  • return statements
  • Expression statements

Getting started

prerequisite golang 1.22+

On your terminal

go build -o .

then

./karp

About

The Karp Programming Language. Karp is a small and fast language.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published