Skip to content

Thomas-Mewily/simple_rust_repl_interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple interpreter in Rust.

This project is a simple virtual machine for executing expression, and a tiny programming langage using the Lisp S-expression syntax style that can be parsed and used into the virtual machine.

You can use it like an REPL for the moment (Read–eval–print loop) by typing expression in the terminal :

42
=> 42
(+ 1 2)
=> 3
(+ 1 (* 2 (+ 3 4))) 
=> 15
(& true false)
=> false
(if (== 1 2) 10 20)
=> 20

Strongly typed :

(& true 42)    
Expected `bool` instead of `42` for the 2 arg
> fn(bool, bool) -> bool

Currently support :

  • Integer,
  • Boolean,
  • If Else,
  • and user build in function from the source language

Adding new function/constant/definition from Rust into the virtual machine is easy :

self.add("zero", 0i32);

self.add("true", true);
self.add("false", false);

self.add("void", ());
self.add("bool", Kind::Bool);
self.add("i32", Kind::I32);
self.add("type", Kind::Kind);

self.add("+", |x: i32, y: i32| x + y);
self.add("*", |x: i32, y: i32| x * y);

self.add("&", |x: bool, y: bool| x & y);
self.add("|", |x: bool, y: bool| x | y);

self.add("!", |x: bool| !x);

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages