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); }
public override Value Invoke(List <Value> parameters) { if (parameters.Count == parameterNames.Count) { // create new scope for the method call var methodScope = new Scope(); for (int i = 0; i < parameterNames.Count; i++) { methodScope.Define(parameterNames[i]); methodScope.Assign(parameterNames[i], parameters[i]); } var nodeStream = new CommonTreeNodeStream(functionBody); // Create a tree walker to evaluate this method's code block var walker = new SGLTreeWalker(nodeStream, methodScope); // Ok, executing the function then Value returnValue = walker.main().Evaluate(); if (returnValue.Type == ValType.Return) { return(returnValue.ReturnValue); } else { return(returnValue); } // we shouldn't check the return type /*if (!returnValue.GetVarType().Equals(this.returnType)) * { * throw new Exception("The method doesn't return the expected return type (" + returnValue.ToString() + " is not from type " + this.returnType + ")"); * }*/ } throw new CompilerException(definedLine, 318, name, parameterNames.Count.ToString(), parameters.Count.ToString()); }
private String GenerateStoryboardCode(CommonTreeNodeStream input) { Stopwatch timeNeeded = timeRecording ? new Stopwatch() : null; if (timeRecording) { timeNeeded.Start(); } // Parser: Converting the tokens into an abstract syntax tree var treewalker = new SGLTreeWalker(input, true); treewalker.main().Evaluate(); //String output = treewalker.GetStoryboardCode().ToString(); String output = GlobalMemory.Instance.StoryboardCode.ToString(); if (timeRecording) { timeNeeded.Stop(); Console.WriteLine("Time needed for converting the tree into storyboard code: " + timeNeeded.ElapsedMilliseconds + " ms (" + timeNeeded.Elapsed + ")"); } return(output); }
public Value Invoke(Value objectVar, List <Value> parameters) { if (parameters.Count == parameterNames.Count) { // create new scope for the method call var methodScope = new Scope(); methodScope.Define("this"); methodScope.Assign("this", objectVar); for (int i = 0; i < parameterNames.Count; i++) { methodScope.Define(parameterNames[i]); methodScope.Assign(parameterNames[i], parameters[i]); } var nodeStream = new CommonTreeNodeStream(functionBody); // Create a tree walker to evaluate this method's code block var walker = new SGLTreeWalker(nodeStream, methodScope); Value returnValue = null; // Ok, executing the function then returnValue = walker.main().Evaluate(); // we shouldn't check the return type /*if (!returnValue.GetVarType().Equals(this.returnType)) * { * throw new Exception("The method doesn't return the expected return type (" + returnValue.ToString() + " is not from type " + this.returnType + ")"); * }*/ return(returnValue); } // TODO: Exception throw new Exception(); }