private void GetFile(string filename, ref string expected, ref string result) { StreamReader sr = new StreamReader(filename); PrologCodeParser parser = new PrologCodeParser(); parser.Scanner = new PrologScanner(sr); PrologCodeTerm term = parser.ConvertBinaryTreeToCodeDOM(parser.Term(1200)); sr.Close(); StreamReader codefile = new StreamReader(filename); string originalCode = codefile.ReadLine(); codefile.Close(); string exp = originalCode.Replace(" ", "").Replace(".", ""); string res = term.ToString().Replace(" ", "").Replace(".", ""); expected = exp; result = res; }
public void Parse_Fact_no_Args() { // Try to parse 'predicate.' Write("factnoargs.txt", "predicate."); StreamReader sr = new StreamReader("C:\\factnoargs.txt"); PrologCodeParser parser = new PrologCodeParser(); parser.Scanner = new PrologScanner(sr); BinaryTree ast = parser.Term(1200); sr.Close(); // Expect: BinaryTree("predicate", null, null, null); Assert.AreEqual("predicate", ast.Name); Assert.IsNull(ast.Left); Assert.IsNull(ast.Right); Assert.IsNull(ast.Arguments); }
private BinaryTree PrologTerm(string s) { // Try to parse 'predicate.' Write("parsertest.txt", s); StreamReader sr = new StreamReader("C:\\parsertest.txt"); PrologCodeParser parser = new PrologCodeParser(); parser.Scanner = new PrologScanner(sr); BinaryTree ast = parser.Term(1200); sr.Close(); File.Delete("C:\\parsertest.txt"); return ast; }
public void Parse_Fact_with_Variable_Arg() { // Try to parse 'predicate.' Write("factnoargs.txt", "predicate(X)."); StreamReader sr = new StreamReader("C:\\factnoargs.txt"); PrologCodeParser parser = new PrologCodeParser(); parser.Scanner = new PrologScanner(sr); BinaryTree ast = parser.Term(1200); sr.Close(); // Expect: BinaryTree("predicate", null, null, null); Assert.AreEqual("predicate", ast.Name); Assert.IsNull(ast.Left); Assert.IsNull(ast.Right); ArrayList args = new ArrayList(); ast.Flatten((BinaryTree)ast.Arguments[0], ref args); Assert.AreEqual(1, args.Count); }