예제 #1
0
 private void RegisterFunction(bool builtIn, string name, Func <Exp> compileBody)
 {
     try
     {
         var body = compileBody();
         functions[name] = new SkiFunction(name, functions[name].Id, functions[name].ArgsCount, body.Unlambda().Simplify(), builtIn);
     }
     catch (Exception e)
     {
         throw new Exception($"Can't parse {name}. {e.Message}", e);
     }
 }
예제 #2
0
 private static SkiFunction ParseFunction(string line, Dictionary <string, SkiFunction> functionsDir)
 {
     try
     {
         var parts       = line.Split(" = ");
         var body        = Parser.ParseSKI(parts[1].Trim(), n => new KnownFunction(new Lazy <SkiFunction>(() => functionsDir[n])));
         var name        = parts[0].Trim();
         var skiFunction = new SkiFunction(null, name, 0, body, false);
         functionsDir.Add(name, skiFunction);
         return(skiFunction);
     }
     catch (Exception exception)
     {
         throw new Exception($"{line}", exception);
     }
 }