yes-lang

Crates.ioyes-lang
lib.rsyes-lang
version0.1.0
sourcesrc
created_at2021-08-02 20:30:00.060697
updated_at2021-08-02 20:30:00.060697
descriptionYet anothEr Scripting Language
homepagehttps://github.com/sergey-melnychuk/yes-lang
repositoryhttps://github.com/sergey-melnychuk/yes-lang
max_upload_size
id430692
size70,995
Sergey Melnychuk (sergey-melnychuk)

documentation

https://github.com/sergey-melnychuk/yes-lang

README

yes-lang

Yet anothEr Scripting Language

Simple interpreter in Rust:

  • "manual" tokenization
  • single-/multi-line comments
  • prefix & infix operators
  • Pratt parser impl
  • tree-walking interpreter
  • immutable scope-based bindings
  • functions as a first class citizens
  • lexer, parser, interpreter & REPL in <2k LoC

Goals:

  • learn by doing
  • easy to understand
  • easy to implement
  • easy to follow
  • test coverage

Non-goals:

  • IO
  • stdlib
  • safety
  • collections
  • performance
  • type-safety
  • production-readiness
  • usability in general

REPL

$ cargo run
[...]
REPL: enter :q to quit.
> let hi = fn(name) { "hello " + name };
[AST]
<function>
> hi("world")
[AST]
hello world
> :q
$

Run

// examples/fib.yes

fn fib1(n, a, b) {
    if n == 0 { a+b }
    else { fib1(n-1, a+b, a) }
}

fn fib(n) {
    if n <= 0 { 0 }
    else {
        if n <= 2 { 1 }
        else {
            fib1(n-2, 1, 0)
        }
    }
}

fib(42) == 267914296 && fib(84) == 160500643816367088

$ cargo run examples/fib.yes
[...]
true
Commit count: 28

cargo fmt