Index: branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/GPDef.atg
===================================================================
--- branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/GPDef.atg	(revision 9430)
+++ branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/GPDef.atg	(revision 9724)
@@ -1,78 +1,35 @@
+$namespace=HeuristicLab.Problems.GPDL
+
+using System.Text;
+using System.Collections.Generic;
+using IEnumerableConstraintNode = System.Collections.Generic.IEnumerable<ConstraintNode>;
+
 COMPILER GPDef
-SEM <<
   static StringBuilder srcText;
   public static HeuristicLab.Optimization.IProblem problem;
->>
-
-
-CHARACTER SETS
+  static string lastSrc;
+  
+CHARACTERS
   letter = 'A'..'Z' + 'a'..'z'.
   digit = '0'..'9'.
-  whiteSpace = CHR(9) + EOL IGNORE. /* ' ' ignored by default */
+
+TOKENS
+  ident = letter {letter | digit}  .
 
 COMMENTS
-  FROM '/*' TO '*/' NESTED.
-
-KEYWORDS
-  'PROBLEM'. 'END'. 'EPS'.
-  'LOCAL'. 'NONTERMINALS'. 'RULES'.
-  'SEM'. 'MAXIMIZE'. 'MINIMIZE'. 'TERMINALS'. 'CONSTRAINTS'. 'INIT'. 'MUTATE'. 'CODE'.
-  'IN'. 'SET'. 'RANGE'.
-
-TOKENS
-  '='. '|'. '.'. '('. ')'. '['. ']'. '{'. '}'. '..'.
-
-TOKEN CLASSES
-  ident<<out string identStr>> =
-    letter {letter | digit}        LEX << identStr = tokenStr; >>
-  .
-
-PRAGMAS
-  source       = '<<' SEM << GPDefSem.srcText = new StringBuilder();
-                             for (; ; ) {
-                              switch (GPDefLex.curCh) {
-                                case Utils.EF:
-                                  Errors.SemError(GPDefLex.curLine, GPDefLex.curCol, "end of file in source text");
-                                  return;
-                                case '<':
-                                  GPDefLex.NextCh();
-                                  if (GPDefLex.curCh == '<') {
-                                    GPDefSem.srcText.Append('<');
-                                    Errors.Warning(GPDefLex.curLine, GPDefLex.curCol, "non closed source text before?");
-                                    GPDefLex.NextCh();
-                                  }
-                                  GPDefSem.srcText.Append('<');
-                                  break;
-                                case '>':
-                                  GPDefLex.NextCh();
-                                  if (GPDefLex.curCh == '>') {
-                                    GPDefLex.curCh = ' ';          // force GPDefLex to get next character
-                                    SourceReader.Handle(GPDefSem.srcText.ToString());
-                                    return;
-                                  }
-                                  GPDefSem.srcText.Append('>');
-                                  break;
-                                default:
-                                  GPDefSem.srcText.Append(GPDefLex.curCh);
-                                  GPDefLex.NextCh();
-                                  break;
-                              }
-                            }
-                            >> .
-NONTERMINALS
-  GPDef.
-  NonterminalDecl<<out NonTerminalNode ntNode>>.
-  TerminalDecl<<out TerminalNode tNode>>.
-  RuleDef<<out RuleNode rNode>>.
-  SynExpr<<out RuleExprNode expr>>.
-  SynTerm<<out RuleExprNode expr>>.
-  SynFact<<out RuleExprNode expr>>.
-  SemAction<<out RuleActionNode action>>.
-  ConstraintDef<<out IEnumerable<ConstraintNode> constraints>>.
-  ConstraintRule<<out ConstraintNode constraint>>.
-  SetDefinition<<ConstraintNode constraint>>.
-
-RULES
-  GPDef =                                                                         LOCAL <<
+  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 =                                                                         (.
                                                                                     string identStr = "";
                                                                                     RuleNode ruleNode = null;
@@ -82,70 +39,72 @@
                                                                                     TerminalNode tNode = null;
                                                                                     problem = null;
-                                                                                  >>
-    'PROBLEM' ident<<out identStr>>                                               SEM << gpDef.Name = identStr; >>
-    ['CODE' /* SourceText */                                                      SEM << SourceReader.WithNext((src) => gpDef.ClassCodeNode = new CodeNode{SrcCode = src});  >>
+                                                                                    string src = "";
+                                                                                  .)
+    "PROBLEM" ident                                                               (. gpDef.Name = t.val; .)
+    ["CODE" SourceCode<out src>                                                   (. gpDef.ClassCodeNode = new CodeNode{SrcCode = src}; .)
     ]
-    ['INIT' /* SourceText */                                                      SEM << SourceReader.WithNext((src) => gpDef.InitCodeNode = new CodeNode{SrcCode = src});  >>
+    ["INIT" SourceCode<out src>                                                   (. gpDef.InitCodeNode = new CodeNode{SrcCode = src}; .)
     ]
 
-    'NONTERMINALS' { NonterminalDecl<<out ntNode>>                                SEM << gpDef.NonTerminals.Add(ntNode); >>
-    }
-    'TERMINALS' { TerminalDecl<<out tNode>>                                       SEM << gpDef.Terminals.Add(tNode); >>
-    }
-    'RULES' { RuleDef<<out ruleNode>>                                                SEM << gpDef.Rules.Add(ruleNode); >>
-    }
-                                                                                  SEM << fitnessFunNode = new FitnessFunctionNode();
+    "NONTERMINALS" { NonterminalDecl<out ntNode>                                  (. gpDef.NonTerminals.Add(ntNode); .)
+    }
+    "TERMINALS" { TerminalDecl<out tNode>                                         (. gpDef.Terminals.Add(tNode); .)
+    }
+    "RULES" { RuleDef<out ruleNode>                                               (. gpDef.Rules.Add(ruleNode); .)
+    }
+                                                                                  (. fitnessFunNode = new FitnessFunctionNode();
                                                                                          gpDef.FitnessFunctionNode = fitnessFunNode;
-                                                                                  >>
-    ('MAXIMIZE'                                                                   SEM << fitnessFunNode.Maximization = true; >>
-    | 'MINIMIZE'                                                                  SEM << fitnessFunNode.Maximization = false; >>
+                                                                                  .)
+    ("MAXIMIZE"                                                                   (. fitnessFunNode.Maximization = true; .)
+    | "MINIMIZE"                                                                  (. fitnessFunNode.Maximization = false; .)
     )
-     /* SourceText */                                                             SEM << SourceReader.WithNext((src) => fitnessFunNode.SrcCode = src);  >>
-    'END' ident<<out identStr>> '.'                                               SEM <<
-                                                                                    SourceReader.Handle(GPDefSem.srcText.ToString()); // flush the source reader
+     SourceCode<out src>                                                          (. fitnessFunNode.SrcCode = src; .)
+    "END" ident                                                                   (.
+                                                                                    // SourceReader.Handle(GPDefSem.srcText.ToString()); // flush the source reader
                                                                                     var gen = new ProblemGenerator();
                                                                                     problem = gen.GenerateFromAst(gpDef);
-                                                                                  >>
-  .
-
-
-  /******************************************************/
-  SemAction<<out RuleActionNode action>> =                                        LOCAL << RuleActionNode myAction = null; action = null; >>
-    'SEM' /* SourceText */                                                        SEM <<
+                                                                                  .)
+    '.'
+  .
+
+
+  /******************************************************/
+  SemAction<out RuleActionNode action> =                                          (. RuleActionNode myAction = null; action = null; string src = ""; .)
+    "SEM" SourceCode<out src>                                                     (.
                                                                                     myAction = new RuleActionNode();
-                                                                                    SourceReader.WithNext((src) => {myAction.SrcCode = src;});
+                                                                                    myAction.SrcCode = src;
                                                                                     action = myAction;
-                                                                                  >>
-  .
-
-  /******************************************************/
-  NonterminalDecl<<out NonTerminalNode ntNode>> =                                 LOCAL << string identStr = ""; ntNode = null;>>
-    ident<<out identStr>> /* FormalAttrList */                                    SEM <<
+                                                                                  .)
+  .
+
+  /******************************************************/
+  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;
-                                                                                    SourceReader.WithNext((src) => {myNtNode.FormalParameters = src;});
-                                                                                  >>
+                                                                                    myNtNode.FormalParameters = src;
+                                                                                  .)
     '.'
   .
 
   /******************************************************/
-  TerminalDecl<<out TerminalNode tNode>> =                                        LOCAL <<
+  TerminalDecl<out TerminalNode tNode> =                                          (.
                                                                                     string identStr = "";
                                                                                     tNode = null;
                                                                                     TerminalNode myTNode = null;
-                                                                                    IEnumerable<ConstraintNode> constraints = null;
-                                                                                  >>
-  ident<<out identStr>> /* FormalAttrList */                                      SEM <<
+                                                                                    IEnumerableConstraintNode constraints = null;
+                                                                                    string src = "";
+                                                                                  .)
+  ident                                                                           (. identStr = t.val; .) 
+  SourceCode<out src>                                                             (.
                                                                                          myTNode = new TerminalNode();
                                                                                          tNode = myTNode;
                                                                                          myTNode.Ident = identStr;
-                                                                                         SourceReader.WithNext((src) => {
-                                                                                           myTNode.FormalParameters = src;
-                                                                                           myTNode.FieldDefinitions = SourceReader.ExtractFormalParameters(src);
-                                                                                         });
-
-                                                                                  >>
-  [ 'CONSTRAINTS' ConstraintDef<<out constraints>>                                SEM << myTNode.Constraints = constraints; >>
+                                                                                         myTNode.FormalParameters = src;
+                                                                                         myTNode.FieldDefinitions = SourceReader.ExtractFormalParameters(src);
+                                                                                  .)
+  [ "CONSTRAINTS" ConstraintDef<out constraints>                                  (. myTNode.Constraints = constraints; .)
   ]
   '.'
@@ -154,96 +113,102 @@
 
   /******************************************************/
-  ConstraintDef<<out IEnumerable<ConstraintNode> constraints>>  =             LOCAL <<
+  ConstraintDef<out IEnumerableConstraintNode constraints>  =                   (.
                                                                                     List<ConstraintNode> constraintsList = new List<ConstraintNode>();
                                                                                     ConstraintNode n = null;
                                                                                     constraints = null;
-                                                                                  >>
-    { ConstraintRule<<out n>>                                                     SEM << constraintsList.Add(n); >>
-    }
-                                                                                  SEM << constraints = constraintsList; >>
-  .
-
-  /******************************************************/
-  ConstraintRule<<out ConstraintNode constraint>> =                               LOCAL <<
+                                                                                  .)
+    { ConstraintRule<out n>                                                       (. constraintsList.Add(n); .)
+    }
+                                                                                  (. constraints = constraintsList; .)
+  .
+
+  /******************************************************/
+  ConstraintRule<out ConstraintNode constraint> =                                 (.
                                                                                     string identStr = null;
                                                                                     constraint = null;
-                                                                                  >>
-    ident<<out identStr>>                                                         SEM << constraint = new ConstraintNode(identStr); >>
-    'IN' SetDefinition<<constraint>>                                              SEM << SourceReader.Handle(GPDefSem.srcText.ToString()); // flush the source reader  >>
-  .
-
-  /******************************************************/
-  SetDefinition<<ConstraintNode constraint>> =
-    'SET'                                                                        SEM << constraint.Type = ConstraintNodeType.Set; >>
-    /* SourceText */                                                              SEM << SourceReader.WithNext((src) => {constraint.SetExpression = src;}); >>
-    | 
-    'RANGE'                                                                       SEM << constraint.Type = ConstraintNodeType.Range; >>
-    /* SourceText */                                                              SEM << SourceReader.WithNext((src) => {constraint.RangeMinExpression = src;}); >>
-    '..' /* SourceText */                                                         SEM << SourceReader.Handle(GPDefSem.srcText.ToString()); // flush the source reader 
-                                                                                         SourceReader.WithNext((src) => {constraint.RangeMaxExpression = src;}); >>    
-  .
-
-  /******************************************************/
-  RuleDef<<out RuleNode rule>> =                                                  LOCAL <<
+                                                                                  .)
+    ident                                                                         (. constraint = new ConstraintNode(t.val); .)
+    "IN" SetDefinition<constraint>                                                // (. SourceReader.Handle(GPDefSem.srcText.ToString()); .) // flush the source reader 
+  .
+
+  /******************************************************/
+  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>                                                     (. // SourceReader.Handle(GPDefSem.srcText.ToString()); // flush the source reader 
+                                                                                    constraint.RangeMaxExpression = src; .)
+    )
+  .
+
+  /******************************************************/
+  RuleDef<out RuleNode rule> =                                                    (.
                                                                                     RuleExprNode expr = null;
                                                                                     string identStr = null;
                                                                                     RuleNode myRule = null;
                                                                                     rule = null;
-                                                                                  >>
-  ident<<out identStr>> /* FormalAttrList */ '='                                  SEM <<
+                                                                                   string src = "";
+                                                                                  .)
+  ident                                                                           (. identStr = t.val; .) 
+  SourceCode<out src> '='                                                         (.
                                                                                       myRule = new RuleNode();
                                                                                       rule = myRule;
                                                                                       myRule.NtSymbol = identStr;
-                                                                                  >>
-  ['LOCAL' /* SourceText */                                                       SEM <<
-                                                                                    SourceReader.WithNext((src) => {myRule.LocalCode = src;});
-                                                                                  >>
+                                                                                  .)
+  ["LOCAL" SourceCode<out src>                                                    (.
+                                                                                    myRule.LocalCode = src;
+                                                                                  .)
   ]
-  SynExpr<<out expr>> '.'                                                        SEM <<
+  SynExpr<out expr> '.'                                                          (.
                                                                                     myRule.RuleExpr = expr;
-                                                                                 >>
-  .
-
-  /******************************************************/
-  SynExpr<<out RuleExprNode expr >> =                                             LOCAL <<
+                                                                                 .)
+  .
+
+  /******************************************************/
+  SynExpr<out RuleExprNode expr > =                                               (.
                                                                                     expr = null;
                                                                                     AlternativesNode alt = null;
-                                                                                  >>
-  SynTerm<<out expr>>                                                             SEM <<
+                                                                                  .)
+  SynTerm<out expr>                                                               (.
                                                                                     alt = new AlternativesNode();
                                                                                     alt.Add(expr);
-                                                                                   >>
+                                                                                  .)
   {
-    '|' SynTerm<<out expr>>                                                       SEM << alt.Add(expr); expr = alt; >>
+    '|' SynTerm<out expr>                                                         (. alt.Add(expr); expr = alt; .)
   }
   .
 
   /******************************************************/
-  SynTerm<<out RuleExprNode expr>> =                                             LOCAL << SequenceNode seq = null; expr = null; >>
-  SynFact<<out expr>>                                                            SEM <<
+  SynTerm<out RuleExprNode expr> =                                               (. SequenceNode seq = null; expr = null; .)
+  SynFact<out expr>                                                              (.
                                                                                    seq = new SequenceNode();
                                                                                    seq.Add(expr);
-                                                                                 >>
+                                                                                 .)
   {
-    SynFact<<out expr>>                                                          SEM << seq.Add(expr); expr = seq; >>
+    SynFact<out expr>                                                            (. seq.Add(expr); expr = seq; .)
   }
   .
 
   /******************************************************/
-  SynFact<<out RuleExprNode expr>> =                                             LOCAL <<
+  SynFact<out RuleExprNode expr> =                                               (.
                                                                                    string identStr = "";
                                                                                    RuleActionNode action = null;
                                                                                    expr = null;
-                                                                                 >>
-    ident<<out identStr>> /* ActualAttrList */                                   SEM <<
+                                                                                   string src = "";
+                                                                                 .)
+    (ident                                                                        (. identStr = t.val; .)
+     SourceCode<out src>                                                          (.
                                                                                     var callNode = new CallSymbolNode{Ident = identStr};
-                                                                                    SourceReader.WithNext((src) => {callNode.ActualParameter = src;});
+                                                                                    callNode.ActualParameter = src;
                                                                                     expr = callNode;
-                                                                                  >>
---    | 'EPS'
---    | '(' SynExpr<<ref rules, mBuilder>> ')'
---    | '[' SynExpr<<ref rules, mBuilder>> ']'
---    | '{' SynExpr<<ref rules, mBuilder>> '}'
-    | SemAction<<out action>>                                                    SEM << expr = action; >>
+                                                                                 .)
+// 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; .)
+    )
   .
 
