Esempio n. 1
0
        public static void DoTests()
        {
            Console.WriteLine("DoTests");

            Console.WriteLine(">----------------------------------------------------------<");
            var content = "(require lang)\n(map 1 2 3)\n(print \"test\")";
            var atom    = BombardoLang.Parse(content);

            Console.WriteLine($"Parse:\n\n{content}\n\n");
            Console.WriteLine($"Results:\n\n{atom}\n\n");
            Console.WriteLine(">----------------------------------------------------------<");
        }
Esempio n. 2
0
        private static void FromString(Evaluator eval, StackFrame frame)
        {
            var  args = frame.args;
            Atom str  = (Atom)args.value;

            if (!str.IsString)
            {
                throw new ArgumentException("Argument must be string!");
            }
            Atom list = BombardoLang.Parse((string)str.value);

            eval.Return(list);
        }
Esempio n. 3
0
        private static void Parse(Evaluator eval, StackFrame frame)
        {
            Atom text = frame.args?.atom;

            if (text.type != AtomType.String)
            {
                throw new ArgumentException("Argument must be string!");
            }

            try
            {
                var list = BombardoLang.Parse((string)text.value);

                eval.Return(list);
            }
            catch
            {
            }

            eval.Return(null);
        }
Esempio n. 4
0
        private static void Load(Evaluator eval, StackFrame frame)
        {
            Atom args = frame.args;

            Atom path = (Atom)args?.value;

            if (path == null || !path.IsString)
            {
                throw new ArgumentException("Path must be string!");
            }

            string file = (string)path.value;

            if (File.Exists(file))
            {
                string raw   = File.ReadAllText(file);
                Atom   nodes = BombardoLang.Parse(raw);

                eval.Return(nodes);
                return;
            }

            eval.Return(null);
        }
Esempio n. 5
0
        public static void Main(string[] argsArray)
        {
            // Мне тут нужны:
            // Путь до интерпретатора
            // Путь до ядра (бут-скрипт)
            // Путь до исполняемого скрипта

            string pathToApp           = System.Reflection.Assembly.GetEntryAssembly().Location;
            string basePath            = Path.GetDirectoryName(pathToApp);
            string pathToBoot          = Path.Combine(basePath, "bombardo.boot.brd");
            string pathToScript        = null;
            string pathToWorkDirectory = Directory.GetCurrentDirectory();

            var args = new Queue <string>(argsArray);

            while (args.Count > 0)
            {
                var arg = args.Dequeue();
                if (arg.StartsWith("boot:"))
                {
                    pathToBoot = Path.GetFullPath(arg.Substring(5));
                    continue;
                }
                pathToScript = Path.GetFullPath(arg);
            }

            if (args.Count > 0)
            {
                Console.WriteLine($"Too match arguments!\nWill be ignored: {string.Join(" ", args)}");
            }

            pathToBoot = FSUtils.FindFile(pathToBoot);

            if (string.IsNullOrEmpty(pathToBoot))
            {
                Console.WriteLine($"File not found: {pathToBoot}");
                return;
            }

            var bootScript = File.ReadAllText(pathToBoot);

            var bootContext = BuildBootContext();

            bootContext.Define("pathToApp", CreateString(pathToApp));
            bootContext.Define("basePath", CreateString(basePath));
            bootContext.Define("pathToBoot", CreateString(pathToBoot));
            bootContext.Define("pathToScript", CreateString(pathToScript));
            bootContext.Define("pathToWorkDirectory", CreateString(pathToWorkDirectory));
            bootContext.@sealed = true;
            bootContext         = new Context(bootContext);

            var bootProgram = BombardoLang.Parse(bootScript);

            var  eval       = new Evaluator();
            Atom bootResult = null;

            try
            {
                bootResult = eval.Evaluate(bootProgram, bootContext, "-eval-block-");
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc);
                Console.WriteLine();
                eval.Stack.Dump();
            }

            Console.WriteLine($"{bootResult}");
        }