public void Add(string rawToken) { if (IsEmpty()) { Token = rawToken; return; } else { var newNode = new LISPAbstractSyntaxTreeNode(rawToken); Add(newNode); } }
public void Add(LISPAbstractSyntaxTreeNode newNode) { if (IsEmpty()) { Token = newNode.Token; Children = newNode.Children; return; } else { newNode.Parent = this; _children.Add(newNode); } }
/// <summary> /// This method will return the whitespace that should preface a token /// when printing abstract syntax trees in a human readable format. /// </summary> private static string GetIndendationString(LISPAbstractSyntaxTreeNode ASTNode) { // Check if the node is the root, or a direct descendent of the root. bool doesNotNeedIndendation = ASTNode.IsRoot(); doesNotNeedIndendation = (doesNotNeedIndendation) ? doesNotNeedIndendation : ASTNode.Parent.IsRoot(); if (doesNotNeedIndendation) { // If so, there is no need to indent. Return an empty string. return(""); } // Find the parent's indentation and form an indentation string. string parentIndentationString = GetIndendationString(ASTNode.Parent); string indentationWhitespace = new string(' ', indentationIncrement); string indentationString = String.Concat(parentIndentationString, " |", indentationWhitespace); return(indentationString); }
/// <summary> /// This method will print the contents of a syntax tree and its /// children to the console output. /// </summary> public static void PrintSyntaxTree(LISPAbstractSyntaxTreeNode ASTNode) { if (ASTNode == null) { throw new NullReferenceException(); } else if (ASTNode.IsEmpty()) { return; } PrintCurrentNodeTokenWithIndentation(ASTNode); if (ASTNode.Children != null) { // Print any nodes descending from the current node. foreach (var currentChild in ASTNode.Children) { PrintSyntaxTree(currentChild); } } }
public LISPAbstractSyntaxTree(string rawInputExpression) { string[] syntaxTokens = InputParsing.RawInputParser .ParseExpressionIntoList(rawInputExpression); _root = new LISPAbstractSyntaxTreeNode(syntaxTokens); }
public LISPAbstractSyntaxTree(string[] syntaxTokens) { _root = new LISPAbstractSyntaxTreeNode(syntaxTokens); }
public LISPAbstractSyntaxTree() { _root = new LISPAbstractSyntaxTreeNode(); }
public LISPAbstractSyntaxTreeNode(string token) { _token = token; _children = new List <LISPAbstractSyntaxTreeNode>(); _parent = null; }
public LISPAbstractSyntaxTreeNode() { _token = ""; _children = new List <LISPAbstractSyntaxTreeNode>(); _parent = null; }