private void SourceTextChanged(object sender, EventArgs e) { string input = this.Source.Text.Replace("\t", " "); File.WriteAllText("test.sc", input); try { TargetCpp sugar_cpp = new TargetCpp(); string output = sugar_cpp.Compile(input, "test").Implementation; this.Result.Text = output; File.WriteAllText("test.cpp", output); } catch (Exception ex) { string output = string.Format("Compile Error:\n{0}", ex.Message); this.Result.Text = output; } }
private void Source_TextChanged_1(object sender, EventArgs e) { string input = this.Source.Text; File.WriteAllText("test.sc", input); try { TargetCpp sugar_cpp = new TargetCpp(); var result = sugar_cpp.Compile(input, "test"); this.Header.Text = result.Header; File.WriteAllText("test.h", this.Header.Text); this.Implementation.Text = result.Implementation; File.WriteAllText("test.cpp", this.Implementation.Text); } catch (Exception ex) { string output = string.Format("Compile Error:\n{0}", ex.Message); this.Header.Text = output; } }
internal static void DoCompile(string inputFileName, string arguments) { string cppFileName = Path.GetTempFileName(); string input = File.ReadAllText(inputFileName); TargetCppResult result = null; try { TargetCpp sugarCpp = new TargetCpp(); result = sugarCpp.Compile(input, cppFileName); } catch (Exception ex) { Program.Panic(string.Format("Compile Error:\n{0}", ex.Message)); } // Write to temperory file File.Delete(cppFileName); File.WriteAllText(cppFileName + ".h", result.Header); File.WriteAllText(cppFileName + ".cpp", result.Implementation); // Execute compiler RunCommand(compiler.Command, cppFileName + ".cpp" + " " + arguments + " " + compiler.AdditionalArgs); }
private void OnFileEvent(object sender, FileSystemEventArgs e) { Thread.Sleep(1); string root = watcher_to_root[sender]; string input = null; try { input = File.ReadAllText(e.FullPath); } catch (Exception) { compile_info[root][e.Name] = string.Format("Failed to read file."); UpdateGui(); return; } string result = null; try { TargetCpp sugar_cpp = new TargetCpp(); result = sugar_cpp.Compile(input, "test").Implementation; } catch (Exception err) { compile_info[root][e.Name] = string.Format("Compile Error:\n{0}", err); Console.WriteLine("Compile Error!"); UpdateGui(); return; } try { string name = e.Name.Substring(0, e.Name.Length - 3) + ".cpp"; name = name.Substring(name.LastIndexOf("/") + 1); name = name.Substring(name.LastIndexOf("\\") + 1); File.WriteAllText(root + "/" + name, result); } catch (Exception) { compile_info[root][e.Name] = string.Format("Can't access file."); UpdateGui(); return; } compile_info[root][e.Name] = null; Console.WriteLine("Compile Success!"); UpdateGui(); }
public string Compile(string input) { var sugarCpp = new TargetCpp(); return sugarCpp.Compile(input, "test").Implementation; }
public static string Compile(string input) { input = input.Replace("\r", ""); ANTLRStringStream Input = new ANTLRStringStream(input); SugarCppLexer lexer = new SugarCppLexer(Input); CommonTokenStream tokens = new CommonTokenStream(lexer); SugarCppParser parser = new SugarCppParser(tokens); AstParserRuleReturnScope<CommonTree, IToken> t = parser.root(); CommonTree ct = (CommonTree)t.Tree; if (parser.errors.Count() > 0) { StringBuilder sb = new StringBuilder(); foreach (var error in parser.errors) { sb.Append(error); sb.Append("\n"); } throw new Exception(sb.ToString()); } CommonTreeNodeStream nodes = new CommonTreeNodeStream(ct); SugarWalker walker = new SugarWalker(nodes); Root ast = walker.root(); TargetCpp target_cpp = new TargetCpp(); return ast.Accept(target_cpp).Render(); }
public void SpeedTest1MB() { var sugarCpp = new TargetCpp(); sugarCpp.Compile(_input1MB, "test"); }