public Boolean RunTest() { try { ANTLRStringStream sStream = new ANTLRStringStream(input); SGLLexer lexer = new SGLLexer(sStream); CommonTokenStream tStream = new CommonTokenStream(lexer); // Parsing SGLParser parser = new SGLParser(tStream); CommonTree t = (CommonTree)parser.compilationUnit().Tree; // Printing tree Console.WriteLine("; " + t.ToStringTree()); // TreeWalking CommonTreeNodeStream treeStream = new CommonTreeNodeStream(t); SGLTreeWalker tw = new SGLTreeWalker(treeStream); SGLNode returned = tw.compilationUnit(); returned.Evaluate(); realOutput = tw.GetStoryboardCode().ToString(); // comparison realOutput = realOutput.Trim(); output.Trim(); if (output.Equals(realOutput)) { return true; } else { return false; } } catch (SGLCompilerException ce) { if (ce.ErrorType.Equals("Antlr.Parser")) { Console.WriteLine("Error (wrong syntax) on " + ce.Message); } else { Console.WriteLine("Error (" + ce.ErrorType + ") on line " + ce.Line + ": " + ce.Message); } return false; } catch (Exception ex) { Console.WriteLine("Es ist ein Fehler aufgetreten."); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); return false; } }
private CommonTokenStream GenerateTokens(String input) { Stopwatch timeNeeded = timeRecording ? new Stopwatch() : null; if (timeRecording) timeNeeded.Start(); // Lexer: Converting the string into tokens SGLLexer lexer = new SGLLexer(new ANTLRStringStream(input)); CommonTokenStream 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; }