Index: branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Grammar.cs
===================================================================
--- branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Grammar.cs	(revision 15714)
+++ branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Grammar.cs	(revision 15722)
@@ -6,4 +6,6 @@
 using HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration.GrammarEnumeration;
 using HeuristicLab.Common;
+using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
+using HeuristicLab.Problems.DataAnalysis.Symbolic;
 
 namespace HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration {
@@ -13,4 +15,5 @@
 
     #region Symbols
+
     public VariableSymbol Var;
 
@@ -21,6 +24,25 @@
     public TerminalSymbol Addition;
     public TerminalSymbol Multiplication;
-    #endregion
-
+
+    #endregion
+
+
+    #region HL Symbols for Parsing ExpressionTrees
+
+    private TypeCoherentExpressionGrammar symbolicExpressionGrammar;
+
+    private ISymbol constSy;
+    private ISymbol varSy;
+
+    private ISymbol addSy;
+    private ISymbol mulSy;
+    private ISymbol logSy;
+    private ISymbol expSy;
+    private ISymbol divSy;
+
+    private ISymbol rootSy;
+    private ISymbol startSy;
+
+    #endregion
 
     public Grammar(string[] variables) {
@@ -48,4 +70,21 @@
       Factor.AddProduction(Var);
       #endregion
+
+      #region Parsing to SymbolicExpressionTree
+      symbolicExpressionGrammar = new TypeCoherentExpressionGrammar();
+      symbolicExpressionGrammar.ConfigureAsDefaultRegressionGrammar();
+
+      constSy = symbolicExpressionGrammar.Symbols.OfType<Constant>().First();
+      varSy = symbolicExpressionGrammar.Symbols.OfType<Variable>().First();
+      addSy = symbolicExpressionGrammar.AllowedSymbols.OfType<Addition>().First();
+      mulSy = symbolicExpressionGrammar.AllowedSymbols.OfType<Multiplication>().First();
+      logSy = symbolicExpressionGrammar.AllowedSymbols.OfType<Logarithm>().First();
+      expSy = symbolicExpressionGrammar.AllowedSymbols.OfType<Exponential>().First();
+      divSy = symbolicExpressionGrammar.AllowedSymbols.OfType<Division>().First();
+
+      rootSy = symbolicExpressionGrammar.AllowedSymbols.OfType<ProgramRootSymbol>().First();
+      startSy = symbolicExpressionGrammar.AllowedSymbols.OfType<StartSymbol>().First();
+
+      #endregion
     }
 
@@ -60,4 +99,5 @@
     }
 
+    #region Hashing
     private int[] GetSubtreeHashes(TerminalSymbol currentSymbol, Stack<TerminalSymbol> parseStack) {
       List<int> childHashes = null;
@@ -66,5 +106,6 @@
         childHashes = currentSymbol.StringRepresentation.GetHashCode().ToEnumerable().ToList();
 
-      } else if (ReferenceEquals(currentSymbol, Multiplication)) { // MULTIPLICATION
+      } else if (ReferenceEquals(currentSymbol, Multiplication)) {
+        // MULTIPLICATION
         childHashes = new List<int>();
 
@@ -94,5 +135,6 @@
 
 
-      } else if (ReferenceEquals(currentSymbol, Addition)) { // ADDITION
+      } else if (ReferenceEquals(currentSymbol, Addition)) {
+        // ADDITION
         HashSet<int> uniqueChildHashes = new HashSet<int>();
 
@@ -129,4 +171,49 @@
       return hashes.Aggregate(0, (result, ti) => ((result << 5) + result) ^ ti.GetHashCode());
     }
+    #endregion
+
+    #region Parse to SymbolicExpressionTree
+    public SymbolicExpressionTree ParseSymbolicExpressionTree(SymbolString sentence) {
+      Debug.Assert(sentence.Any(), "Trying to evaluate empty sentence!");
+      Debug.Assert(sentence.All(s => s is TerminalSymbol), "Trying to evaluate symbol sequence with nonterminalsymbols!");
+
+      symbolicExpressionGrammar.ConfigureAsDefaultRegressionGrammar();
+
+      var rootNode = rootSy.CreateTreeNode();
+      var startNode = startSy.CreateTreeNode();
+      rootNode.AddSubtree(startNode);
+
+      Stack<TerminalSymbol> parseStack = new Stack<TerminalSymbol>(sentence.OfType<TerminalSymbol>());
+      startNode.AddSubtree(ParseSymbolicExpressionTree(parseStack));
+
+      return new SymbolicExpressionTree(rootNode);
+    }
+
+    public ISymbolicExpressionTreeNode ParseSymbolicExpressionTree(Stack<TerminalSymbol> parseStack) {
+      TerminalSymbol currentSymbol = parseStack.Pop();
+
+      ISymbolicExpressionTreeNode parsedSubTree = null;
+
+      if (ReferenceEquals(currentSymbol, Addition)) {
+        parsedSubTree = addSy.CreateTreeNode();
+        parsedSubTree.AddSubtree(ParseSymbolicExpressionTree(parseStack)); // left part
+        parsedSubTree.AddSubtree(ParseSymbolicExpressionTree(parseStack)); // right part
+
+      } else if (ReferenceEquals(currentSymbol, Multiplication)) {
+        parsedSubTree = mulSy.CreateTreeNode();
+        parsedSubTree.AddSubtree(ParseSymbolicExpressionTree(parseStack)); // left part
+        parsedSubTree.AddSubtree(ParseSymbolicExpressionTree(parseStack)); // right part
+
+      } else if (Var.VariableTerminalSymbols.Contains(currentSymbol)) {
+        VariableTreeNode varNode = (VariableTreeNode)varSy.CreateTreeNode();
+        varNode.Weight = 1.0;
+        varNode.VariableName = currentSymbol.StringRepresentation;
+        parsedSubTree = varNode;
+      }
+
+      Debug.Assert(parsedSubTree != null);
+      return parsedSubTree;
+    }
+    #endregion
   }
 }
