Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Benchmark Generator/HeuristicLab.BenchmarkGenerator/3.3/ExpressionEvaluator.cs @ 13847

Last change on this file since 13847 was 10088, checked in by bburlacu, 11 years ago

#2083: Removed old project and rewritten the Benchmark Generator as a HeuristicLab plugin. Added new functions and visualization capability.

File size: 2.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Collections.Generic;
23using Irony.Interpreter;
24using Irony.Parsing;
25
26namespace HeuristicLab.BenchmarkGenerator {
27  class ExpressionEvaluator {
28    public ExpressionGrammar Grammar { get; private set; }
29    public Parser Parser { get; private set; }
30    public LanguageData Language { get; private set; }
31    public LanguageRuntime Runtime { get; private set; }
32    public ScriptApp App { get; private set; }
33    public IDictionary<string, object> Globals { get { return App.Globals; } }
34
35    public ExpressionEvaluator() : this(new ExpressionGrammar()) { }
36
37    public ExpressionEvaluator(ExpressionGrammar grammar) {
38      Grammar = grammar;
39      Language = new LanguageData(Grammar);
40      Parser = new Parser(Language);
41      Runtime = Grammar.CreateRuntime(Language);
42      App = new ScriptApp(Runtime);
43    }
44
45    public object Evaluate(ParseTree parsedScript) {
46      var result = App.Evaluate(parsedScript);
47      return result;
48    }
49
50    public object Evaluate() {
51      return App.Evaluate();
52    }
53
54    public void ClearOutput() {
55      App.ClearOutputBuffer();
56    }
57
58    public string GetOutput() {
59      return App.GetOutput();
60    }
61  }
62}
Note: See TracBrowser for help on using the repository browser.