Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/whiteblackgoose/ohnolisp
C# implementation of something looking like Lisp idk, too lazy to read the wikipage about what LISP is
https://github.com/whiteblackgoose/ohnolisp
Last synced: 18 days ago
JSON representation
C# implementation of something looking like Lisp idk, too lazy to read the wikipage about what LISP is
- Host: GitHub
- URL: https://github.com/whiteblackgoose/ohnolisp
- Owner: WhiteBlackGoose
- License: cc0-1.0
- Created: 2022-01-08T19:57:00.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-08T20:20:14.000Z (almost 3 years ago)
- Last Synced: 2024-10-19T18:47:07.535Z (30 days ago)
- Language: C#
- Size: 13.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Oh, no! LISP
C# implementation of something looking like Lisp idk, too lazy to read the wikipage about what LISP is.
It only supports commands `add`, `mul`, and `print` and integers as values.
So um, it has tokens, lexer, AST, parser, interpreter, and compiler to IL.
## What it can
E. g. take this code:
```cs
var source = @"
(add
(mul 3 b)
a
)
)
";
```Now let's create lexer for it:
```cs
var lexer = new OhnoLexer(source);
```We can go over it with `lexer.Eof` and `lexer.Next()`, but we can just trust the parser:
```cs
var parser = new OhnoParser();
var ast = parser.Parse(lexer);
````ast` is of type `INode` which can be `Command`, `Integer`, or `Variable`.
Now we can run an interpreter of our AST passing in the values of arguments:
```cs
var interpreter = new OhnoInterpreter();
interpreter.Run(ast, new() { ["a"] = 5, ["b"] = 10 });
```Or we can compile it to IL and run the delegate:
```cs
var compiler = new OhnoCompiler();
Func func = compiler.Compile(ast, "a", "b");
func(5, 10);
```## Why???
Because how else would you spend an evening???
Wrote this thing in 1.5 hour, gotta get back to reading a book.