Skip to content
/ expr Public

sandboxed language that only consists of call expressions

Notifications You must be signed in to change notification settings

intervinn/expr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

this is an academy exam project ive made in 2 days

i've previously had other parsers and lexers in work, and as for this one - it's not the cleanest one, but one of the most complete ones

i think i wont touch c# for any time soon after this one

the entire point is to make the language minimal and easy to embed into programs, there are no globals except for the one you define, and there is no other syntax other than calls and string/int literals

public class Program {
    public static void Main() {
        var state = new State();
        state.PushFunction("print", (args, stack) => {
            Console.WriteLine(args[0]);
            return new VoidValue();
        });

        state.PushFunction("set", (args, stack) => {
            var key = args[0].ToString();
            var value = args[1];

            stack[key] = value;

            return new VoidValue();
        });

        state.PushFunction("get", (args, stack) => {
            var key = args[0].ToString();
            var result = stack[key];
            return result;
        });

        state.PushFunction("message", (args, stack) => {
            return new StringValue("hello, world");
        });

        state.DoString("set(\"count\", 10);print(get(\"count\"))");
    }
}

About

sandboxed language that only consists of call expressions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages