static void TestLexer() { int a = 46; for (int i = 1; i <= a; i++) { StreamReader test = File.OpenText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"C:\Users\ellia\source\repos\Compiler\Compiler\lexer_tests\tests\" + i + ".txt")); StreamReader result = File.OpenText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"C:\Users\ellia\source\repos\Compiler\Compiler\lexer_tests\results\" + i + ".txt")); Lexer lexer = new Lexer(test); bool isCorrect = true; while (true) { Token token = lexer.GetNext(); if (token.type == TokenType.END_OF_FILE) { break; } //Console.WriteLine("Test {0} end\n", i) string res = token.ToString(); //if (i == 45) Console.WriteLine(res); string myres = result.ReadLine(); if (res == myres) { isCorrect = true; } else { Console.WriteLine(res); isCorrect = false; break; } } Console.WriteLine("Test {0} : {1}", i, isCorrect); } }
public Node ParseBlock() { Token t = lexer.GetNext(); if (t.value == "{") { var sl = ParseStatementList(); if ((t = lexer.GetNext()).value == "}") { return(sl); } lexer.PutBack(t); return(new NodeError()); } lexer.PutBack(t); return(ParseStatement()); }