public void Execute_AddVariable_AddsToContext()
        {
            bool wasCalled = false;
            var  context   = new Mock <IContext>();

            context.Setup(c => c.AddVariable(ValueTypes.Bool, "tested")).Callback(() => wasCalled = true);

            var decl = new Declaration(ValueTypes.Bool, "tested");

            decl.Execute(context.Object);
            Assert.That(wasCalled);
        }
Esempio n. 2
0
        public static void RunFile(string path)
        {
            byte[] file  = File.ReadAllBytes(path);
            byte[] bytes = file.Skip(3).ToArray();
            LinkedList <IToken> lexout  = Lexer.Scan(bytes);
            Declaration         program = Parser.Parse(lexout);
            Scope s = new Scope(null);

            program.Resolve(s);
            program.Execute(s);
            while (true)
            {
                ;
            }
        }
Esempio n. 3
0
        public static void REPL()
        {
            Scope s = new Scope(true);

            while (true)
            {
                Console.WriteLine("<enter an expression>");
                string input = "";
                while (input.Length == 0 || input.Count((c) => c == '{') != input.Count((c) => c == '}'))
                {
                    input += Console.ReadLine();
                }
                byte[] bytes = Encoding.ASCII.GetBytes(input);
                try {
                    LinkedList <IToken> lexout  = Lexer.Scan(bytes);
                    Declaration         program = Parser.Parse(lexout);
                    program.Resolve(s);
                    //Console.WriteLine("Parsed: " + program.ToString());
                    if (program is Expression e)
                    {
                        Operand result = e.Eval(s);
                        if (!(result is null))
                        {
                            Console.WriteLine("Expression returned " + result);
                        }
                    }
                    else
                    {
                        program.Execute(s);
                    }
                } catch (OutletException ex) {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(ex.Message);
                    Console.ForegroundColor = ConsoleColor.White;
                } finally {
                    //s.Lines.Clear();
                }
            }
        }