public Boolean RunTest() { try { GlobalMemory.Clear(); var sStream = new ANTLRStringStream(input); var lexer = new SGLLexer(sStream); var tStream = new CommonTokenStream(lexer); // Parsing var parser = new SGLParser(tStream); var t = (CommonTree) parser.main().Tree; // Printing tree Console.WriteLine("; " + t.ToStringTree()); // TreeWalking var treeStream = new CommonTreeNodeStream(t); var tw = new SGLTreeWalker(treeStream, true); AbstractNode returned = tw.main(); returned.Evaluate(); if (debug) { realOutput = GlobalMemory.Instance.DebugString; } else { realOutput = GlobalMemory.Instance.StoryboardCode.ToString(); } // comparison realOutput = realOutput.Trim(); output.Trim(); if (output.Equals(realOutput)) { return true; } else { return false; } } catch (CompilerException ce) { Console.WriteLine(ce.GetExceptionAsString()); return false; } catch (Exception ex) { Console.WriteLine("Es ist ein Fehler aufgetreten."); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); return false; } }
public Boolean Run() { // run lexer on input var lexer = new SGLLexer(new ANTLRStringStream(Input)); var tokenStream = new CommonTokenStream(lexer); // run parser on tokens var parser = new SGLParser(tokenStream); var ast = (CommonTree) parser.main().Tree; // maybe test the tree if (testTree) { if (!ast.ToStringTree().Trim().Equals(ExpectedTree.Trim())) { result += "Test " + name + "failed! Tree comparison failed!"; result += "Expected tree: " + ExpectedTree.Trim(); result += "Given tree: " + ast.ToStringTree().Trim(); return false; } } var astStream = new CommonTreeNodeStream(ast); // run walker on AST GlobalMemory.Clear(); var treewalker = new SGLTreeWalker(astStream, true); treewalker.main().Evaluate(); //String output = treewalker.GetStoryboardCode().ToString(); if (testOutput) { String output = GlobalMemory.Instance.StoryboardCode.ToString(); if (!output.Trim().Equals(ExpectedOutput.Trim())) { result += "Test " + name + "failed! Output comparison failed!"; result += "Expected output: \r\n" + ExpectedOutput.Trim(); result += "Given output: \r\n" + output.Trim(); return false; } } if (testDebug) { String debug = GlobalMemory.Instance.StoryboardCode.ToString(); if (!debug.Trim().Equals(ExpectedDebug.Trim())) { result += "Test " + name + "failed! Debug comparison failed!"; result += "Expected debug: \r\n" + ExpectedDebug.Trim(); result += "Given debug: \r\n" + debug.Trim(); return false; } } return true; }
private CommonTokenStream GenerateTokens(String input) { try { Stopwatch timeNeeded = timeRecording ? new Stopwatch() : null; if (timeRecording) timeNeeded.Start(); // Lexer: Converting the string into tokens var lexer = new SGLLexer(new ANTLRStringStream(input)); var tokenStream = new CommonTokenStream(lexer); if (timeRecording) { timeNeeded.Stop(); Console.WriteLine("Time needed for converting the string into tokens: " + timeNeeded.ElapsedMilliseconds + " ms (" + timeNeeded.Elapsed + ")"); } return tokenStream; } catch (Exception e) { throw e; } }