Index: /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/AST.cs
===================================================================
--- /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/AST.cs	(revision 10056)
+++ /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/AST.cs	(revision 10056)
@@ -0,0 +1,154 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+public class GPDefNode {
+  public string Name { get; set; }
+  public CodeNode ClassCodeNode { get; set; }
+  public CodeNode InitCodeNode { get; set; }
+  public List<SymbolNode> NonTerminals { get; private set; }
+  public List<SymbolNode> Terminals { get; private set; }
+  public List<RuleNode> Rules { get; private set; }
+  public FitnessFunctionNode FitnessFunctionNode { get; set; }
+
+  public GPDefNode() {
+    this.NonTerminals = new List<SymbolNode>();
+    this.Terminals = new List<SymbolNode>();
+    this.Rules = new List<RuleNode>();
+    this.ClassCodeNode = new CodeNode();
+    this.InitCodeNode = new CodeNode();
+  }
+
+  public bool IsSymbolDefined(SymbolNode n) {
+    return NonTerminals.Any(s => s.Ident == n.Ident) ||
+           Terminals.Any(s => s.Ident == n.Ident);
+  }
+  public bool IsNonTerminalDefined(string ntIdent) {
+    return NonTerminals.Any(s => s.Ident == ntIdent);
+  }
+  public bool IsRuleDefined(RuleNode n) {
+    return IsRuleDefined(n.NtSymbol);
+  }
+  public bool IsRuleDefined(string ntSymbol) {
+    return Rules.Any(r => r.NtSymbol == ntSymbol);
+  }
+  public string UndefinedNonTerminals() {
+    var sb = new StringBuilder();
+    foreach (var nt in NonTerminals) {
+      if (!IsRuleDefined(nt.Ident)) {
+        sb.AppendFormat("{0} ", nt.Ident);
+      }
+    }
+    return sb.ToString();
+  }
+}
+
+public class CodeNode {
+  public string SrcCode { get; set; }
+}
+
+public class FitnessFunctionNode {
+  public bool Maximization { get; set; }
+  public string SrcCode { get; set; }
+}
+
+public class SymbolNode {
+  public string Ident { get; set; }
+  public string FormalParameters { get; set; }
+
+}
+
+public class NonTerminalNode : SymbolNode {
+}
+
+public class TerminalNode : SymbolNode {
+  public class FieldDefinition {
+    private readonly string refOrOut;
+    private readonly string type;
+    private readonly string identifier;
+
+    public FieldDefinition(string refOrOut, string type, string identifier) {
+      this.type = type;
+      this.identifier = identifier;
+      this.refOrOut = refOrOut;
+    }
+    public string RefOrOut { get { return this.refOrOut; } }
+    public string Type { get { return this.type; } }
+    public string Identifier { get { return this.identifier; } }
+  }
+  public IEnumerable<ConstraintNode> Constraints { get; set; }
+  public IEnumerable<FieldDefinition> FieldDefinitions { get; set; }
+}
+
+
+public enum ConstraintNodeType { Set, Range };
+public class ConstraintNode {
+  public string Ident { get; set; }
+  public ConstraintNodeType Type { get; set; }
+  public string SetExpression { get; set; }
+  public string RangeMinExpression { get; set; }
+  public string RangeMaxExpression { get; set; }
+  public ConstraintNode(string ident) {
+    this.Ident = ident;
+  }
+}
+
+public class RuleNode {
+  public string NtSymbol { get; set; }
+  public string LocalCode { get; set; }
+  public RuleExprNode RuleExpr { get; set; }
+}
+
+public class RuleExprNode { }
+
+public class AlternativesNode : RuleExprNode {
+  private List<RuleExprNode> alt;
+  public IEnumerable<RuleExprNode> Alternatives { get { return alt; } }
+  public AlternativesNode() {
+    this.alt = new List<RuleExprNode>();
+  }
+  public void Add(RuleExprNode expr) {
+    alt.Add(expr);
+  }
+}
+
+public class SequenceNode : RuleExprNode {
+  private readonly List<RuleExprNode> seq;
+  public IEnumerable<RuleExprNode> Sequence { get { return seq; } }
+  public SequenceNode() {
+    seq = new List<RuleExprNode>();
+  }
+  public void Add(RuleExprNode expr) {
+    seq.Add(expr);
+  }
+}
+
+public class CallSymbolNode : RuleExprNode {
+  public string Ident { get; set; }
+  public string ActualParameter { get; set; }
+}
+
+public class RuleActionNode : RuleExprNode {
+  public string SrcCode { get; set; }
+}
Index: /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/GPDef.atg
===================================================================
--- /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/GPDef.atg	(revision 10056)
+++ /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/GPDef.atg	(revision 10056)
@@ -0,0 +1,257 @@
+/* HeuristicLab
+ * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Coco/R grammar for the GPDL compiler
+
+$namespace=HeuristicLab.Problems.GPDL
+
+using System.Text;
+using System.Collections.Generic;
+using System.Linq;
+using IEnumerableConstraintNode = System.Collections.Generic.IEnumerable<ConstraintNode>;
+
+COMPILER GPDef
+public GPDefNode AbstractSyntaxTree { get; private set; }
+
+CHARACTERS
+  letter = 'A'..'Z' + 'a'..'z'.
+  digit = '0'..'9'.
+
+TOKENS
+  ident = letter {letter | digit}  .
+
+COMMENTS
+  FROM "/*" TO "*/" NESTED
+
+IGNORE '\t' + '\r' + '\n'
+
+
+PRODUCTIONS
+
+  SourceCode<out string src> =                                                    (. src = ""; .)
+   "<<"                                                                           (. int beg = la.pos; .)
+   {ANY}                                                                          (. int end = la.pos; .)
+   ">>"                                                                           (. if(end>beg) src = scanner.buffer.GetString(beg, end); .)
+  .
+
+  GPDef =                                                                         (.
+                                                                                    RuleNode ruleNode = null;
+                                                                                    GPDefNode gpDef = new GPDefNode();
+                                                                                    NonTerminalNode ntNode = null;
+                                                                                    FitnessFunctionNode fitnessFunNode = null;
+                                                                                    TerminalNode tNode = null;
+                                                                                    string src = "";
+                                                                                  .)
+    "PROBLEM" ident                                                               (. gpDef.Name = t.val; .)
+    ["CODE" SourceCode<out src>                                                   (. gpDef.ClassCodeNode = new CodeNode{SrcCode = src}; .)
+    ]
+    ["INIT" SourceCode<out src>                                                   (. gpDef.InitCodeNode = new CodeNode{SrcCode = src}; .)
+    ]
+
+    "NONTERMINALS" { NonterminalDecl<out ntNode>                                  (. if(gpDef.IsSymbolDefined(ntNode)) {
+                                                                                       SemErr("Duplicate non-terminal symbol: " + ntNode.Ident);
+                                                                                     } else {
+                                                                                       gpDef.NonTerminals.Add(ntNode);
+                                                                                     } 
+                                                                                  .)
+    }                                                                             (. if(!gpDef.NonTerminals.Any())
+                                                                                       SemErr("No non-terminal symbols defined.");
+                                                                                  .)
+    "TERMINALS" { TerminalDecl<out tNode>                                         (. if(gpDef.IsSymbolDefined(tNode)) {
+                                                                                       SemErr("Duplicate terminal symbol: " + tNode.Ident);
+                                                                                     } else {
+                                                                                       gpDef.Terminals.Add(tNode); 
+                                                                                     }
+                                                                                  .)
+    }                                                                             (. if(!gpDef.Terminals.Any())
+                                                                                       SemErr("No terminal symbols defined.");
+                                                                                  .)
+    "RULES" { RuleDef<out ruleNode>                                               (. 
+                                                                                     if(!gpDef.IsNonTerminalDefined(ruleNode.NtSymbol)) {
+                                                                                       SemErr("Non-terminal symbol " + ruleNode.NtSymbol + " is not defined in the NONTERMINALS section.");
+                                                                                     } else if(gpDef.IsRuleDefined(ruleNode)) {
+                                                                                       SemErr("Duplicate rule definition for non-terminal symbol " + ruleNode.NtSymbol);
+                                                                                     } else {
+                                                                                       gpDef.Rules.Add(ruleNode);
+                                                                                     } 
+                                                                                   .)
+    }                                                                             (.
+                                                                                     var undefinedNT = gpDef.UndefinedNonTerminals();
+                                                                                     if(!string.IsNullOrEmpty(undefinedNT)) {
+                                                                                       SemErr("Rules missing in the RULES section for: " + undefinedNT);
+                                                                                     }
+                                                                                  .)
+                                                                                  (. fitnessFunNode = new FitnessFunctionNode();
+                                                                                     gpDef.FitnessFunctionNode = fitnessFunNode;
+                                                                                  .)
+    ("MAXIMIZE"                                                                   (. fitnessFunNode.Maximization = true; .)
+    | "MINIMIZE"                                                                  (. fitnessFunNode.Maximization = false; .)
+    )
+     SourceCode<out src>                                                          (. fitnessFunNode.SrcCode = src; .)
+                                                                                  (. if(errors.count > 0) throw new FatalError("Syntactic or semantic errors found."); .)
+    "END" ident                                                                   (.
+                                                                                    AbstractSyntaxTree = gpDef;
+                                                                                  .)
+    '.'
+  .
+
+
+  /******************************************************/
+  SemAction<out RuleActionNode action> =                                          (. RuleActionNode myAction = null; action = null; string src = ""; .)
+    "SEM" SourceCode<out src>                                                     (.
+                                                                                    myAction = new RuleActionNode();
+                                                                                    myAction.SrcCode = src;
+                                                                                    action = myAction;
+                                                                                  .)
+  .
+
+  /******************************************************/
+  NonterminalDecl<out NonTerminalNode ntNode> =                                   (. string identStr = ""; ntNode = null; string src = ""; .)
+    ident                                                                         (. identStr = t.val; .)
+    [ SourceCode<out src> ]                                                       (.
+                                                                                    var myNtNode = new NonTerminalNode();
+                                                                                    ntNode = myNtNode;
+                                                                                    myNtNode.Ident = identStr;
+                                                                                    myNtNode.FormalParameters = src;
+                                                                                  .)
+    '.'
+  .
+
+  /******************************************************/
+  TerminalDecl<out TerminalNode tNode> =                                          (.
+                                                                                    string identStr = "";
+                                                                                    tNode = null;
+                                                                                    TerminalNode myTNode = null;
+                                                                                    IEnumerableConstraintNode constraints = new List<ConstraintNode>();
+                                                                                    string src = "";
+                                                                                  .)
+  ident                                                                           (. identStr = t.val; .) 
+  [ SourceCode<out src> ]                                                         (.
+                                                                                         myTNode = new TerminalNode();
+                                                                                         tNode = myTNode;
+                                                                                         myTNode.Ident = identStr;
+                                                                                         myTNode.FormalParameters = src;
+                                                                                         myTNode.FieldDefinitions = Util.ExtractFormalParameters(src);
+                                                                                  .)
+  [ "CONSTRAINTS" ConstraintDef<out constraints>
+  ]                                                                               (. myTNode.Constraints = constraints; .)
+  '.'
+  .
+
+
+  /******************************************************/
+  ConstraintDef<out IEnumerableConstraintNode constraints>  =                   (.
+                                                                                    List<ConstraintNode> constraintsList = new List<ConstraintNode>();
+                                                                                    ConstraintNode n = null;
+                                                                                    constraints = null;
+                                                                                  .)
+    { ConstraintRule<out n>                                                       (. constraintsList.Add(n); .)
+    }
+                                                                                  (. constraints = constraintsList; .)
+  .
+
+  /******************************************************/
+  ConstraintRule<out ConstraintNode constraint> =                                 (.
+                                                                                    constraint = null;
+                                                                                  .)
+    ident                                                                         (. constraint = new ConstraintNode(t.val); .)
+    "IN" SetDefinition<constraint>                                               
+  .
+
+  /******************************************************/
+  SetDefinition<ConstraintNode constraint> =                                      (. string src = ""; .)
+    ("SET"                                                                        (. constraint.Type = ConstraintNodeType.Set; .)
+     SourceCode<out src>                                                          (. constraint.SetExpression = src; .)
+     |
+     "RANGE"                                                                      (. constraint.Type = ConstraintNodeType.Range; .)
+     SourceCode<out src>                                                          (. constraint.RangeMinExpression = src; .)
+     ".." SourceCode<out src>                                                     (. constraint.RangeMaxExpression = src; .)
+    )
+  .
+
+  /******************************************************/
+  RuleDef<out RuleNode rule> =                                                    (.
+                                                                                     RuleExprNode expr = null;
+                                                                                     string identStr = null;
+                                                                                     RuleNode myRule = null;
+                                                                                     rule = null;
+                                                                                     string src = "";
+                                                                                  .)
+  ident                                                                           (. identStr = t.val; .) 
+  [ SourceCode<out src> ] '='                                                     (.
+                                                                                     myRule = new RuleNode();
+                                                                                     rule = myRule;
+                                                                                     myRule.NtSymbol = identStr;
+                                                                                  .)
+  ["LOCAL" SourceCode<out src>                                                    (.
+                                                                                     myRule.LocalCode = src;
+                                                                                  .)
+  ]
+  SynExpr<out expr> '.'                                                          (.
+                                                                                    myRule.RuleExpr = expr;
+                                                                                 .)
+  .
+
+  /******************************************************/
+  SynExpr<out RuleExprNode expr > =                                               (.
+                                                                                    expr = null;
+                                                                                    AlternativesNode alt = null;
+                                                                                  .)
+  SynTerm<out expr>                                                               (.
+                                                                                    alt = new AlternativesNode();
+                                                                                    alt.Add(expr);
+                                                                                  .)
+  {
+    '|' SynTerm<out expr>                                                         (. alt.Add(expr); expr = alt; .)
+  }
+  .
+
+  /******************************************************/
+  SynTerm<out RuleExprNode expr> =                                               (. SequenceNode seq = null; expr = null; .)
+  SynFact<out expr>                                                              (.
+                                                                                   seq = new SequenceNode();
+                                                                                   seq.Add(expr);
+                                                                                 .)
+  {
+    SynFact<out expr>                                                            (. seq.Add(expr); expr = seq; .)
+  }
+  .
+
+  /******************************************************/
+  SynFact<out RuleExprNode expr> =                                               (.
+                                                                                   string identStr = "";
+                                                                                   RuleActionNode action = null;
+                                                                                   expr = null;
+                                                                                   string src = "";
+                                                                                 .)
+    (ident                                                                       (. identStr = t.val; .)
+     [ SourceCode<out src> ]                                                     (.
+                                                                                    var callNode = new CallSymbolNode{Ident = identStr};
+                                                                                    callNode.ActualParameter = src;
+                                                                                    expr = callNode;
+                                                                                 .)
+// not implemented   | "EPS" 
+// not implemented   | '(' SynExpr<ref rules, mBuilder> ')'
+// not implemented   | '[' SynExpr<ref rules, mBuilder> ']'
+// not implemented   | '{' SynExpr<ref rules, mBuilder> '}'
+     | SemAction<out action>                                                     (. expr = action; .)
+    )
+  .
+
+END GPDef.
Index: /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/Grammar.cs
===================================================================
--- /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/Grammar.cs	(revision 10056)
+++ /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/Grammar.cs	(revision 10056)
@@ -0,0 +1,168 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+public class Grammar {
+  private class Sequence : List<string> {
+    public override string ToString() {
+      var sb = new StringBuilder();
+      foreach (var e in this) {
+        sb.Append(e).Append(" ");
+      }
+      return sb.ToString();
+    }
+  }
+  private class Alternatives : List<Sequence> {
+    public override string ToString() {
+      var sb = new StringBuilder();
+      if (Count == 0)
+        sb.Append("EPS");
+      else
+        sb.Append(this[0]);
+      foreach (var e in this.Skip(1)) {
+        sb.Append("| ").Append(e);
+      }
+      return sb.ToString();
+    }
+  }
+
+  private Dictionary<string, Alternatives> alternatives = new Dictionary<string, Alternatives>();
+  private Dictionary<string, string> localDefinitions = new Dictionary<string, string>();
+  private Dictionary<string, List<IEnumerable<RuleExprNode>>> seqWithActions = new Dictionary<string, List<IEnumerable<RuleExprNode>>>();
+  public string RootSymbol { get; private set; }
+  public IEnumerable<string> Symbols { get; private set; }
+
+  public Grammar(IEnumerable<SymbolNode> ntSymbols, IEnumerable<SymbolNode> tSymbols, List<RuleNode> ruleNodes) {
+    CheckGrammarConstraints(ntSymbols, tSymbols, ruleNodes);
+    foreach (var ruleNode in ruleNodes) {
+      alternatives[ruleNode.NtSymbol] = ToAlternatives(ruleNode.RuleExpr);
+      localDefinitions[ruleNode.NtSymbol] = ruleNode.LocalCode;
+      seqWithActions[ruleNode.NtSymbol] = ToAlternativesWithActions(ruleNode.RuleExpr);
+    }
+    RootSymbol = ruleNodes.First().NtSymbol;
+    Symbols = ntSymbols.Select(n => n.Ident).Concat(tSymbols.Select(n => n.Ident)).ToList();
+  }
+
+  private List<IEnumerable<RuleExprNode>> ToAlternativesWithActions(RuleExprNode ruleExprNode) {
+    var l = new List<IEnumerable<RuleExprNode>>();
+    var altNode = ruleExprNode as AlternativesNode;
+    if (altNode != null) {
+      l.AddRange(altNode.Alternatives.Select(expr => Flatten(expr)));
+    } else {
+      l.Add(Flatten(ruleExprNode));
+    }
+    return l;
+  }
+
+  private IEnumerable<RuleExprNode> Flatten(RuleExprNode expr) {
+    var seqNode = expr as SequenceNode;
+    var callNode = expr as CallSymbolNode;
+    var actionNode = expr as RuleActionNode;
+    if (seqNode != null) {
+      return seqNode.Sequence;
+    } else if (callNode != null) {
+      return Enumerable.Repeat(callNode, 1);
+    } else if (actionNode != null) {
+      return Enumerable.Repeat(actionNode, 1);
+    } else {
+      throw new NotSupportedException();
+    }
+  }
+
+  public IEnumerable<List<string>> GetAlternatives(string sy) {
+    if (!alternatives.ContainsKey(sy)) return Enumerable.Empty<List<string>>();
+    return alternatives[sy];
+  }
+
+  public string GetLocalDefinitions(string sy) {
+    if (!localDefinitions.ContainsKey(sy)) return string.Empty;
+    return localDefinitions[sy];
+  }
+
+  private Alternatives ToAlternatives(RuleExprNode ruleExprNode) {
+    var alt = new Alternatives();
+    var altNode = ruleExprNode as AlternativesNode;
+    if (altNode != null) {
+      alt.AddRange(altNode.Alternatives.Select(expr => ToSequence(expr)));
+    } else {
+      alt.Add(ToSequence(ruleExprNode));
+    }
+    return alt;
+  }
+
+  private Sequence ToSequence(RuleExprNode ruleExprNode) {
+    var seqNode = ruleExprNode as SequenceNode;
+    var callNode = ruleExprNode as CallSymbolNode;
+    var actionNode = ruleExprNode as RuleActionNode;
+    var seq = new Sequence();
+    if (seqNode != null) {
+      // keep only the nodes refering to symbols
+      seq.AddRange(seqNode.Sequence.OfType<CallSymbolNode>().Select(n => n.Ident));
+    } else if (callNode != null) {
+      seq.Add(callNode.Ident);
+    } else if (actionNode != null) {
+      throw new NotSupportedException();
+    } else {
+      throw new NotSupportedException();
+    }
+    return seq;
+  }
+
+  public IEnumerable<RuleExprNode> GetSequenceWithSemanticActions(string sy, int altIdx) {
+    return seqWithActions[sy][altIdx];
+  }
+
+  // should be checked when reading the grammar?
+  private void CheckGrammarConstraints(IEnumerable<SymbolNode> ntSymbols, IEnumerable<SymbolNode> tSymbols, List<RuleNode> rules) {
+    /* rules: 
+     *  - one rule for each non-terminal symbol 
+     *  - LL(1)
+     *  - alternatives have to be single-symbol chains
+     *  - all symbols used on the right hand side have to be defined
+     */
+
+    //// only one rule for non-terminal symbols
+    //var dupSymbols = rules.GroupBy(r => r.NtSymbol).Where(g => g.Count() > 1);
+    //if (dupSymbols.Count() > 0) throw new ArgumentException("Two grammar rules for " + dupSymbols.Select(g => g.Key).Aggregate("", (s, s1) => s + ", " + s1));
+
+    //// a rule for all non-terminal symbols
+    //foreach (var ntSymbol in ntSymbols) {
+    //  if (rules.All(r => r.NtSymbol != ntSymbol.Ident)) throw new ArgumentException("No grammar rule for NTSymbol " + ntSymbol);
+    //}
+
+    //foreach (var r in rules) {
+
+    //}
+  }
+
+  public override string ToString() {
+    var sb = new StringBuilder();
+    foreach (var entry in alternatives) {
+      sb.Append(entry.Key).Append(" -> ").AppendLine(entry.Value.ToString());
+    }
+    return sb.ToString();
+  }
+
+}
Index: /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/HeuristicLab.Problems.GPDL-3.4.csproj
===================================================================
--- /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/HeuristicLab.Problems.GPDL-3.4.csproj	(revision 10056)
+++ /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/HeuristicLab.Problems.GPDL-3.4.csproj	(revision 10056)
@@ -0,0 +1,157 @@
+﻿<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>9.0.30729</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{E4EE5AFB-D552-447B-8A16-6CBE7938AF32}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>HeuristicLab.Problems.GPDL</RootNamespace>
+    <AssemblyName>HeuristicLab.Problems.GPDL-3.4</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <TargetFrameworkProfile>
+    </TargetFrameworkProfile>
+    <FileAlignment>512</FileAlignment>
+    <SignAssembly>true</SignAssembly>
+    <AssemblyOriginatorKeyFile>HeuristicLab.snk</AssemblyOriginatorKeyFile>
+    <FileUpgradeFlags>
+    </FileUpgradeFlags>
+    <OldToolsVersion>3.5</OldToolsVersion>
+    <UpgradeBackupLocation />
+    <PublishUrl>publish\</PublishUrl>
+    <Install>true</Install>
+    <InstallFrom>Disk</InstallFrom>
+    <UpdateEnabled>false</UpdateEnabled>
+    <UpdateMode>Foreground</UpdateMode>
+    <UpdateInterval>7</UpdateInterval>
+    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+    <UpdatePeriodically>false</UpdatePeriodically>
+    <UpdateRequired>false</UpdateRequired>
+    <MapFileExtensions>true</MapFileExtensions>
+    <ApplicationRevision>0</ApplicationRevision>
+    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+    <IsWebBootstrapper>false</IsWebBootstrapper>
+    <UseApplicationTrust>false</UseApplicationTrust>
+    <BootstrapperEnabled>true</BootstrapperEnabled>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DebugType>full</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
+    <OutputPath>bin\x64\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <Optimize>true</Optimize>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DebugType>full</DebugType>
+    <PlatformTarget>x86</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <OutputPath>bin\x86\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <Optimize>true</Optimize>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>x86</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Drawing" />
+    <Reference Include="System.Windows.Forms" />
+    <Reference Include="System.Windows.Forms.DataVisualization" />
+    <Reference Include="System.Xml.Linq">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Data.DataSetExtensions">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="AST.cs" />
+    <Compile Include="Grammar.cs" />
+    <Compile Include="Parser.cs" />
+    <Compile Include="Scanner.cs" />
+    <Compile Include="Util.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <None Include="GPDef.atg" />
+    <None Include="HeuristicLab.snk" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
+      <Visible>False</Visible>
+      <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
+      <Install>false</Install>
+    </BootstrapperPackage>
+    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+      <Visible>False</Visible>
+      <ProductName>.NET Framework 3.5 SP1</ProductName>
+      <Install>true</Install>
+    </BootstrapperPackage>
+    <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
+      <Visible>False</Visible>
+      <ProductName>Windows Installer 3.1</ProductName>
+      <Install>true</Install>
+    </BootstrapperPackage>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+  <PropertyGroup>
+    <PreBuildEvent>set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
+set ProjectDir=$(ProjectDir)
+set SolutionDir=$(SolutionDir)
+set Outdir=$(Outdir)
+
+call PreBuildEvent.cmd
+call GenerateFromAtg.cmd</PreBuildEvent>
+  </PropertyGroup>
+</Project>
Index: /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/Parser.cs
===================================================================
--- /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/Parser.cs	(revision 10056)
+++ /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/Parser.cs	(revision 10056)
@@ -0,0 +1,439 @@
+using System.Text;
+using System.Collections.Generic;
+using System.Linq;
+using IEnumerableConstraintNode = System.Collections.Generic.IEnumerable<ConstraintNode>;
+
+
+
+using System;
+
+namespace HeuristicLab.Problems.GPDL {
+
+
+
+public class Parser {
+	public const int _EOF = 0;
+	public const int _ident = 1;
+	public const int maxT = 23;
+
+	const bool T = true;
+	const bool x = false;
+	const int minErrDist = 2;
+	
+	public Scanner scanner;
+	public Errors  errors;
+
+	public Token t;    // last recognized token
+	public Token la;   // lookahead token
+	int errDist = minErrDist;
+
+public GPDefNode AbstractSyntaxTree { get; private set; }
+
+
+
+	public Parser(Scanner scanner) {
+		this.scanner = scanner;
+		errors = new Errors();
+	}
+
+	void SynErr (int n) {
+		if (errDist >= minErrDist) errors.SynErr(la.line, la.col, n);
+		errDist = 0;
+	}
+
+	public void SemErr (string msg) {
+		if (errDist >= minErrDist) errors.SemErr(t.line, t.col, msg);
+		errDist = 0;
+	}
+	
+	void Get () {
+		for (;;) {
+			t = la;
+			la = scanner.Scan();
+			if (la.kind <= maxT) { ++errDist; break; }
+
+			la = t;
+		}
+	}
+	
+	void Expect (int n) {
+		if (la.kind==n) Get(); else { SynErr(n); }
+	}
+	
+	bool StartOf (int s) {
+		return set[s, la.kind];
+	}
+	
+	void ExpectWeak (int n, int follow) {
+		if (la.kind == n) Get();
+		else {
+			SynErr(n);
+			while (!StartOf(follow)) Get();
+		}
+	}
+
+
+	bool WeakSeparator(int n, int syFol, int repFol) {
+		int kind = la.kind;
+		if (kind == n) {Get(); return true;}
+		else if (StartOf(repFol)) {return false;}
+		else {
+			SynErr(n);
+			while (!(set[syFol, kind] || set[repFol, kind] || set[0, kind])) {
+				Get();
+				kind = la.kind;
+			}
+			return StartOf(syFol);
+		}
+	}
+
+	
+	void SourceCode(out string src) {
+		src = ""; 
+		Expect(2);
+		int beg = la.pos; 
+		while (StartOf(1)) {
+			Get();
+		}
+		int end = la.pos; 
+		Expect(3);
+		if(end>beg) src = scanner.buffer.GetString(beg, end); 
+	}
+
+	void GPDef() {
+		RuleNode ruleNode = null;
+		GPDefNode gpDef = new GPDefNode();
+		NonTerminalNode ntNode = null;
+		FitnessFunctionNode fitnessFunNode = null;
+		TerminalNode tNode = null;
+		string src = "";
+		
+		Expect(4);
+		Expect(1);
+		gpDef.Name = t.val; 
+		if (la.kind == 5) {
+			Get();
+			SourceCode(out src);
+			gpDef.ClassCodeNode = new CodeNode{SrcCode = src}; 
+		}
+		if (la.kind == 6) {
+			Get();
+			SourceCode(out src);
+			gpDef.InitCodeNode = new CodeNode{SrcCode = src}; 
+		}
+		Expect(7);
+		while (la.kind == 1) {
+			NonterminalDecl(out ntNode);
+			if(gpDef.IsSymbolDefined(ntNode)) {
+			 SemErr("Duplicate non-terminal symbol: " + ntNode.Ident);
+			} else {
+			 gpDef.NonTerminals.Add(ntNode);
+			} 
+			
+		}
+		if(!gpDef.NonTerminals.Any())
+		 SemErr("No non-terminal symbols defined.");
+		
+		Expect(8);
+		while (la.kind == 1) {
+			TerminalDecl(out tNode);
+			if(gpDef.IsSymbolDefined(tNode)) {
+			 SemErr("Duplicate terminal symbol: " + tNode.Ident);
+			} else {
+			 gpDef.Terminals.Add(tNode); 
+			}
+			
+		}
+		if(!gpDef.Terminals.Any())
+		 SemErr("No terminal symbols defined.");
+		
+		Expect(9);
+		while (la.kind == 1) {
+			RuleDef(out ruleNode);
+			if(!gpDef.IsNonTerminalDefined(ruleNode.NtSymbol)) {
+			 SemErr("Non-terminal symbol " + ruleNode.NtSymbol + " is not defined in the NONTERMINALS section.");
+			} else if(gpDef.IsRuleDefined(ruleNode)) {
+			 SemErr("Duplicate rule definition for non-terminal symbol " + ruleNode.NtSymbol);
+			} else {
+			 gpDef.Rules.Add(ruleNode);
+			} 
+			
+		}
+		var undefinedNT = gpDef.UndefinedNonTerminals();
+		if(!string.IsNullOrEmpty(undefinedNT)) {
+		 SemErr("Rules missing in the RULES section for: " + undefinedNT);
+		}
+		
+		fitnessFunNode = new FitnessFunctionNode();
+		gpDef.FitnessFunctionNode = fitnessFunNode;
+		
+		if (la.kind == 10) {
+			Get();
+			fitnessFunNode.Maximization = true; 
+		} else if (la.kind == 11) {
+			Get();
+			fitnessFunNode.Maximization = false; 
+		} else SynErr(24);
+		SourceCode(out src);
+		fitnessFunNode.SrcCode = src; 
+		if(errors.count > 0) throw new FatalError("Syntactic or semantic errors found."); 
+		Expect(12);
+		Expect(1);
+		AbstractSyntaxTree = gpDef;
+		
+		Expect(13);
+	}
+
+	void NonterminalDecl(out NonTerminalNode ntNode) {
+		string identStr = ""; ntNode = null; string src = ""; 
+		Expect(1);
+		identStr = t.val; 
+		if (la.kind == 2) {
+			SourceCode(out src);
+		}
+		var myNtNode = new NonTerminalNode();
+		ntNode = myNtNode;
+		myNtNode.Ident = identStr;
+		myNtNode.FormalParameters = src;
+		
+		Expect(13);
+	}
+
+	void TerminalDecl(out TerminalNode tNode) {
+		string identStr = "";
+		tNode = null;
+		TerminalNode myTNode = null;
+		IEnumerableConstraintNode constraints = new List<ConstraintNode>();
+		string src = "";
+		
+		Expect(1);
+		identStr = t.val; 
+		if (la.kind == 2) {
+			SourceCode(out src);
+		}
+		myTNode = new TerminalNode();
+		tNode = myTNode;
+		myTNode.Ident = identStr;
+		myTNode.FormalParameters = src;
+		myTNode.FieldDefinitions = Util.ExtractFormalParameters(src);
+		
+		if (la.kind == 15) {
+			Get();
+			ConstraintDef(out constraints);
+		}
+		myTNode.Constraints = constraints; 
+		Expect(13);
+	}
+
+	void RuleDef(out RuleNode rule) {
+		RuleExprNode expr = null;
+		string identStr = null;
+		RuleNode myRule = null;
+		rule = null;
+		string src = "";
+		
+		Expect(1);
+		identStr = t.val; 
+		if (la.kind == 2) {
+			SourceCode(out src);
+		}
+		Expect(20);
+		myRule = new RuleNode();
+		rule = myRule;
+		myRule.NtSymbol = identStr;
+		
+		if (la.kind == 21) {
+			Get();
+			SourceCode(out src);
+			myRule.LocalCode = src;
+			
+		}
+		SynExpr(out expr);
+		Expect(13);
+		myRule.RuleExpr = expr;
+		
+	}
+
+	void SemAction(out RuleActionNode action) {
+		RuleActionNode myAction = null; action = null; string src = ""; 
+		Expect(14);
+		SourceCode(out src);
+		myAction = new RuleActionNode();
+		myAction.SrcCode = src;
+		action = myAction;
+		
+	}
+
+	void ConstraintDef(out IEnumerableConstraintNode constraints) {
+		List<ConstraintNode> constraintsList = new List<ConstraintNode>();
+		ConstraintNode n = null;
+		constraints = null;
+		
+		while (la.kind == 1) {
+			ConstraintRule(out n);
+			constraintsList.Add(n); 
+		}
+		constraints = constraintsList; 
+	}
+
+	void ConstraintRule(out ConstraintNode constraint) {
+		constraint = null;
+		
+		Expect(1);
+		constraint = new ConstraintNode(t.val); 
+		Expect(16);
+		SetDefinition(constraint);
+	}
+
+	void SetDefinition(ConstraintNode constraint) {
+		string src = ""; 
+		if (la.kind == 17) {
+			Get();
+			constraint.Type = ConstraintNodeType.Set; 
+			SourceCode(out src);
+			constraint.SetExpression = src; 
+		} else if (la.kind == 18) {
+			Get();
+			constraint.Type = ConstraintNodeType.Range; 
+			SourceCode(out src);
+			constraint.RangeMinExpression = src; 
+			Expect(19);
+			SourceCode(out src);
+			constraint.RangeMaxExpression = src; 
+		} else SynErr(25);
+	}
+
+	void SynExpr(out RuleExprNode expr ) {
+		expr = null;
+		AlternativesNode alt = null;
+		
+		SynTerm(out expr);
+		alt = new AlternativesNode();
+		alt.Add(expr);
+		
+		while (la.kind == 22) {
+			Get();
+			SynTerm(out expr);
+			alt.Add(expr); expr = alt; 
+		}
+	}
+
+	void SynTerm(out RuleExprNode expr) {
+		SequenceNode seq = null; expr = null; 
+		SynFact(out expr);
+		seq = new SequenceNode();
+		seq.Add(expr);
+		
+		while (la.kind == 1 || la.kind == 14) {
+			SynFact(out expr);
+			seq.Add(expr); expr = seq; 
+		}
+	}
+
+	void SynFact(out RuleExprNode expr) {
+		string identStr = "";
+		RuleActionNode action = null;
+		expr = null;
+		string src = "";
+		
+		if (la.kind == 1) {
+			Get();
+			identStr = t.val; 
+			if (la.kind == 2) {
+				SourceCode(out src);
+			}
+			var callNode = new CallSymbolNode{Ident = identStr};
+			callNode.ActualParameter = src;
+			expr = callNode;
+			
+		} else if (la.kind == 14) {
+			SemAction(out action);
+			expr = action; 
+		} else SynErr(26);
+	}
+
+
+
+	public void Parse() {
+		la = new Token();
+		la.val = "";		
+		Get();
+		GPDef();
+		Expect(0);
+
+	}
+	
+	static readonly bool[,] set = {
+		{T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x},
+		{x,T,T,x, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, x}
+
+	};
+} // end Parser
+
+
+public class Errors {
+	public int count = 0;                                    // number of errors detected
+	public System.IO.TextWriter errorStream = Console.Out;   // error messages go to this stream
+	public string errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text
+
+	public virtual void SynErr (int line, int col, int n) {
+		string s;
+		switch (n) {
+			case 0: s = "EOF expected"; break;
+			case 1: s = "ident expected"; break;
+			case 2: s = "\"<<\" expected"; break;
+			case 3: s = "\">>\" expected"; break;
+			case 4: s = "\"PROBLEM\" expected"; break;
+			case 5: s = "\"CODE\" expected"; break;
+			case 6: s = "\"INIT\" expected"; break;
+			case 7: s = "\"NONTERMINALS\" expected"; break;
+			case 8: s = "\"TERMINALS\" expected"; break;
+			case 9: s = "\"RULES\" expected"; break;
+			case 10: s = "\"MAXIMIZE\" expected"; break;
+			case 11: s = "\"MINIMIZE\" expected"; break;
+			case 12: s = "\"END\" expected"; break;
+			case 13: s = "\".\" expected"; break;
+			case 14: s = "\"SEM\" expected"; break;
+			case 15: s = "\"CONSTRAINTS\" expected"; break;
+			case 16: s = "\"IN\" expected"; break;
+			case 17: s = "\"SET\" expected"; break;
+			case 18: s = "\"RANGE\" expected"; break;
+			case 19: s = "\"..\" expected"; break;
+			case 20: s = "\"=\" expected"; break;
+			case 21: s = "\"LOCAL\" expected"; break;
+			case 22: s = "\"|\" expected"; break;
+			case 23: s = "??? expected"; break;
+			case 24: s = "invalid GPDef"; break;
+			case 25: s = "invalid SetDefinition"; break;
+			case 26: s = "invalid SynFact"; break;
+
+			default: s = "error " + n; break;
+		}
+		errorStream.WriteLine(errMsgFormat, line, col, s);
+		count++;
+	}
+
+	public virtual void SemErr (int line, int col, string s) {
+		errorStream.WriteLine(errMsgFormat, line, col, s);
+		count++;
+	}
+	
+	public virtual void SemErr (string s) {
+		errorStream.WriteLine(s);
+		count++;
+	}
+	
+	public virtual void Warning (int line, int col, string s) {
+		errorStream.WriteLine(errMsgFormat, line, col, s);
+	}
+	
+	public virtual void Warning(string s) {
+		errorStream.WriteLine(s);
+	}
+} // Errors
+
+
+public class FatalError: Exception {
+	public FatalError(string m): base(m) {}
+}
+}
Index: /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/Plugin.cs
===================================================================
--- /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/Plugin.cs	(revision 10056)
+++ /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/Plugin.cs	(revision 10056)
@@ -0,0 +1,29 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using HeuristicLab.PluginInfrastructure;
+
+namespace HeuristicLab.Problems.GPDL {
+  [Plugin("HeuristicLab.Problems.GPDL","Provides classes to define genetic programming problems using GPDL.", "3.4.0.9872")]
+  [PluginFile("HeuristicLab.Problems.GPDL-3.4.dll", PluginFileType.Assembly)]
+  public class Plugin : PluginBase {
+  }
+}
Index: /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/Properties/AssemblyInfo.cs
===================================================================
--- /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/Properties/AssemblyInfo.cs	(revision 10056)
+++ /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/Properties/AssemblyInfo.cs	(revision 10056)
@@ -0,0 +1,53 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System.Reflection;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("HeuristicLab.Problems.GPDL")]
+[assembly: AssemblyDescription("Provides classes to create genetic programming problems using GPDL.")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("HeuristicLab")]
+[assembly: AssemblyCopyright("(c) 2002-2013 HEAL")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("B3B18403-394F-423D-ADD0-C65EF47D42E2")]
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers 
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("3.4.0.0")]
Index: /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/Scanner.cs
===================================================================
--- /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/Scanner.cs	(revision 10056)
+++ /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/Scanner.cs	(revision 10056)
@@ -0,0 +1,434 @@
+
+using System;
+using System.IO;
+using System.Collections;
+
+namespace HeuristicLab.Problems.GPDL {
+
+public class Token {
+	public int kind;    // token kind
+	public int pos;     // token position in bytes in the source text (starting at 0)
+	public int charPos;  // token position in characters in the source text (starting at 0)
+	public int col;     // token column (starting at 1)
+	public int line;    // token line (starting at 1)
+	public string val;  // token value
+	public Token next;  // ML 2005-03-11 Tokens are kept in linked list
+}
+
+//-----------------------------------------------------------------------------------
+// Buffer
+//-----------------------------------------------------------------------------------
+public class Buffer {
+	// This Buffer supports the following cases:
+	// 1) seekable stream (file)
+	//    a) whole stream in buffer
+	//    b) part of stream in buffer
+	// 2) non seekable stream (network, console)
+
+	public const int EOF = char.MaxValue + 1;
+	const int MIN_BUFFER_LENGTH = 1024; // 1KB
+	const int MAX_BUFFER_LENGTH = MIN_BUFFER_LENGTH * 64; // 64KB
+	byte[] buf;         // input buffer
+	int bufStart;       // position of first byte in buffer relative to input stream
+	int bufLen;         // length of buffer
+	int fileLen;        // length of input stream (may change if the stream is no file)
+	int bufPos;         // current position in buffer
+	Stream stream;      // input stream (seekable)
+	bool isUserStream;  // was the stream opened by the user?
+	
+	public Buffer (Stream s, bool isUserStream) {
+		stream = s; this.isUserStream = isUserStream;
+		
+		if (stream.CanSeek) {
+			fileLen = (int) stream.Length;
+			bufLen = Math.Min(fileLen, MAX_BUFFER_LENGTH);
+			bufStart = Int32.MaxValue; // nothing in the buffer so far
+		} else {
+			fileLen = bufLen = bufStart = 0;
+		}
+
+		buf = new byte[(bufLen>0) ? bufLen : MIN_BUFFER_LENGTH];
+		if (fileLen > 0) Pos = 0; // setup buffer to position 0 (start)
+		else bufPos = 0; // index 0 is already after the file, thus Pos = 0 is invalid
+		if (bufLen == fileLen && stream.CanSeek) Close();
+	}
+	
+	protected Buffer(Buffer b) { // called in UTF8Buffer constructor
+		buf = b.buf;
+		bufStart = b.bufStart;
+		bufLen = b.bufLen;
+		fileLen = b.fileLen;
+		bufPos = b.bufPos;
+		stream = b.stream;
+		// keep destructor from closing the stream
+		b.stream = null;
+		isUserStream = b.isUserStream;
+	}
+
+	~Buffer() { Close(); }
+	
+	protected void Close() {
+		if (!isUserStream && stream != null) {
+			stream.Close();
+			stream = null;
+		}
+	}
+	
+	public virtual int Read () {
+		if (bufPos < bufLen) {
+			return buf[bufPos++];
+		} else if (Pos < fileLen) {
+			Pos = Pos; // shift buffer start to Pos
+			return buf[bufPos++];
+		} else if (stream != null && !stream.CanSeek && ReadNextStreamChunk() > 0) {
+			return buf[bufPos++];
+		} else {
+			return EOF;
+		}
+	}
+
+	public int Peek () {
+		int curPos = Pos;
+		int ch = Read();
+		Pos = curPos;
+		return ch;
+	}
+	
+	// beg .. begin, zero-based, inclusive, in byte
+	// end .. end, zero-based, exclusive, in byte
+	public string GetString (int beg, int end) {
+		int len = 0;
+		char[] buf = new char[end - beg];
+		int oldPos = Pos;
+		Pos = beg;
+		while (Pos < end) buf[len++] = (char) Read();
+		Pos = oldPos;
+		return new String(buf, 0, len);
+	}
+
+	public int Pos {
+		get { return bufPos + bufStart; }
+		set {
+			if (value >= fileLen && stream != null && !stream.CanSeek) {
+				// Wanted position is after buffer and the stream
+				// is not seek-able e.g. network or console,
+				// thus we have to read the stream manually till
+				// the wanted position is in sight.
+				while (value >= fileLen && ReadNextStreamChunk() > 0);
+			}
+
+			if (value < 0 || value > fileLen) {
+				throw new FatalError("buffer out of bounds access, position: " + value);
+			}
+
+			if (value >= bufStart && value < bufStart + bufLen) { // already in buffer
+				bufPos = value - bufStart;
+			} else if (stream != null) { // must be swapped in
+				stream.Seek(value, SeekOrigin.Begin);
+				bufLen = stream.Read(buf, 0, buf.Length);
+				bufStart = value; bufPos = 0;
+			} else {
+				// set the position to the end of the file, Pos will return fileLen.
+				bufPos = fileLen - bufStart;
+			}
+		}
+	}
+	
+	// Read the next chunk of bytes from the stream, increases the buffer
+	// if needed and updates the fields fileLen and bufLen.
+	// Returns the number of bytes read.
+	private int ReadNextStreamChunk() {
+		int free = buf.Length - bufLen;
+		if (free == 0) {
+			// in the case of a growing input stream
+			// we can neither seek in the stream, nor can we
+			// foresee the maximum length, thus we must adapt
+			// the buffer size on demand.
+			byte[] newBuf = new byte[bufLen * 2];
+			Array.Copy(buf, newBuf, bufLen);
+			buf = newBuf;
+			free = bufLen;
+		}
+		int read = stream.Read(buf, bufLen, free);
+		if (read > 0) {
+			fileLen = bufLen = (bufLen + read);
+			return read;
+		}
+		// end of stream reached
+		return 0;
+	}
+}
+
+//-----------------------------------------------------------------------------------
+// UTF8Buffer
+//-----------------------------------------------------------------------------------
+public class UTF8Buffer: Buffer {
+	public UTF8Buffer(Buffer b): base(b) {}
+
+	public override int Read() {
+		int ch;
+		do {
+			ch = base.Read();
+			// until we find a utf8 start (0xxxxxxx or 11xxxxxx)
+		} while ((ch >= 128) && ((ch & 0xC0) != 0xC0) && (ch != EOF));
+		if (ch < 128 || ch == EOF) {
+			// nothing to do, first 127 chars are the same in ascii and utf8
+			// 0xxxxxxx or end of file character
+		} else if ((ch & 0xF0) == 0xF0) {
+			// 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
+			int c1 = ch & 0x07; ch = base.Read();
+			int c2 = ch & 0x3F; ch = base.Read();
+			int c3 = ch & 0x3F; ch = base.Read();
+			int c4 = ch & 0x3F;
+			ch = (((((c1 << 6) | c2) << 6) | c3) << 6) | c4;
+		} else if ((ch & 0xE0) == 0xE0) {
+			// 1110xxxx 10xxxxxx 10xxxxxx
+			int c1 = ch & 0x0F; ch = base.Read();
+			int c2 = ch & 0x3F; ch = base.Read();
+			int c3 = ch & 0x3F;
+			ch = (((c1 << 6) | c2) << 6) | c3;
+		} else if ((ch & 0xC0) == 0xC0) {
+			// 110xxxxx 10xxxxxx
+			int c1 = ch & 0x1F; ch = base.Read();
+			int c2 = ch & 0x3F;
+			ch = (c1 << 6) | c2;
+		}
+		return ch;
+	}
+}
+
+//-----------------------------------------------------------------------------------
+// Scanner
+//-----------------------------------------------------------------------------------
+public class Scanner {
+	const char EOL = '\n';
+	const int eofSym = 0; /* pdt */
+	const int maxT = 23;
+	const int noSym = 23;
+
+
+	public Buffer buffer; // scanner buffer
+	
+	Token t;          // current token
+	int ch;           // current input character
+	int pos;          // byte position of current character
+	int charPos;      // position by unicode characters starting with 0
+	int col;          // column number of current character
+	int line;         // line number of current character
+	int oldEols;      // EOLs that appeared in a comment;
+	static readonly Hashtable start; // maps first token character to start state
+
+	Token tokens;     // list of tokens already peeked (first token is a dummy)
+	Token pt;         // current peek token
+	
+	char[] tval = new char[128]; // text of current token
+	int tlen;         // length of current token
+	
+	static Scanner() {
+		start = new Hashtable(128);
+		for (int i = 65; i <= 90; ++i) start[i] = 1;
+		for (int i = 97; i <= 122; ++i) start[i] = 1;
+		start[60] = 2; 
+		start[62] = 4; 
+		start[46] = 9; 
+		start[61] = 7; 
+		start[124] = 8; 
+		start[Buffer.EOF] = -1;
+
+	}
+	
+	public Scanner (string fileName) {
+		try {
+			Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
+			buffer = new Buffer(stream, false);
+			Init();
+		} catch (IOException) {
+			throw new FatalError("Cannot open file " + fileName);
+		}
+	}
+	
+	public Scanner (Stream s) {
+		buffer = new Buffer(s, true);
+		Init();
+	}
+	
+	void Init() {
+		pos = -1; line = 1; col = 0; charPos = -1;
+		oldEols = 0;
+		NextCh();
+		if (ch == 0xEF) { // check optional byte order mark for UTF-8
+			NextCh(); int ch1 = ch;
+			NextCh(); int ch2 = ch;
+			if (ch1 != 0xBB || ch2 != 0xBF) {
+				throw new FatalError(String.Format("illegal byte order mark: EF {0,2:X} {1,2:X}", ch1, ch2));
+			}
+			buffer = new UTF8Buffer(buffer); col = 0; charPos = -1;
+			NextCh();
+		}
+		pt = tokens = new Token();  // first token is a dummy
+	}
+	
+	void NextCh() {
+		if (oldEols > 0) { ch = EOL; oldEols--; } 
+		else {
+			pos = buffer.Pos;
+			// buffer reads unicode chars, if UTF8 has been detected
+			ch = buffer.Read(); col++; charPos++;
+			// replace isolated '\r' by '\n' in order to make
+			// eol handling uniform across Windows, Unix and Mac
+			if (ch == '\r' && buffer.Peek() != '\n') ch = EOL;
+			if (ch == EOL) { line++; col = 0; }
+		}
+
+	}
+
+	void AddCh() {
+		if (tlen >= tval.Length) {
+			char[] newBuf = new char[2 * tval.Length];
+			Array.Copy(tval, 0, newBuf, 0, tval.Length);
+			tval = newBuf;
+		}
+		if (ch != Buffer.EOF) {
+			tval[tlen++] = (char) ch;
+			NextCh();
+		}
+	}
+
+
+
+	bool Comment0() {
+		int level = 1, pos0 = pos, line0 = line, col0 = col, charPos0 = charPos;
+		NextCh();
+		if (ch == '*') {
+			NextCh();
+			for(;;) {
+				if (ch == '*') {
+					NextCh();
+					if (ch == '/') {
+						level--;
+						if (level == 0) { oldEols = line - line0; NextCh(); return true; }
+						NextCh();
+					}
+				} else if (ch == '/') {
+					NextCh();
+					if (ch == '*') {
+						level++; NextCh();
+					}
+				} else if (ch == Buffer.EOF) return false;
+				else NextCh();
+			}
+		} else {
+			buffer.Pos = pos0; NextCh(); line = line0; col = col0; charPos = charPos0;
+		}
+		return false;
+	}
+
+
+	void CheckLiteral() {
+		switch (t.val) {
+			case "PROBLEM": t.kind = 4; break;
+			case "CODE": t.kind = 5; break;
+			case "INIT": t.kind = 6; break;
+			case "NONTERMINALS": t.kind = 7; break;
+			case "TERMINALS": t.kind = 8; break;
+			case "RULES": t.kind = 9; break;
+			case "MAXIMIZE": t.kind = 10; break;
+			case "MINIMIZE": t.kind = 11; break;
+			case "END": t.kind = 12; break;
+			case "SEM": t.kind = 14; break;
+			case "CONSTRAINTS": t.kind = 15; break;
+			case "IN": t.kind = 16; break;
+			case "SET": t.kind = 17; break;
+			case "RANGE": t.kind = 18; break;
+			case "LOCAL": t.kind = 21; break;
+			default: break;
+		}
+	}
+
+	Token NextToken() {
+		while (ch == ' ' ||
+			ch >= 9 && ch <= 10 || ch == 13
+		) NextCh();
+		if (ch == '/' && Comment0()) return NextToken();
+		int recKind = noSym;
+		int recEnd = pos;
+		t = new Token();
+		t.pos = pos; t.col = col; t.line = line; t.charPos = charPos;
+		int state;
+		if (start.ContainsKey(ch)) { state = (int) start[ch]; }
+		else { state = 0; }
+		tlen = 0; AddCh();
+		
+		switch (state) {
+			case -1: { t.kind = eofSym; break; } // NextCh already done
+			case 0: {
+				if (recKind != noSym) {
+					tlen = recEnd - t.pos;
+					SetScannerBehindT();
+				}
+				t.kind = recKind; break;
+			} // NextCh already done
+			case 1:
+				recEnd = pos; recKind = 1;
+				if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;}
+				else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
+			case 2:
+				if (ch == '<') {AddCh(); goto case 3;}
+				else {goto case 0;}
+			case 3:
+				{t.kind = 2; break;}
+			case 4:
+				if (ch == '>') {AddCh(); goto case 5;}
+				else {goto case 0;}
+			case 5:
+				{t.kind = 3; break;}
+			case 6:
+				{t.kind = 19; break;}
+			case 7:
+				{t.kind = 20; break;}
+			case 8:
+				{t.kind = 22; break;}
+			case 9:
+				recEnd = pos; recKind = 13;
+				if (ch == '.') {AddCh(); goto case 6;}
+				else {t.kind = 13; break;}
+
+		}
+		t.val = new String(tval, 0, tlen);
+		return t;
+	}
+	
+	private void SetScannerBehindT() {
+		buffer.Pos = t.pos;
+		NextCh();
+		line = t.line; col = t.col; charPos = t.charPos;
+		for (int i = 0; i < tlen; i++) NextCh();
+	}
+	
+	// get the next token (possibly a token already seen during peeking)
+	public Token Scan () {
+		if (tokens.next == null) {
+			return NextToken();
+		} else {
+			pt = tokens = tokens.next;
+			return tokens;
+		}
+	}
+
+	// peek for the next token, ignore pragmas
+	public Token Peek () {
+		do {
+			if (pt.next == null) {
+				pt.next = NextToken();
+			}
+			pt = pt.next;
+		} while (pt.kind > maxT); // skip pragmas
+	
+		return pt;
+	}
+
+	// make sure that peeking starts at the current scan position
+	public void ResetPeek () { pt = tokens; }
+
+} // end Scanner
+}
Index: /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/Util.cs
===================================================================
--- /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/Util.cs	(revision 10056)
+++ /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/Util.cs	(revision 10056)
@@ -0,0 +1,36 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System.Collections.Generic;
+using System.Linq;
+using System.Text.RegularExpressions;
+
+public class Util {
+  private static Regex formalParameterExpr = new Regex(@"\s*,?\s*((?<refOrOut>(out|ref))\s+)?(?<type>[_\w]*)\s+(?<id>[_\w]*)\s*");
+  public static IEnumerable<TerminalNode.FieldDefinition> ExtractFormalParameters(string formalParameterSrc) {
+    var match = formalParameterExpr.Match(formalParameterSrc);
+    var matches = formalParameterExpr.Matches(formalParameterSrc);
+
+    foreach (var m in matches.OfType<Match>()) {
+      yield return new TerminalNode.FieldDefinition(m.Groups["refOrOut"].Value, m.Groups["type"].Value, m.Groups["id"].Value);
+    }
+  }
+}
