public PrologCodeUnit Parse(TextReader input) { _scanner = new PrologScanner(input); _errors.Clear(); PrologCodeTerm term = null; while (true) { term = ReadTerm(1200); if (_scanner.Next().Kind != PrologToken.DOT) { _errors.Add(new PrologCompilerError("P0001", "Unexpected end of term", "", false, _scanner.Current.Line, _scanner.Current.Column)); break; } if (term is PrologCodeHeadlessClause) { ProcessHeadlessClause(term); } else { _codeUnit.Terms.Add(term); } if (_scanner.Lookahead.Kind == PrologToken.EOF) { break; } } return(_codeUnit); }
public void DotTest() { Write("dot.txt", " . "); StreamReader stream = new StreamReader("C:\\dot.txt"); scanner = new PrologScanner(stream); scanner.Next(); Assert.AreEqual(PrologToken.DOT, scanner.Current.Kind); stream.Close(); }
public void CommaTest() { Write("comma.txt", " , "); StreamReader stream = new StreamReader("C:\\comma.txt"); scanner = new PrologScanner(stream); scanner.Next(); Assert.AreEqual(PrologToken.COMMA, scanner.Current.Kind); stream.Close(); }
public void AtomTest() { Write("atom.txt", " atom "); StreamReader stream = new StreamReader("C:\\atom.txt"); scanner = new PrologScanner(stream); scanner.Next(); Assert.AreEqual(PrologToken.ATOM, scanner.Current.Kind); stream.Close(); }
public void CurrentTest() { Write("current.txt", "scary Variable "); StreamReader stream = new StreamReader("C:\\current.txt"); scanner = new PrologScanner(stream); scanner.Next(); Assert.AreEqual(PrologToken.ATOM, scanner.Current.Kind); scanner.Next(); Assert.AreEqual(PrologToken.VARIABLE, scanner.Current.Kind); stream.Close(); }
public void FactTokensRule() { Write("fact_tokens.txt", "male(ali,hodroj,X,'Fine not really!',[A|B])."); StreamReader stream = new StreamReader("C:\\fact_tokens.txt"); scanner = new PrologScanner(stream); // male scanner.Next(); Assert.AreEqual(PrologToken.ATOM, scanner.Current.Kind); // ( scanner.Next(); Assert.AreEqual(PrologToken.LPAREN, scanner.Current.Kind); // ali scanner.Next(); Assert.AreEqual(PrologToken.ATOM, scanner.Current.Kind); // , scanner.Next(); Assert.AreEqual(PrologToken.COMMA, scanner.Current.Kind); // hodroj scanner.Next(); Assert.AreEqual(PrologToken.ATOM, scanner.Current.Kind); // , scanner.Next(); Assert.AreEqual(PrologToken.COMMA, scanner.Current.Kind); // X scanner.Next(); Assert.AreEqual(PrologToken.VARIABLE, scanner.Current.Kind); // , scanner.Next(); Assert.AreEqual(PrologToken.COMMA, scanner.Current.Kind); // 'Fine Not Really!' scanner.Next(); Assert.AreEqual(PrologToken.ATOM, scanner.Current.Kind); // , scanner.Next(); Assert.AreEqual(PrologToken.COMMA, scanner.Current.Kind); // [ scanner.Next(); Assert.AreEqual(PrologToken.LBRACKET, scanner.Current.Kind); // A scanner.Next(); Assert.AreEqual(PrologToken.VARIABLE, scanner.Current.Kind); // | scanner.Next(); Assert.AreEqual(PrologToken.LIST_SEP, scanner.Current.Kind); // B scanner.Next(); Assert.AreEqual(PrologToken.VARIABLE, scanner.Current.Kind); // ] scanner.Next(); Assert.AreEqual(PrologToken.RBRACKET, scanner.Current.Kind); // ) scanner.Next(); Assert.AreEqual(PrologToken.RPAREN, scanner.Current.Kind); // . scanner.Next(); Assert.AreEqual(PrologToken.DOT, scanner.Current.Kind); stream.Close(); }
public void VariableTest() { Write("var.txt", "Father "); StreamReader stream = new StreamReader("C:\\var.txt"); scanner = new PrologScanner(stream); scanner.Next(); Assert.AreEqual(PrologToken.VARIABLE, scanner.Current.Kind); stream.Close(); }
public void StringTest() { Write("string.txt", " 'This is a string' "); StreamReader stream = new StreamReader("C:\\string.txt"); scanner = new PrologScanner(stream); scanner.Next(); Assert.AreEqual(PrologToken.ATOM, scanner.Current.Kind); stream.Close(); }
public void RParenTest() { Write("rparen.txt", " ) "); StreamReader stream = new StreamReader("C:\\rparen.txt"); scanner = new PrologScanner(stream); scanner.Next(); Assert.AreEqual(PrologToken.RPAREN, scanner.Current.Kind); stream.Close(); }
public void RBracketTest() { Write("rbra.txt", " ] "); StreamReader stream = new StreamReader("C:\\rbra.txt"); scanner = new PrologScanner(stream); scanner.Next(); Assert.AreEqual(PrologToken.RBRACKET, scanner.Current.Kind); stream.Close(); }
public void ListSepTest() { Write("sep.txt", " | "); StreamReader stream = new StreamReader("C:\\sep.txt"); scanner = new PrologScanner(stream); scanner.Next(); Assert.AreEqual(PrologToken.LIST_SEP, scanner.Current.Kind); stream.Close(); }
public PrologCodeUnit Parse(TextReader input) { _scanner = new PrologScanner(input); _errors.Clear(); PrologCodeTerm term = null; while(true) { term = ReadTerm(1200); if (_scanner.Next().Kind != PrologToken.DOT) { _errors.Add(new PrologCompilerError("P0001", "Unexpected end of term", "", false, _scanner.Current.Line, _scanner.Current.Column)); break; } if (term is PrologCodeHeadlessClause) { ProcessHeadlessClause(term); } else { _codeUnit.Terms.Add(term); } if (_scanner.Lookahead.Kind == PrologToken.EOF) break; } return _codeUnit; }