Git Product home page Git Product logo

mydsl's Introduction

DSL For Programming Practice (BUPT)

暂时就叫“波普特鼠人客服/解释器”🤔

⚠️本项目为北京邮电大学《程序设计实践》课程所要求课程设计,这个项目并不适合真的来实现DSL,小幅修改+强行解释作为课程大作业,但涵盖了课程设计中的大部分要求

参考自索斯藤·鲍尔(Thorsten Ball)的《用GO语言自制解释器》

适合想体验GO语言+体验手撕解释器+恰好选中这门课程的同学作为参考

⚠️ This project is a course design required for the "Programming Practice" course at Beijing University of Posts and Telecommunications (BUPT)

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

9288bb6079791eefac2cb65121acca71

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";

Documentation

you can check the doc for more details.

Quick Start

go build main.go

./main <your_script.txt>

example

thanks to those 🙏

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

mydsl's People

Contributors

ye-rm avatar

Stargazers

Yongxin Zhang avatar

Watchers

 avatar

Forkers

x-tfrk

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.