Example #1
0
        static void Main(string[] args)
        {
            if (args.Length != 0)
            {
                using (StreamReader reader = new StreamReader(args[0]))
                {
                    var parser = new Parser();
                    var output = parser.BuildExpressionTree(parser.Tokenize(parser.Split(reader.ReadToEnd())), 0);

                    var interpreter = new Interpreter(output);
                    interpreter.LoadLibrary(StandardLibrary.Load);
                    var timer = Stopwatch.StartNew();
                    interpreter.Run();
                    timer.Stop();
                    Console.WriteLine("Time spent: " + timer.ElapsedMilliseconds);
                }
            }
            else
            {
                using (StreamReader reader = new StreamReader("samples/sandbox.hy"))
                {
                    var parser = new Parser();
                    var output = parser.BuildExpressionTree(parser.Tokenize(parser.Split(reader.ReadToEnd())), 0);

                    var interpreter = new Interpreter(output);
                    interpreter.LoadLibrary(StandardLibrary.Load);
                    var timer = Stopwatch.StartNew();
                    interpreter.Run();
                    timer.Stop();
                    Console.WriteLine("Time spent: " + timer.ElapsedMilliseconds);
                }
            }
            Console.WriteLine("Done");
            Console.ReadKey();
        }
Example #2
0
        public void Fact()
        {
            using (StreamReader reader = new StreamReader(SamplesPath + "fact.hy"))
            {
                var parser = new Parser();
                var output = parser.BuildExpressionTree(parser.Tokenize(parser.Split(reader.ReadToEnd())), 0);

                var interpreter = new Interpreter(output);
                interpreter.LoadLibrary(StandardLibrary.Load);
                interpreter.Run();

                Assert.IsInstanceOfType(interpreter.CurrentScopeNode.LookupNoRef("acc"), typeof(Number));
                Assert.AreEqual(2004310016, (interpreter.CurrentScopeNode.LookupNoRef("acc") as Number).Num);
            }
        }
Example #3
0
        public void Bool()
        {
            using (StreamReader reader = new StreamReader(SamplesPath + "bool.hy"))
            {
                var parser = new Parser();
                var output = parser.BuildExpressionTree(parser.Tokenize(parser.Split(reader.ReadToEnd())), 0);

                var interpreter = new Interpreter(output);
                interpreter.LoadLibrary(StandardLibrary.Load);
                interpreter.Run();

                Assert.IsInstanceOfType(interpreter.CurrentScopeNode.LookupNoRef("a"), typeof(Hype.SL.Global.Boolean));
                Assert.IsInstanceOfType(interpreter.CurrentScopeNode.LookupNoRef("b"), typeof(Number));
                Assert.IsInstanceOfType(interpreter.CurrentScopeNode.LookupNoRef("c"), typeof(Hype.SL.Global.Boolean));
                Assert.IsInstanceOfType(interpreter.CurrentScopeNode.LookupNoRef("d"), typeof(Hype.SL.Global.Boolean));
                Assert.AreEqual(false, (interpreter.CurrentScopeNode.LookupNoRef("a") as Hype.SL.Global.Boolean).Bool);
                Assert.AreEqual(6, (interpreter.CurrentScopeNode.LookupNoRef("b") as Number).Num);
                Assert.AreEqual(true, (interpreter.CurrentScopeNode.LookupNoRef("c") as Hype.SL.Global.Boolean).Bool);
                Assert.AreEqual(true, (interpreter.CurrentScopeNode.LookupNoRef("d") as Hype.SL.Global.Boolean).Bool);
            }
        }
Example #4
0
        public void Strings()
        {
            using (StreamReader reader = new StreamReader(SamplesPath + "strings.hy"))
            {
                var parser = new Parser();
                var output = parser.BuildExpressionTree(parser.Tokenize(parser.Split(reader.ReadToEnd())), 0);

                var interpreter = new Interpreter(output);
                interpreter.LoadLibrary(StandardLibrary.Load);
                interpreter.Run();

                Assert.IsInstanceOfType(interpreter.CurrentScopeNode.LookupNoRef("a"), typeof(Hype.SL.Global.String));
                Assert.IsInstanceOfType(interpreter.CurrentScopeNode.LookupNoRef("b"), typeof(Hype.SL.Global.String));
                Assert.AreEqual("testing", (interpreter.CurrentScopeNode.LookupNoRef("a") as Hype.SL.Global.String).Str);
                Assert.AreEqual("strings", (interpreter.CurrentScopeNode.LookupNoRef("b") as Hype.SL.Global.String).Str);
            }
        }
Example #5
0
        public void Scopes()
        {
            using (StreamReader reader = new StreamReader(SamplesPath + "scopes.hy"))
            {
                var parser = new Parser();
                var output = parser.BuildExpressionTree(parser.Tokenize(parser.Split(reader.ReadToEnd())), 0);

                var interpreter = new Interpreter(output);
                interpreter.LoadLibrary(StandardLibrary.Load);

                var writter = new StringWriter();
                var temp = Console.Out;
                Console.SetOut(writter);
                interpreter.Run();
                Console.SetOut(temp);

                var str = writter.ToString();
                Assert.AreEqual(@"0
            1
            2
            3
            4
            Var: i, Type: BlankIdentifier
            ", str);
            }
        }