[10088] | 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 |
|
---|
| 22 | using System.Collections.Generic;
|
---|
| 23 | using Irony.Interpreter;
|
---|
| 24 | using Irony.Parsing;
|
---|
| 25 |
|
---|
| 26 | namespace 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 | }
|
---|