public void ForIfTest(string line, string expected)
        {
            var parser = GenerateTree(
                @"{
for i = 1..5
{"
                + $"\n if({line})\n" +
                @"{
a = 3;
}
}
}");
            var expectedTree = GenerateTree(
                @"{
for i = 1..5
{"
                + $"\n if({expected})\n" +
                @"{
a = 3;
}
}
}");
            var a = new NumberEqualityVisitor();

            a.Visit(parser.root);
            var first = ((parser.root.StList[0] as ForNode)
                         .Stat.StList[0] as IfNode)
                        .Condition as BoolValNode;
            var second = ((expectedTree.root.StList[0] as ForNode)
                          .Stat.StList[0] as IfNode)
                         .Condition as BoolValNode;

            Assert.AreEqual(first.Val, second.Val);
        }
        public void OneLineTests(string line, string expected)
        {
            var parser       = GenerateTree(@"{" + $"\n{line}\n" + @"}");
            var expectedTree = GenerateTree(@"{" + $"\n{expected}\n" + @"}");
            var a            = new NumberEqualityVisitor();

            a.Visit(parser.root);
            var first  = (parser.root.StList[0] as AssignNode).Expr as BoolValNode;
            var second = (expectedTree.root.StList[0] as AssignNode).Expr as BoolValNode;

            Assert.AreEqual(first.Val, second.Val);
        }
        public void WhileTest(string line, string expected)
        {
            var parser = GenerateTree(@"{" + $"\n while({line})\n" +
                                      @"{
a = 3;
}
}");
            var expectedTree = GenerateTree(@"{" + $"\n while({expected})\n" +
                                            @"{
a = 3;
}
}");
            var a = new NumberEqualityVisitor();

            a.Visit(parser.root);
            var first  = (parser.root.StList[0] as WhileNode).Condition as BoolValNode;
            var second = (expectedTree.root.StList[0] as WhileNode).Condition as BoolValNode;

            Assert.AreEqual(first.Val, second.Val);
        }
예제 #4
0
        static void CurrentTests(Parser parser) // 07.04 pervie 10 ballov
        {
            Console.WriteLine("Syntax tree before: \n");
            foreach (var st in parser.root.StList)
            {
                Console.WriteLine(st);
            }
            var pf = new FillParentVisitor();

            parser.root.Visit(pf);
            var ne = new NumberEqualityVisitor();

            parser.root.Visit(ne);
            var ifelse = new AlwaysIfOrElseVisitor();

            parser.root.Visit(ifelse);
            Console.WriteLine("After visitors: \n");
            foreach (var st in parser.root.StList)
            {
                Console.WriteLine(st);
            }
        }