public PrologCodeTerm ConvertBinaryTreeToCodeDOM(BinaryTree tree) { // Clause if (tree.Name == ":-") { PrologCodeClause term = new PrologCodeClause(); if (tree.Left != null) { ArrayList goals = new ArrayList(); tree.Flatten(tree.Right, ref goals); foreach (BinaryTree goal in goals) { term.Goals.Add(ConvertGoalBinaryTreeToCodeDOM(goal)); } term.Head = (PrologCodePredicate)ConvertBinaryTreeToCodeDOM(tree.Left); return term; } // Headless clause else { // process headless clause here PrologCodeHeadlessClause hClause = new PrologCodeHeadlessClause(); ArrayList goals = new ArrayList(); tree.Flatten(tree.Right, ref goals); foreach (BinaryTree goal in goals) { hClause.Goals.Add(ConvertGoalBinaryTreeToCodeDOM(goal)); } return hClause; } } else if (tree.Name == ".") { return ConvertBinaryListToCodeDOM(tree); } // Variable else if (Char.IsUpper(tree.Name[0])) { if (tree.Left != null || tree.Right != null) { ParserError("Something was not parsed right. Variable has arity > 0", 0, 0); } PrologCodeVariable var = new PrologCodeVariable(tree.Name); return var; } else { return ConvertGoalBinaryTreeToCodeDOM(tree); } //return null; }