参考自索斯藤·鲍尔(Thorsten Ball)的《用GO语言自制解释器》
适合想体验GO语言+体验手撕解释器+恰好选中这门课程的同学作为参考
Referenced from Thorsten Ball's "Writing An Interpreter In Go", this project is not really suitable for implementing DSL
Suitable as a reference for students who want to experience the GOlang + experience writng an interpreter + have taken this course
A simple DSL, which helps you build your own bot. support basic data types, such as integer, boolean, string, array have builtin functions, such as len, first, last, rest, push support user defined function support if-else statement support user defined function Example for a simple program:
By setting env in your shell, awesomeDSL support openai-api, please check doc for more details.
the DSL is crazy simple, but it's enough for a simple bot
let question_without_space
= variable, function call, if-else statement, builtin function
when you type question, the bot will answer you with value at right of =
for example,
with let a = 1
, when you type 'a', the bot will answer you with '1'
for more examples, please check in examples
//builtin function
let hello = puts("hello world");
//variables
let a = 1;
let b = 2;
let c = true;
let d = "hello world";
//define function
let add = fn(x, y) {
x + y;
};
//call function
let result = add(a, b);
//if-else statement
let tellmeresult= if (result > 0) {
"result is positive";
} else {
"result is negative";
};
//array
let arr = [1, 2, 3];
//array builtin function
let first = first(arr);
let last = last(arr);
let rest = rest(arr);
//array push
let arr2 = push(arr, 4);
//array len
let len = len(arr2);
//array index
let index = arr2[0];
//string concat
let len = "hello"+" world";
you can check the doc for more details.
go build main.go
./main <your_script.txt>
bubbletea build tui by this framework.
vhs The gifs in this repo were all made by this tool;
gomarkdoc This generate doc in .md.
go-openai This to support openai-api.
And the most important, author of Writing An Interpreter In Go.
Generated by gomarkdoc