Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/PushGP.Cli/Program.cs @ 15428

Last change on this file since 15428 was 15017, checked in by pkimmesw, 8 years ago

#2665 Fixed Benchmark Problem Definition, Converted LoopExpressions to stateless expressions, Added several unit test to ensure funcionality, Fixed UI bugs

File size: 2.1 KB
RevLine 
[14727]1using System;
2using System.Threading.Tasks;
3
4namespace HeuristicLab.Algorithms.PushGP.Cli {
[15017]5  using System.Collections.Generic;
6  using System.Linq;
7
[14727]8  using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration;
[15017]9  using HeuristicLab.Problems.ProgramSynthesis.Push.Constants;
[14727]10  using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
11
12  class Program {
13    static void Main(string[] args) {
[15017]14      string code = null;
[14727]15
[15017]16      if (args.Length == 0) {
17        var lines = new List<string>();
18
19        Console.WriteLine(@"Program: ( must start with '(' and end with ')' )");
20
21        var bracesCount = 0;
22        var linesRead = 0;
23
24        while (bracesCount > 0 || lines.Count == 0 || linesRead == 0) {
25          var line = Console.ReadLine();
26          linesRead++;
27
28          if (string.IsNullOrWhiteSpace(line))
29            continue;
30
31          line = line.Trim();
32          lines.Add(line);
33
34          var openBraces = line.Count(c => c == PushEnvironment.ProgramStartSymbol);
35          var closeBraces = line.Count(c => c == PushEnvironment.ProgramEndSymbol);
36          bracesCount += openBraces - closeBraces;
37        }
38
39        code = string.Join(" ", lines);
40      } else {
41        code = args[0];
42      }
43
[14777]44      EvaluateStepwise(code).Wait();
[14727]45
[15017]46      Console.WriteLine(@"Press any key to terminate...");
[14727]47    }
48
49    static async Task EvaluateStepwise(string code) {
[14744]50      var interpreter = new PushInterpreter(new PushConfiguration {
[14727]51        TopLevelPushCode = false
52      });
53
[14834]54      Console.WriteLine(@"Press ESC to cancel, SPACE to resume, Any other key to step...");
55      interpreter.Run(code, true);
[14727]56
57      while (!interpreter.IsCompleted) {
58        Console.Clear();
59        interpreter.PrintStacks();
60        interpreter.Step();
61
62        var input = Console.ReadKey();
63        if (input.Key == ConsoleKey.Escape) {
64          break;
[14834]65        }
66
67        if (input.Key == ConsoleKey.Spacebar) {
[14727]68          await interpreter.ResumeAsync();
69        }
70      }
71
72      Console.Clear();
73      interpreter.PrintStacks();
74    }
75  }
76}
Note: See TracBrowser for help on using the repository browser.