Beispiel #1
0
        public static DaisyProgram <T> Compile <T>(string code, StatementSet statements, DaisyMode mode = DaisyMode.Debug)
        {
            var ast    = DaisyParser.Parse(code);
            var linker = new DaisyLinker(ast, statements, typeof(T));

            linker.Link();
            return(new DaisyProgram <T>(ast, mode));
        }
        public string ItPrintsPrograms(string code)
        {
            var ast  = DaisyParser.Parse(code);
            var p    = new DaisyAstPrinter(ast.Root);
            var back = p.Print();

            Assert.AreEqual(0, p.indent);
            return(back);
        }
Beispiel #3
0
        public bool ItRunsPrograms(string code)
        {
            var ast = DaisyParser.Parse(code);

            AddLink(ast, "t", i => true);
            AddLink(ast, "f", i => false);
            var program = new DaisyProgram <int>(ast, DaisyMode.Debug);
            var result  = program.Execute(1).Outcome;

            return(result);
        }
Beispiel #4
0
        public bool ItExecutesAggregates(string code, string values)
        {
            var ast = DaisyParser.Parse(code);

            AddLink(ast, "even", i => i % 2 == 0);
            AddLink(ast, "t", i => true);
            AddAggregateLink(ast, "any");
            var program = new DaisyProgram <IEnumerable <int> >(ast, DaisyMode.Debug);
            var result  = program.Execute(values.Split(',').Select(int.Parse)).Outcome;

            return(result);
        }
Beispiel #5
0
        public void ItParsesLanguages(string code, string expectedTree)
        {
            var llstream = new LookAheadStream <Token>(new Lexer(code.ToStream()).Lex());
            var parser   = new DaisyParser(llstream);
            var tree     = parser.Parse();

            Assert.IsNotNull(tree);
            var actualTree = DaisyAstPrinter.Print(tree.Root);

            if (expectedTree != actualTree)
            {
                Console.WriteLine(expectedTree);
                Console.WriteLine("----------------");
                Console.WriteLine(actualTree);
            }
            Assert.AreEqual(expectedTree, actualTree);
        }