Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/19/13 00:31:12 (11 years ago)
Author:
gkronber
Message:

#2026 changed ATG to Coco/R syntax and use Coco/R (C#) to generate scanner and parser for GPDL

Location:
branches/HeuristicLab.Problems.GPDL
Files:
8 added
10 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GPDL/GenerateFromAtg.cmd

    r9518 r9724  
    1 cd %SolutionDir%\Coco-2
    2 SG  %ProjectDir%\GPDef.atg
    3 PGT %ProjectDir%\GPDef.atg
     1cd %SolutionDir%\CocoR
     2Coco -frames . %ProjectDir%\GPDef.atg
    43
    5 cd %ProjectDir%
    6 move %SolutionDir%\Coco-2\*.cs .
  • branches/HeuristicLab.Problems.GPDL/GpdlCompiler/Program.cs

    r9528 r9724  
    1 // ATTENTION: Replace all occurences of GpdlCompiler by the compiler name!
    2 
    3 // GpdlCompiler.cs                                                        HDO, 2006-08-28
     1// GpdlCompiler.cs                                                        HDO, 2006-08-28
    42// -----
    53// Main program for compiler generated from GpdlCompiler.atg with Coco-2.
     
    75
    86using System;
    9 using System.IO;
    10 
    11 using Lex = GPDefLex;
    12 using Syn = GPDefSyn;
     7using HeuristicLab.Problems.GPDL;
    138
    149public class GpdlCompiler {
    1510
    16   private static String NAME = "GpdlCompiler";
    17   private static bool interactiveMode;
    18 
    19   private static void Abort(String abortKind, String moduleName,
    20                             String methName, String descr) {
    21     Console.WriteLine();
    22     Console.WriteLine("*** {0} in class {1} method {2}",
    23                       abortKind, moduleName, methName);
    24     Console.WriteLine("*** {0}", descr);
    25     Console.WriteLine();
    26     Console.WriteLine();
    27     Console.WriteLine(NAME + " aborted");
    28     Utils.Modules(Utils.ModuleAction.cleanupModule);
    29     if (interactiveMode) {
    30       Console.Write("type [CR] to quit");
    31       string dummy = Console.ReadLine();
    32     } // if
    33     Environment.Exit(Utils.EXIT_FAILURE);
    34   } // Abort
    35 
    36   private static int CompileFile(String srcFileName) {
    37     FileStream srcFs = null;
    38     try {
    39       srcFs = new FileStream(srcFileName, FileMode.Open);
    40     }
    41     catch (Exception) {
    42       Console.WriteLine("*** file \"{0}\" not found", srcFileName);
    43       return Utils.EXIT_FAILURE;
    44     } // try/catch
    45     try {
    46       Lex.src = new StreamReader(srcFs);
    47       Console.WriteLine("parsing ...");
    48       Syn.Parse();
    49       Lex.src.Close();
    50       Lex.src.Dispose();
    51       Lex.src = null;
    52       if (Errors.NumOfErrors() > 0) {
    53         Console.WriteLine("listing ...");
    54         String lstFileName = Path.ChangeExtension(srcFileName, ".lst");
    55         FileStream lstFs = null;
    56         try {
    57           lstFs = new FileStream(lstFileName, FileMode.Create);
    58         }
    59         catch (Exception) {
    60           Utils.FatalError(NAME, "CompileFile", "file \"{0}\" not created", lstFileName);
    61           return Utils.EXIT_FAILURE;
    62         } // try/catch
    63         StreamWriter lstWriter = null;
    64         try {
    65           lstWriter = new StreamWriter(lstFs);
    66           StreamReader srcFsReader = null;
    67           try { // open the source file a second time to generate the error listing
    68             srcFsReader = new StreamReader(new FileStream(srcFileName, FileMode.Open));
    69             lstWriter.WriteLine(NAME + " (file: \"{0}\")", srcFileName);
    70             Errors.GenerateListing(srcFsReader, lstWriter, Errors.ListingShape.longListing);
    71           }
    72           finally {
    73             srcFsReader.Close();
    74             srcFsReader.Dispose();
    75           } // try/finally
    76           Console.WriteLine("{0} error(s) detected", Errors.NumOfErrors());
    77         }
    78         finally {
    79           lstWriter.Close();
    80           lstWriter.Dispose();
    81         } // try/finally
    82       } else
    83         Console.WriteLine("no errors detected");
    84     }
    85     finally {
    86       if (Lex.src != null) {
    87         Lex.src.Close();
    88         Lex.src.Dispose();
    89         Lex.src = null;
    90       } // if
    91       Utils.Modules(Utils.ModuleAction.resetModule);
    92     } // try/finally to make sure srcFs and srcReader are closed
    93     return Utils.EXIT_SUCCESS;
    94   } // CompileFile
    95 
    96 
    9711  public static void Main(String[] args) {
    9812    //-----------------------------------|----------------------------------------
    99     int result = 0;
     13    if (args.Length > 0) {
     14      Scanner scanner = new Scanner(args[0]);
     15      Parser parser = new Parser(scanner);
     16      parser.Parse();
     17    } else
     18      Console.WriteLine("-- No source file specified");
     19  }
    10020
    101     // --- install modules ---
    102     Utils.InstallModule("Utils", new Utils.ModuleMethodDelegate(Utils.UtilsMethod));
    103     Utils.InstallModule("Sets", new Utils.ModuleMethodDelegate(Sets.SetsMethod));
    104     Utils.InstallModule("Errors", new Utils.ModuleMethodDelegate(Errors.ErrorsMethod));
    105 
    106     Utils.InstallModule("GPDefLex", new Utils.ModuleMethodDelegate(GPDefLex.GPDefLexMethod));
    107     Utils.InstallModule("GPDefSem", new Utils.ModuleMethodDelegate(GPDefSem.GPDefSemMethod));
    108     Utils.InstallModule("GPDefSyn", new Utils.ModuleMethodDelegate(GPDefSyn.GPDefSynMethod));
    109 
    110     // --- initialize modules ---
    111     Utils.Modules(Utils.ModuleAction.initModule);
    112 
    113     Errors.PushAbortMethod(new Errors.AbortMethod(Abort));
    114 
    115     Console.WriteLine("---------------------------");
    116     Console.WriteLine(" {0} Compiler {1," + (5 - NAME.Length) + "} Version X  ", NAME, "");
    117     Console.WriteLine(" Frontend gen. with Coco-2");
    118     Console.WriteLine("---------------------------");
    119     Console.WriteLine();
    120 
    121     if (args.Length > 0) { // command line mode
    122       interactiveMode = false;
    123       Console.WriteLine();
    124       int i = 0;
    125       do {
    126         Console.WriteLine("source file \"{0}\"", args[i]);
    127         result = CompileFile(args[i]);
    128         if (result != Utils.EXIT_SUCCESS)
    129           Environment.Exit(result);
    130         Console.WriteLine();
    131         i++;
    132       } while (i < args.Length);
    133     } else { // args.Length == 0, interactive mode
    134       interactiveMode = true;
    135       for (; ; ) {
    136         String srcFileName;
    137         Utils.GetInputFileName("source file > ", out srcFileName);
    138         if (srcFileName.Length > 0) {
    139           result = CompileFile(srcFileName);
    140           if (result != Utils.EXIT_SUCCESS)
    141             Environment.Exit(result);
    142         } // if
    143         char answerCh;
    144         do {
    145           Console.WriteLine();
    146           Console.Write("[c]ontinue or [q]uit > ");
    147           answerCh = Char.ToUpper(Console.ReadKey().KeyChar);
    148         } while (answerCh != 'C' && answerCh != 'Q');
    149         if (answerCh == 'Q')
    150           break;
    151         else // answerCh == 'C'
    152           Console.WriteLine();
    153       } // for
    154     } // else
    155 
    156     Utils.Modules(Utils.ModuleAction.cleanupModule);
    157     Environment.Exit(Utils.EXIT_SUCCESS);
    158 
    159   } // Main
    160 
    161 } // GpdlCompiler
    162 
    163 // End of GpdlCompiler.cs
    164 //=====================================|========================================
     21}
  • branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL.Views/3.4/CodeEditor.xaml.cs

    r9674 r9724  
    5757    }
    5858
    59     private void textEditor_MouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e) {
     59    private void textEditor_MouseWheel(object sender, MouseWheelEventArgs e) {
    6060    }
    6161
    62     private void textEditor_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) {
     62    private void textEditor_KeyDown(object sender, KeyEventArgs e) {
    6363      if (e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl) controlHeld = true;
    6464    }
     
    7070    internal void SetLexError(string msg, int line, int col) {
    7171      errorLineTransformer.MarkLexError(msg, line, col);
    72       textEditor.InvalidateVisual();
     72      textEditor.TextArea.TextView.Redraw();
    7373    }
    7474
    7575    internal void SetSynError(string msg, int line, int col) {
    7676      errorLineTransformer.MarkSynError(msg, line, col);
    77       textEditor.InvalidateVisual();
     77      textEditor.TextArea.TextView.Redraw();
    7878    }
    7979
    8080    internal void ClearErrors() {
    8181      errorLineTransformer.ClearErrors();
    82       textEditor.InvalidateVisual();
     82      textEditor.TextArea.TextView.Redraw();
    8383    }
    8484
  • branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL.Views/3.4/GpdlEditor.cs

    r9674 r9724  
    22using System.IO;
    33using System.Linq;
     4using System.Text;
    45using HeuristicLab.MainForm.WindowsForms;
    56using HeuristicLab.Problems.Instances;
     
    1920
    2021    private void compileButton_Click(object sender, EventArgs e) {
    21       Utils.InstallModule("Utils", Utils.UtilsMethod);
    22       Utils.InstallModule("Sets", Sets.SetsMethod);
    23       Utils.InstallModule("Errors", Errors.ErrorsMethod);
     22      //Utils.InstallModule("Utils", Utils.UtilsMethod);
     23      //Utils.InstallModule("Sets", Sets.SetsMethod);
     24      //Utils.InstallModule("Errors", Errors.ErrorsMethod);
    2425
    25       Utils.InstallModule("GPDefLex", GPDefLex.GPDefLexMethod);
    26       Utils.InstallModule("GPDefSem", GPDefSem.GPDefSemMethod);
    27       Utils.InstallModule("GPDefSyn", GPDefSyn.GPDefSynMethod);
     26      //Utils.InstallModule("GPDefLex", GPDefLex.GPDefLexMethod);
     27      //Utils.InstallModule("GPDefSem", GPDefSem.GPDefSemMethod);
     28      //Utils.InstallModule("GPDefSyn", GPDefSyn.GPDefSynMethod);
    2829
    29       // --- initialize modules ---
    30       Utils.Modules(Utils.ModuleAction.initModule);
     30      //// --- initialize modules ---
     31      //Utils.Modules(Utils.ModuleAction.initModule);
    3132
    32       Errors.PushAbortMethod(new Errors.AbortMethod(Abort));
     33      //Errors.PushAbortMethod(new Errors.AbortMethod(Abort));
    3334
    34       using (var src = new StringReader(codeEditor.textEditor.Text)) {
    35         GPDefLex.src = src;
    36         GPDefSyn.Parse();
     35      using (var src = new MemoryStream(Encoding.UTF8.GetBytes(codeEditor.textEditor.Text))) {
     36        Scanner scanner = new Scanner(src);
     37        Parser parser = new Parser(scanner);
     38        parser.Parse();
    3739      }
    3840
    3941      codeEditor.ClearErrors();
    4042
    41       if (Errors.NumOfErrors() == 0) {
    42         GPDefLex.InitLex();
    43         GPDefSyn.Interpret();
     43      //if (Errors.NumOfErrors() == 0) {
     44      //  GPDefLex.InitLex();
     45      //  GPDefSyn.Interpret();
    4446
    45         MainForm.MainFormManager.MainForm.ShowContent(GPDefSem.problem);
    46       } else {
    47         int nLexErrors = Errors.NumOfLexErrors();
    48         for (int i = 0; i < nLexErrors; i++) {
    49           var lexErr = Errors.GetLexError(i == 0);
    50           codeEditor.SetLexError(lexErr.msg, lexErr.line, lexErr.col);
    51         }
    52         int nSynErrors = Errors.NumOfSynErrors();
    53         for (int i = 0; i < nSynErrors; i++) {
    54           var synErr = Errors.GetSynError(i == 0);
    55           codeEditor.SetLexError(synErr.msg, synErr.line, synErr.col);
    56         }
    57       }
     47      //  MainForm.MainFormManager.MainForm.ShowContent(GPDefSem.problem);
     48      //} else {
     49      //  int nLexErrors = Errors.NumOfLexErrors();
     50      //  for (int i = 0; i < nLexErrors; i++) {
     51      //    var lexErr = Errors.GetLexError(i == 0);
     52      //    codeEditor.SetLexError(lexErr.msg, lexErr.line, lexErr.col);
     53      //  }
     54      //  int nSynErrors = Errors.NumOfSynErrors();
     55      //  for (int i = 0; i < nSynErrors; i++) {
     56      //    var synErr = Errors.GetSynError(i == 0);
     57      //    codeEditor.SetLexError(synErr.msg, synErr.line, synErr.col);
     58      //  }
     59      //}
    5860    }
    5961
  • branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/GPDef.atg

    r9430 r9724  
     1$namespace=HeuristicLab.Problems.GPDL
     2
     3using System.Text;
     4using System.Collections.Generic;
     5using IEnumerableConstraintNode = System.Collections.Generic.IEnumerable<ConstraintNode>;
     6
    17COMPILER GPDef
    2 SEM <<
    38  static StringBuilder srcText;
    49  public static HeuristicLab.Optimization.IProblem problem;
    5 >>
    6 
    7 
    8 CHARACTER SETS
     10  static string lastSrc;
     11 
     12CHARACTERS
    913  letter = 'A'..'Z' + 'a'..'z'.
    1014  digit = '0'..'9'.
    11   whiteSpace = CHR(9) + EOL IGNORE. /* ' ' ignored by default */
     15
     16TOKENS
     17  ident = letter {letter | digit}  .
    1218
    1319COMMENTS
    14   FROM '/*' TO '*/' NESTED.
    15 
    16 KEYWORDS
    17   'PROBLEM'. 'END'. 'EPS'.
    18   'LOCAL'. 'NONTERMINALS'. 'RULES'.
    19   'SEM'. 'MAXIMIZE'. 'MINIMIZE'. 'TERMINALS'. 'CONSTRAINTS'. 'INIT'. 'MUTATE'. 'CODE'.
    20   'IN'. 'SET'. 'RANGE'.
    21 
    22 TOKENS
    23   '='. '|'. '.'. '('. ')'. '['. ']'. '{'. '}'. '..'.
    24 
    25 TOKEN CLASSES
    26   ident<<out string identStr>> =
    27     letter {letter | digit}        LEX << identStr = tokenStr; >>
    28   .
    29 
    30 PRAGMAS
    31   source       = '<<' SEM << GPDefSem.srcText = new StringBuilder();
    32                              for (; ; ) {
    33                               switch (GPDefLex.curCh) {
    34                                 case Utils.EF:
    35                                   Errors.SemError(GPDefLex.curLine, GPDefLex.curCol, "end of file in source text");
    36                                   return;
    37                                 case '<':
    38                                   GPDefLex.NextCh();
    39                                   if (GPDefLex.curCh == '<') {
    40                                     GPDefSem.srcText.Append('<');
    41                                     Errors.Warning(GPDefLex.curLine, GPDefLex.curCol, "non closed source text before?");
    42                                     GPDefLex.NextCh();
    43                                   }
    44                                   GPDefSem.srcText.Append('<');
    45                                   break;
    46                                 case '>':
    47                                   GPDefLex.NextCh();
    48                                   if (GPDefLex.curCh == '>') {
    49                                     GPDefLex.curCh = ' ';          // force GPDefLex to get next character
    50                                     SourceReader.Handle(GPDefSem.srcText.ToString());
    51                                     return;
    52                                   }
    53                                   GPDefSem.srcText.Append('>');
    54                                   break;
    55                                 default:
    56                                   GPDefSem.srcText.Append(GPDefLex.curCh);
    57                                   GPDefLex.NextCh();
    58                                   break;
    59                               }
    60                             }
    61                             >> .
    62 NONTERMINALS
    63   GPDef.
    64   NonterminalDecl<<out NonTerminalNode ntNode>>.
    65   TerminalDecl<<out TerminalNode tNode>>.
    66   RuleDef<<out RuleNode rNode>>.
    67   SynExpr<<out RuleExprNode expr>>.
    68   SynTerm<<out RuleExprNode expr>>.
    69   SynFact<<out RuleExprNode expr>>.
    70   SemAction<<out RuleActionNode action>>.
    71   ConstraintDef<<out IEnumerable<ConstraintNode> constraints>>.
    72   ConstraintRule<<out ConstraintNode constraint>>.
    73   SetDefinition<<ConstraintNode constraint>>.
    74 
    75 RULES
    76   GPDef =                                                                         LOCAL <<
     20  FROM "/*" TO "*/" NESTED
     21
     22IGNORE '\t' + '\r' + '\n'
     23
     24
     25PRODUCTIONS
     26
     27  SourceCode<out string src> =                                                    (. src = ""; .)
     28   "<<"                                                                           (. int beg = la.pos; .)
     29   {ANY}                                                                          (. int end = la.pos; .)
     30   ">>"                                                                           (. if(end>beg) src = scanner.buffer.GetString(beg, end); .)
     31  .
     32
     33  GPDef =                                                                         (.
    7734                                                                                    string identStr = "";
    7835                                                                                    RuleNode ruleNode = null;
     
    8239                                                                                    TerminalNode tNode = null;
    8340                                                                                    problem = null;
    84                                                                                   >>
    85     'PROBLEM' ident<<out identStr>>                                               SEM << gpDef.Name = identStr; >>
    86     ['CODE' /* SourceText */                                                      SEM << SourceReader.WithNext((src) => gpDef.ClassCodeNode = new CodeNode{SrcCode = src});  >>
     41                                                                                    string src = "";
     42                                                                                  .)
     43    "PROBLEM" ident                                                               (. gpDef.Name = t.val; .)
     44    ["CODE" SourceCode<out src>                                                   (. gpDef.ClassCodeNode = new CodeNode{SrcCode = src}; .)
    8745    ]
    88     ['INIT' /* SourceText */                                                      SEM << SourceReader.WithNext((src) => gpDef.InitCodeNode = new CodeNode{SrcCode = src});  >>
     46    ["INIT" SourceCode<out src>                                                   (. gpDef.InitCodeNode = new CodeNode{SrcCode = src}; .)
    8947    ]
    9048
    91     'NONTERMINALS' { NonterminalDecl<<out ntNode>>                                SEM << gpDef.NonTerminals.Add(ntNode); >>
    92     }
    93     'TERMINALS' { TerminalDecl<<out tNode>>                                       SEM << gpDef.Terminals.Add(tNode); >>
    94     }
    95     'RULES' { RuleDef<<out ruleNode>>                                                SEM << gpDef.Rules.Add(ruleNode); >>
    96     }
    97                                                                                   SEM << fitnessFunNode = new FitnessFunctionNode();
     49    "NONTERMINALS" { NonterminalDecl<out ntNode>                                  (. gpDef.NonTerminals.Add(ntNode); .)
     50    }
     51    "TERMINALS" { TerminalDecl<out tNode>                                         (. gpDef.Terminals.Add(tNode); .)
     52    }
     53    "RULES" { RuleDef<out ruleNode>                                               (. gpDef.Rules.Add(ruleNode); .)
     54    }
     55                                                                                  (. fitnessFunNode = new FitnessFunctionNode();
    9856                                                                                         gpDef.FitnessFunctionNode = fitnessFunNode;
    99                                                                                   >>
    100     ('MAXIMIZE'                                                                   SEM << fitnessFunNode.Maximization = true; >>
    101     | 'MINIMIZE'                                                                  SEM << fitnessFunNode.Maximization = false; >>
     57                                                                                  .)
     58    ("MAXIMIZE"                                                                   (. fitnessFunNode.Maximization = true; .)
     59    | "MINIMIZE"                                                                  (. fitnessFunNode.Maximization = false; .)
    10260    )
    103      /* SourceText */                                                             SEM << SourceReader.WithNext((src) => fitnessFunNode.SrcCode = src);  >>
    104     'END' ident<<out identStr>> '.'                                               SEM <<
    105                                                                                     SourceReader.Handle(GPDefSem.srcText.ToString()); // flush the source reader
     61     SourceCode<out src>                                                          (. fitnessFunNode.SrcCode = src; .)
     62    "END" ident                                                                   (.
     63                                                                                    // SourceReader.Handle(GPDefSem.srcText.ToString()); // flush the source reader
    10664                                                                                    var gen = new ProblemGenerator();
    10765                                                                                    problem = gen.GenerateFromAst(gpDef);
    108                                                                                   >>
    109   .
    110 
    111 
    112   /******************************************************/
    113   SemAction<<out RuleActionNode action>> =                                        LOCAL << RuleActionNode myAction = null; action = null; >>
    114     'SEM' /* SourceText */                                                        SEM <<
     66                                                                                  .)
     67    '.'
     68  .
     69
     70
     71  /******************************************************/
     72  SemAction<out RuleActionNode action> =                                          (. RuleActionNode myAction = null; action = null; string src = ""; .)
     73    "SEM" SourceCode<out src>                                                     (.
    11574                                                                                    myAction = new RuleActionNode();
    116                                                                                     SourceReader.WithNext((src) => {myAction.SrcCode = src;});
     75                                                                                    myAction.SrcCode = src;
    11776                                                                                    action = myAction;
    118                                                                                   >>
    119   .
    120 
    121   /******************************************************/
    122   NonterminalDecl<<out NonTerminalNode ntNode>> =                                 LOCAL << string identStr = ""; ntNode = null;>>
    123     ident<<out identStr>> /* FormalAttrList */                                    SEM <<
     77                                                                                  .)
     78  .
     79
     80  /******************************************************/
     81  NonterminalDecl<out NonTerminalNode ntNode> =                                   (. string identStr = ""; ntNode = null; string src = ""; .)
     82    ident                                                                         (. identStr = t.val; .)
     83    SourceCode<out src>                                                           (.
    12484                                                                                    var myNtNode = new NonTerminalNode();
    12585                                                                                    ntNode = myNtNode;
    12686                                                                                    myNtNode.Ident = identStr;
    127                                                                                     SourceReader.WithNext((src) => {myNtNode.FormalParameters = src;});
    128                                                                                   >>
     87                                                                                    myNtNode.FormalParameters = src;
     88                                                                                  .)
    12989    '.'
    13090  .
    13191
    13292  /******************************************************/
    133   TerminalDecl<<out TerminalNode tNode>> =                                        LOCAL <<
     93  TerminalDecl<out TerminalNode tNode> =                                          (.
    13494                                                                                    string identStr = "";
    13595                                                                                    tNode = null;
    13696                                                                                    TerminalNode myTNode = null;
    137                                                                                     IEnumerable<ConstraintNode> constraints = null;
    138                                                                                   >>
    139   ident<<out identStr>> /* FormalAttrList */                                      SEM <<
     97                                                                                    IEnumerableConstraintNode constraints = null;
     98                                                                                    string src = "";
     99                                                                                  .)
     100  ident                                                                           (. identStr = t.val; .)
     101  SourceCode<out src>                                                             (.
    140102                                                                                         myTNode = new TerminalNode();
    141103                                                                                         tNode = myTNode;
    142104                                                                                         myTNode.Ident = identStr;
    143                                                                                          SourceReader.WithNext((src) => {
    144                                                                                            myTNode.FormalParameters = src;
    145                                                                                            myTNode.FieldDefinitions = SourceReader.ExtractFormalParameters(src);
    146                                                                                          });
    147 
    148                                                                                   >>
    149   [ 'CONSTRAINTS' ConstraintDef<<out constraints>>                                SEM << myTNode.Constraints = constraints; >>
     105                                                                                         myTNode.FormalParameters = src;
     106                                                                                         myTNode.FieldDefinitions = SourceReader.ExtractFormalParameters(src);
     107                                                                                  .)
     108  [ "CONSTRAINTS" ConstraintDef<out constraints>                                  (. myTNode.Constraints = constraints; .)
    150109  ]
    151110  '.'
     
    154113
    155114  /******************************************************/
    156   ConstraintDef<<out IEnumerable<ConstraintNode> constraints>>  =             LOCAL <<
     115  ConstraintDef<out IEnumerableConstraintNode constraints>  =                   (.
    157116                                                                                    List<ConstraintNode> constraintsList = new List<ConstraintNode>();
    158117                                                                                    ConstraintNode n = null;
    159118                                                                                    constraints = null;
    160                                                                                   >>
    161     { ConstraintRule<<out n>>                                                     SEM << constraintsList.Add(n); >>
    162     }
    163                                                                                   SEM << constraints = constraintsList; >>
    164   .
    165 
    166   /******************************************************/
    167   ConstraintRule<<out ConstraintNode constraint>> =                               LOCAL <<
     119                                                                                  .)
     120    { ConstraintRule<out n>                                                       (. constraintsList.Add(n); .)
     121    }
     122                                                                                  (. constraints = constraintsList; .)
     123  .
     124
     125  /******************************************************/
     126  ConstraintRule<out ConstraintNode constraint> =                                 (.
    168127                                                                                    string identStr = null;
    169128                                                                                    constraint = null;
    170                                                                                   >>
    171     ident<<out identStr>>                                                         SEM << constraint = new ConstraintNode(identStr); >>
    172     'IN' SetDefinition<<constraint>>                                              SEM << SourceReader.Handle(GPDefSem.srcText.ToString()); // flush the source reader  >>
    173   .
    174 
    175   /******************************************************/
    176   SetDefinition<<ConstraintNode constraint>> =
    177     'SET'                                                                        SEM << constraint.Type = ConstraintNodeType.Set; >>
    178     /* SourceText */                                                              SEM << SourceReader.WithNext((src) => {constraint.SetExpression = src;}); >>
    179     |
    180     'RANGE'                                                                       SEM << constraint.Type = ConstraintNodeType.Range; >>
    181     /* SourceText */                                                              SEM << SourceReader.WithNext((src) => {constraint.RangeMinExpression = src;}); >>
    182     '..' /* SourceText */                                                         SEM << SourceReader.Handle(GPDefSem.srcText.ToString()); // flush the source reader
    183                                                                                          SourceReader.WithNext((src) => {constraint.RangeMaxExpression = src;}); >>   
    184   .
    185 
    186   /******************************************************/
    187   RuleDef<<out RuleNode rule>> =                                                  LOCAL <<
     129                                                                                  .)
     130    ident                                                                         (. constraint = new ConstraintNode(t.val); .)
     131    "IN" SetDefinition<constraint>                                                // (. SourceReader.Handle(GPDefSem.srcText.ToString()); .) // flush the source reader
     132  .
     133
     134  /******************************************************/
     135  SetDefinition<ConstraintNode constraint> =                                      (. string src = ""; .)
     136    ("SET"                                                                        (. constraint.Type = ConstraintNodeType.Set; .)
     137     SourceCode<out src>                                                          (. constraint.SetExpression = src; .)
     138     |
     139     "RANGE"                                                                      (. constraint.Type = ConstraintNodeType.Range; .)
     140     SourceCode<out src>                                                          (. constraint.RangeMinExpression = src; .)
     141     ".." SourceCode<out src>                                                     (. // SourceReader.Handle(GPDefSem.srcText.ToString()); // flush the source reader
     142                                                                                    constraint.RangeMaxExpression = src; .)
     143    )
     144  .
     145
     146  /******************************************************/
     147  RuleDef<out RuleNode rule> =                                                    (.
    188148                                                                                    RuleExprNode expr = null;
    189149                                                                                    string identStr = null;
    190150                                                                                    RuleNode myRule = null;
    191151                                                                                    rule = null;
    192                                                                                   >>
    193   ident<<out identStr>> /* FormalAttrList */ '='                                  SEM <<
     152                                                                                   string src = "";
     153                                                                                  .)
     154  ident                                                                           (. identStr = t.val; .)
     155  SourceCode<out src> '='                                                         (.
    194156                                                                                      myRule = new RuleNode();
    195157                                                                                      rule = myRule;
    196158                                                                                      myRule.NtSymbol = identStr;
    197                                                                                   >>
    198   ['LOCAL' /* SourceText */                                                       SEM <<
    199                                                                                     SourceReader.WithNext((src) => {myRule.LocalCode = src;});
    200                                                                                   >>
     159                                                                                  .)
     160  ["LOCAL" SourceCode<out src>                                                    (.
     161                                                                                    myRule.LocalCode = src;
     162                                                                                  .)
    201163  ]
    202   SynExpr<<out expr>> '.'                                                        SEM <<
     164  SynExpr<out expr> '.'                                                          (.
    203165                                                                                    myRule.RuleExpr = expr;
    204                                                                                  >>
    205   .
    206 
    207   /******************************************************/
    208   SynExpr<<out RuleExprNode expr >> =                                             LOCAL <<
     166                                                                                 .)
     167  .
     168
     169  /******************************************************/
     170  SynExpr<out RuleExprNode expr > =                                               (.
    209171                                                                                    expr = null;
    210172                                                                                    AlternativesNode alt = null;
    211                                                                                   >>
    212   SynTerm<<out expr>>                                                             SEM <<
     173                                                                                  .)
     174  SynTerm<out expr>                                                               (.
    213175                                                                                    alt = new AlternativesNode();
    214176                                                                                    alt.Add(expr);
    215                                                                                    >>
     177                                                                                  .)
    216178  {
    217     '|' SynTerm<<out expr>>                                                       SEM << alt.Add(expr); expr = alt; >>
     179    '|' SynTerm<out expr>                                                         (. alt.Add(expr); expr = alt; .)
    218180  }
    219181  .
    220182
    221183  /******************************************************/
    222   SynTerm<<out RuleExprNode expr>> =                                             LOCAL << SequenceNode seq = null; expr = null; >>
    223   SynFact<<out expr>>                                                            SEM <<
     184  SynTerm<out RuleExprNode expr> =                                               (. SequenceNode seq = null; expr = null; .)
     185  SynFact<out expr>                                                              (.
    224186                                                                                   seq = new SequenceNode();
    225187                                                                                   seq.Add(expr);
    226                                                                                  >>
     188                                                                                 .)
    227189  {
    228     SynFact<<out expr>>                                                          SEM << seq.Add(expr); expr = seq; >>
     190    SynFact<out expr>                                                            (. seq.Add(expr); expr = seq; .)
    229191  }
    230192  .
    231193
    232194  /******************************************************/
    233   SynFact<<out RuleExprNode expr>> =                                             LOCAL <<
     195  SynFact<out RuleExprNode expr> =                                               (.
    234196                                                                                   string identStr = "";
    235197                                                                                   RuleActionNode action = null;
    236198                                                                                   expr = null;
    237                                                                                  >>
    238     ident<<out identStr>> /* ActualAttrList */                                   SEM <<
     199                                                                                   string src = "";
     200                                                                                 .)
     201    (ident                                                                        (. identStr = t.val; .)
     202     SourceCode<out src>                                                          (.
    239203                                                                                    var callNode = new CallSymbolNode{Ident = identStr};
    240                                                                                     SourceReader.WithNext((src) => {callNode.ActualParameter = src;});
     204                                                                                    callNode.ActualParameter = src;
    241205                                                                                    expr = callNode;
    242                                                                                   >>
    243 --    | 'EPS'
    244 --    | '(' SynExpr<<ref rules, mBuilder>> ')'
    245 --    | '[' SynExpr<<ref rules, mBuilder>> ']'
    246 --    | '{' SynExpr<<ref rules, mBuilder>> '}'
    247     | SemAction<<out action>>                                                    SEM << expr = action; >>
     206                                                                                 .)
     207// not implemented   | "EPS"
     208// not implemented   | '(' SynExpr<ref rules, mBuilder> ')'
     209// not implemented   | '[' SynExpr<ref rules, mBuilder> ']'
     210// not implemented   | '{' SynExpr<ref rules, mBuilder> '}'
     211     | SemAction<out action>                                                      (. expr = action; .)
     212    )
    248213  .
    249214
  • branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/HeuristicLab.Problems.GPDL-3.4.csproj

    r9528 r9724  
    194194    <Compile Include="InterpreterBuilder.cs" />
    195195    <Compile Include="MethodBuilder.cs" />
     196    <Compile Include="Parser.cs" />
    196197    <Compile Include="ProblemGenerator.cs" />
     198    <Compile Include="Scanner.cs" />
    197199    <Compile Include="SourceReader.cs" />
    198200    <Compile Include="SymbolBuilder.cs" />
    199201    <None Include="GPDef.atg" />
    200202    <None Include="HeuristicLab.snk" />
    201     <Compile Include="Coco-2\Errors.cs" />
    202     <Compile Include="Coco-2\Sets.cs" />
    203     <Compile Include="Coco-2\Utils.cs" />
    204     <Compile Include="GPDefLex.cs" />
    205     <Compile Include="GPDefSem.cs" />
    206     <Compile Include="GPDefSyn.cs" />
    207203    <Compile Include="Plugin.cs" />
    208204    <Compile Include="Properties\AssemblyInfo.cs" />
     
    227223    </BootstrapperPackage>
    228224  </ItemGroup>
    229   <ItemGroup>
    230     <Content Include="GPDef.pgt.lst" />
    231     <Content Include="GPDef.sg.lst" />
    232   </ItemGroup>
    233225  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    234226  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  • branches/HeuristicLab.Problems.GPDL/SyntaxAnalyzer/GPDef.atg

    r9696 r9724  
     1$namespace=SyntaxAnalyzer
     2
    13COMPILER GPDefSyntaxAnalyzer
    24
    3 CHARACTER SETS
     5CHARACTERS
    46  letter = 'A'..'Z' + 'a'..'z'.
    57  digit = '0'..'9'.
    6   whiteSpace = CHR(9) + EOL IGNORE. /* ' ' ignored by default */
     8
     9TOKENS
     10  ident = letter {letter | digit} .
    711
    812COMMENTS
    9   FROM '/*' TO '*/' NESTED.
     13  FROM "/*" TO "*/" NESTED
    1014
    11 KEYWORDS
    12   'PROBLEM'. 'END'. 'EPS'.
    13   'LOCAL'. 'NONTERMINALS'. 'RULES'.
    14   'SEM'. 'MAXIMIZE'. 'MINIMIZE'. 'TERMINALS'. 'CONSTRAINTS'. 'INIT'. 'CODE'.
    15   'IN'. 'SET'. 'RANGE'.
     15IGNORE '\t' + '\r' + '\n'
    1616
    17 TOKENS
    18   '='. '|'. '.'. '('. ')'. '['. ']'. '{'. '}'. '>>'. '..'.
    19 
    20 TOKEN CLASSES
    21   ident = letter {letter | digit}.
    22 
    23 PRAGMAS
    24   source       = '<<' SEM <<for (; ; ) {
    25                               switch (GPDefSyntaxAnalyzerLex.curCh) {
    26                                 case Utils.EF:
    27                                   Errors.SemError(GPDefSyntaxAnalyzerLex.curLine, GPDefSyntaxAnalyzerLex.curCol, "end of file in source text");
    28                                   return;
    29                                 case '<':
    30                                   GPDefSyntaxAnalyzerLex.NextCh();
    31                                   if (GPDefSyntaxAnalyzerLex.curCh == '<') {
    32                                     Errors.Warning(GPDefSyntaxAnalyzerLex.curLine, GPDefSyntaxAnalyzerLex.curCol, "non closed source text before?");
    33                                     GPDefSyntaxAnalyzerLex.NextCh();
    34                                   }
    35                                   break;
    36                                 case '>':
    37                                   GPDefSyntaxAnalyzerLex.NextCh();
    38                                   if (GPDefSyntaxAnalyzerLex.curCh == '>') {
    39                                     GPDefSyntaxAnalyzerLex.curCh = ' ';          // force GPDefSyntaxAnalyzerLex to get next character
    40                                     return;
    41                                   }
    42                                   break;
    43                                 default:
    44                                   GPDefSyntaxAnalyzerLex.NextCh();
    45                                   break;
    46                               }
    47                             }>>
    48   .
    49 NONTERMINALS
    50   GPDefSyntaxAnalyzer.   
    51   SemDecl. SemAction. NonterminalDecl.
    52   RuleDef. SynExpr. SynTerm. SynFact. TerminalDecl.
    53   ConstraintDef. ConstraintRule. SetDefinition.
    54 
    55 RULES
     17PRODUCTIONS
    5618  GPDefSyntaxAnalyzer =
    57     'PROBLEM' ident
    58   ['CODE' /* SourceText */]
    59   ['INIT' /* SourceText */]
    60     'NONTERMINALS' { NonterminalDecl }
    61     'TERMINALS' { TerminalDecl }
    62     'RULES' { RuleDef }
    63     ('MAXIMIZE' | 'MINIMIZE') /* SourceText */
    64     'END' ident '.'.
     19    "PROBLEM" ident
     20    ["CODE" "<<" {ANY} ">>" ]
     21    ["INIT" "<<" {ANY} ">>" ]
     22    "NONTERMINALS" { NonterminalDecl }
     23    "TERMINALS" { TerminalDecl }
     24    "RULES" { RuleDef }
     25    ("MAXIMIZE" | "MINIMIZE") "<<" {ANY} ">>"
     26    "END" ident '.'.
    6527
    6628
    67   SemDecl = 'LOCAL' /* SourceText */
     29  SemDecl = "LOCAL" "<<" {ANY} ">>"
    6830  .
    6931
    70   SemAction = 'SEM' /* SourceText */
     32  SemAction = "SEM" "<<" {ANY} ">>"
    7133  .
    7234
    73   NonterminalDecl = ident /* FormalAttrList */ '.'
     35  NonterminalDecl = ident "<<" {ANY} ">>" '.'
    7436  .
    7537
    76   TerminalDecl = ident /* FormalAttrList */
    77     [ 'CONSTRAINTS' ConstraintDef ]
     38  TerminalDecl = ident "<<" {ANY} ">>"
     39    [ "CONSTRAINTS" ConstraintDef ]
    7840    '.'
    7941  .
    8042
    8143  ConstraintDef = { ConstraintRule }.
    82   ConstraintRule = ident 'IN' SetDefinition .
     44  ConstraintRule = ident "IN" SetDefinition .
    8345  SetDefinition =
    84     'SET' /* SourceText */
    85     | 'RANGE' /* SourceText */ '..' /* SourceText */
     46    "SET" "<<" {ANY} ">>"
     47    | "RANGE" "<<" {ANY} ">>" ".." "<<" {ANY} ">>"
    8648  .
    8749
    88   RuleDef = ident /* FormalAttrList */ '=' [SemDecl] SynExpr '.'
     50  RuleDef = ident "<<" {ANY} ">>" '=' [SemDecl] SynExpr '.'
    8951  .
    9052
    91   SynExpr = SynTerm {'|' SynTerm}
     53  SynExpr = SynTerm { '|' SynTerm }
    9254  .
    9355
    94   SynTerm = SynFact {SynFact}
     56  SynTerm = SynFact { SynFact }
    9557  .
    9658
    9759  SynFact =
    98     ident /* ActualAttrList */
    99     | 'EPS'
     60    ident "<<" {ANY} ">>"
     61    | "EPS"
    10062    | '(' SynExpr ')'
    10163    | '[' SynExpr ']'
  • branches/HeuristicLab.Problems.GPDL/SyntaxAnalyzer/SyntaxAnalyzer.csproj

    r9430 r9724  
    4242  </ItemGroup>
    4343  <ItemGroup>
    44     <Compile Include="Coco-2\Errors.cs" />
    45     <Compile Include="Coco-2\Sets.cs" />
    46     <Compile Include="Coco-2\Utils.cs" />
    47     <Compile Include="GPDefSyntaxAnalyzer.cs">
    48       <SubType>Code</SubType>
    49     </Compile>
    50     <Compile Include="GPDefSyntaxAnalyzerLex.cs" />
    51     <Compile Include="GPDefSyntaxAnalyzerSem.cs" />
    52     <Compile Include="GPDefSyntaxAnalyzerSyn.cs" />
     44    <Compile Include="GPDefSyntaxAnalyzer.cs" />
     45    <Compile Include="Parser.cs" />
    5346    <Compile Include="Properties\AssemblyInfo.cs" />
     47    <Compile Include="Scanner.cs" />
    5448  </ItemGroup>
    5549  <ItemGroup>
     
    5751  </ItemGroup>
    5852  <ItemGroup>
    59     <Content Include="GPDef.pgt.lst" />
    60     <Content Include="GPDef.sg.lst" />
     53    <Folder Include="Coco-2\" />
    6154  </ItemGroup>
    6255  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Note: See TracChangeset for help on using the changeset viewer.