private Node parseInternalNode(string _expression, string nextOperatorForParsing, Dictionary <string, string> mappings) { /*put this into a separate function and override it.*/ string[] expressions = divideExrepssionByOperator(_expression, nextOperatorForParsing); Node node; nextOperatorForParsing = nextOperatorForParsing.Trim(); Node lhs = parse(expressions[0], mappings); Node rhs = parse(expressions[1], mappings); /*eliminate W node during parsing * temporary hack. in the subsequent code refactoring move this piece of code * as it is relevant only for temporal logics */ if (nextOperatorForParsing.StartsWith("W")) { string substituteUntil = nextOperatorForParsing.Replace("W", "U"); string substituteAG = nextOperatorForParsing.Replace("W", "AG"); Node uNode = new InternalNode(substituteUntil, lhs, rhs); Node terminal = new LeafNode(); Node agNode = new InternalNode(substituteAG, terminal, lhs); node = new InternalNode("||", uNode, agNode); } else { node = new InternalNode(nextOperatorForParsing, lhs, rhs); } return(node); }
private int calculateDepth(Node rootNode, int depth) { if (rootNode == null || rootNode is LeafNode) { depth = depth > 0 ? depth - 1 : depth; } else if (rootNode is InternalNode) { InternalNode opNode = (InternalNode)rootNode; depth = calculateDepth(opNode.getLeftHandSide(), depth + 1); int rhsDepth = calculateDepth(opNode.getRightHandSide(), depth + 1); if (rhsDepth > depth) { depth = rhsDepth; } } return(depth); }
private ICollection <Node> getLeafsRecursively(Node node) { List <Node> result = new List <Node>(); if (node is LeafNode) { if (!string.IsNullOrWhiteSpace(node.getExpression())) { result.Add(node); } } else if (node is InternalNode) { InternalNode operatorNode = (InternalNode)node; result.AddRange(getLeafsRecursively(operatorNode.getLeftHandSide())); result.AddRange(getLeafsRecursively(operatorNode.getRightHandSide())); } return(result); }
private ICollection <Node> recursiveTraversal(int currentLevel, int requestedLevel, Node currentNode) { List <Node> result = new List <Node>(); if (currentNode is InternalNode) { InternalNode currentOperator = (InternalNode)currentNode; if (currentLevel <= requestedLevel) { result.AddRange(recursiveTraversal(currentLevel + 1, requestedLevel, currentOperator.getLeftHandSide())); result.AddRange(recursiveTraversal(currentLevel + 1, requestedLevel, currentOperator.getRightHandSide())); } } else if (currentNode is LeafNode) { if (currentLevel == 0 || currentLevel == requestedLevel + 1) { result.Add(currentNode); } } return(result); }