Exemplo n.º 1
0
 private void Execute()
 {
     var engine = new Engine();
     var writer = new StringWriter();
     engine.Out = writer;
     var code = txtProgram.Text;
     try {
         engine.Execute(code, tmpName);
         txtOut.ForeColor = Color.Black;
         txtOut.Text = writer.ToString();
     }
     catch (CompilerException ex) {
         txtOut.ForeColor = Color.Red;
         txtOut.Text = "構文が間違っています。";
         SelectLine(ex.Location.Line - 1);
     }
     catch (Exception ex) {
         txtOut.ForeColor = Color.Red;
         txtOut.Text = ex.Message;
         var regex = new Regex(@"行\s+(\d+)");
         int lineNumber = 0;
         foreach (var line in ex.StackTrace.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)) {
             if (line.Contains(tmpName)) {
                 var res = regex.Match(line);
                 if (res.Success) {
                     lineNumber = Int32.Parse(res.Groups[1].Value);
                     break;
                 }
             }
         }
         if (lineNumber > 0) {
             SelectLine(lineNumber - 1);
         }
     }
 }
Exemplo n.º 2
0
 private static void Execute(string code)
 {
     var engine = new Engine();
     var result = engine.Execute(code, "console-test");
     Console.WriteLine(result);
 }