Example #1
0
        public override AstNode VisitStart(ALangParser.StartContext context)
        {
            var astRoot = new CompilationNode(context);

            astRoot.AdoptChildren(context.commands().Accept(this));
            return(astRoot);
        }
Example #2
0
        public void LeftMostChildOfAstRootShouldBeLeftMostSibling()
        {
            var newAstRoot = new CompilationNode();

            newAstRoot.AdoptChildren(new ImportNode());
            Assert.AreEqual(newAstRoot.LeftMostChild, newAstRoot.GetChildren().LeftMostSibling);
        }
 public void Visit(CompilationNode node)
 {
     CurrentSymbolTable.OpenScope();
     CurrentSymbolTable.Insert("TIME", LanguageType.Time, new TimeNode());
     node.AcceptChildren(this);
     node.SymbolTable = CurrentSymbolTable.currentTable;
     CurrentSymbolTable.CloseScope();
 }
Example #4
0
        public void AstNodeShouldNotAdobtNull()
        {
            var newAstRoot = new CompilationNode();

            Assert.IsNotNull(newAstRoot.LeftMostSibling);

            newAstRoot.AdoptChildren(null);
            Assert.IsNotNull(newAstRoot.LeftMostSibling);
        }
Example #5
0
        public void AstNodeShouldAdoptChild()
        {
            var newAstRoot = new CompilationNode();
            var importNode = new ImportNode();

            newAstRoot.AdoptChildren(importNode);
            Assert.IsNotNull(newAstRoot.GetChildren());
            Assert.IsInstanceOf(typeof(ImportNode), newAstRoot.GetChildren());
        }
Example #6
0
        public void Setup()
        {
            var filePath     = "../../../test.alang";
            var AbsolutePath = Path.GetFullPath(filePath);

            if (TestHelpers.ReadFromFile(AbsolutePath, out var text))
            {
                return;
            }
            this.astRoot = TestHelpers.MakeAstRoot(text);
        }
Example #7
0
        public void AdobtedChildHasCorrectParent()
        {
            var newAstRoot = new CompilationNode();

            newAstRoot.AdoptChildren(new ImportNode());
            newAstRoot.AdoptChildren(new ImportNode());

            for (AstNode child = newAstRoot.GetChildren(); child.RightSibling != null; child = child.RightSibling)
            {
                Assert.AreSame(newAstRoot, child.Parent);
            }
        }
Example #8
0
        public void GetChildren_Returns3Children()
        {
            var ast = new CompilationNode
            {
                LeftMostChild = new DeclarationNode()
                {
                    RightSibling = new ImportNode {
                        RightSibling = new DeclarationNode()
                    }
                }
            };

            Assert.That(ast.NumberOfChildren, Is.EqualTo(3));
        }
Example #9
0
        public void GetChildrenOne_IsNotADeclaration()
        {
            var ast = new CompilationNode
            {
                LeftMostChild = new DeclarationNode()
                {
                    RightSibling = new ImportNode {
                        RightSibling = new DeclarationNode()
                    }
                }
            };

            Assert.That(ast.GetChildren(1), Is.TypeOf <ImportNode>());
        }
Example #10
0
        public void AllChildrenPointsToLeftMostSibling()
        {
            var newAstRoot = new CompilationNode();

            newAstRoot.AdoptChildren(new ImportNode());
            newAstRoot.AdoptChildren(new ImportNode());
            newAstRoot.AdoptChildren(new ImportNode());
            var leftMostSibling = newAstRoot.GetChildren();

            for (AstNode child = leftMostSibling; child.RightSibling != null; child = child.RightSibling)
            {
                Assert.AreSame(leftMostSibling, child.LeftMostSibling);
            }
        }
Example #11
0
        public void GetChildrenShouldReturnSecondChild()
        {
            var ast = new CompilationNode
            {
                LeftMostChild = new ImportNode {
                    RightSibling = new ImportNode()
                }
            };

            var firstChild  = ast.LeftMostChild;
            var secondChild = ast.LeftMostChild.RightSibling;

            Assert.AreSame(firstChild, ast.GetChildren(0));
            Assert.AreSame(secondChild, ast.GetChildren(1));
        }
Example #12
0
        public void Visit(CompilationNode node)
        {
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WriteLine("CompilationNode:");
            Console.ResetColor();
            IndentLevel++;
            var child = node.GetChildren();

            while (child != null)
            {
                child.Accept(this);
                child = child.RightSibling;
            }
            IndentLevel--;
        }
Example #13
0
        public void MakeSiblingsShouldAssignCorrectParent()
        {
            var newAstRoot = new CompilationNode();
            var node       = new ImportNode();

            newAstRoot.AdoptChildren(node);

            var node2 = new ImportNode();
            var node3 = new ImportNode();

            node = (ImportNode)node.MakeSiblings(node2.MakeSiblings(node3));

            Assert.AreSame(newAstRoot, node.Parent);
            Assert.AreSame(newAstRoot, node2.Parent);
            Assert.AreSame(newAstRoot, node3.Parent);
        }
Example #14
0
        public void MakeSiblingShouldChainSiblings()
        {
            var newAstRoot = new CompilationNode();
            var node       = new ImportNode();

            newAstRoot.AdoptChildren(node);

            var node2 = new ImportNode();
            var node3 = new ImportNode();

            node = (ImportNode)node.MakeSiblings(node2.MakeSiblings(node3));

            Assert.AreSame(node, node2.LeftMostSibling);
            Assert.AreSame(node2, node.RightSibling);
            Assert.AreSame(node, node3.LeftMostSibling);
            Assert.AreSame(node3, node2.RightSibling);
        }
Example #15
0
        public void TryCompile()
        {
            var codegen = new CodeGenVisitor();
            var ast     = new CompilationNode();

            try
            {
                ast.Accept(codegen);
            }
            catch (SomethingWentWrongException e)
            {
                Console.WriteLine(e.Node.Start);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
 public LanguageType Visit(CompilationNode node)
 {
     CurrentSymbolTable = node.SymbolTable;
     node.AcceptChildren(this);
     return(LanguageType.Void);
 }
Example #17
0
        public void GetChildren_Returns0Children()
        {
            var ast = new CompilationNode();

            Assert.That(ast.NumberOfChildren, Is.EqualTo(0));
        }