public override AstNode VisitStart(ALangParser.StartContext context) { var astRoot = new CompilationNode(context); astRoot.AdoptChildren(context.commands().Accept(this)); return(astRoot); }
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(); }
public void AstNodeShouldNotAdobtNull() { var newAstRoot = new CompilationNode(); Assert.IsNotNull(newAstRoot.LeftMostSibling); newAstRoot.AdoptChildren(null); Assert.IsNotNull(newAstRoot.LeftMostSibling); }
public void AstNodeShouldAdoptChild() { var newAstRoot = new CompilationNode(); var importNode = new ImportNode(); newAstRoot.AdoptChildren(importNode); Assert.IsNotNull(newAstRoot.GetChildren()); Assert.IsInstanceOf(typeof(ImportNode), newAstRoot.GetChildren()); }
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); }
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); } }
public void GetChildren_Returns3Children() { var ast = new CompilationNode { LeftMostChild = new DeclarationNode() { RightSibling = new ImportNode { RightSibling = new DeclarationNode() } } }; Assert.That(ast.NumberOfChildren, Is.EqualTo(3)); }
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>()); }
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); } }
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)); }
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--; }
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); }
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); }
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); }
public void GetChildren_Returns0Children() { var ast = new CompilationNode(); Assert.That(ast.NumberOfChildren, Is.EqualTo(0)); }