Changeset 9724
- Timestamp:
- 07/19/13 00:31:12 (12 years ago)
- 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 1 cd %SolutionDir%\CocoR 2 Coco -frames . %ProjectDir%\GPDef.atg 4 3 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 4 2 // ----- 5 3 // Main program for compiler generated from GpdlCompiler.atg with Coco-2. … … 7 5 8 6 using System; 9 using System.IO; 10 11 using Lex = GPDefLex; 12 using Syn = GPDefSyn; 7 using HeuristicLab.Problems.GPDL; 13 8 14 9 public class GpdlCompiler { 15 10 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 } // if33 Environment.Exit(Utils.EXIT_FAILURE);34 } // Abort35 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/catch45 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/catch63 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 listing68 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/finally76 Console.WriteLine("{0} error(s) detected", Errors.NumOfErrors());77 }78 finally {79 lstWriter.Close();80 lstWriter.Dispose();81 } // try/finally82 } else83 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 } // if91 Utils.Modules(Utils.ModuleAction.resetModule);92 } // try/finally to make sure srcFs and srcReader are closed93 return Utils.EXIT_SUCCESS;94 } // CompileFile95 96 97 11 public static void Main(String[] args) { 98 12 //-----------------------------------|---------------------------------------- 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 } 100 20 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 57 57 } 58 58 59 private void textEditor_MouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e) {59 private void textEditor_MouseWheel(object sender, MouseWheelEventArgs e) { 60 60 } 61 61 62 private void textEditor_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) {62 private void textEditor_KeyDown(object sender, KeyEventArgs e) { 63 63 if (e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl) controlHeld = true; 64 64 } … … 70 70 internal void SetLexError(string msg, int line, int col) { 71 71 errorLineTransformer.MarkLexError(msg, line, col); 72 textEditor. InvalidateVisual();72 textEditor.TextArea.TextView.Redraw(); 73 73 } 74 74 75 75 internal void SetSynError(string msg, int line, int col) { 76 76 errorLineTransformer.MarkSynError(msg, line, col); 77 textEditor. InvalidateVisual();77 textEditor.TextArea.TextView.Redraw(); 78 78 } 79 79 80 80 internal void ClearErrors() { 81 81 errorLineTransformer.ClearErrors(); 82 textEditor. InvalidateVisual();82 textEditor.TextArea.TextView.Redraw(); 83 83 } 84 84 -
branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL.Views/3.4/GpdlEditor.cs
r9674 r9724 2 2 using System.IO; 3 3 using System.Linq; 4 using System.Text; 4 5 using HeuristicLab.MainForm.WindowsForms; 5 6 using HeuristicLab.Problems.Instances; … … 19 20 20 21 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); 24 25 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); 28 29 29 // --- initialize modules ---30 Utils.Modules(Utils.ModuleAction.initModule);30 //// --- initialize modules --- 31 //Utils.Modules(Utils.ModuleAction.initModule); 31 32 32 Errors.PushAbortMethod(new Errors.AbortMethod(Abort));33 //Errors.PushAbortMethod(new Errors.AbortMethod(Abort)); 33 34 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(); 37 39 } 38 40 39 41 codeEditor.ClearErrors(); 40 42 41 if (Errors.NumOfErrors() == 0) {42 GPDefLex.InitLex();43 GPDefSyn.Interpret();43 //if (Errors.NumOfErrors() == 0) { 44 // GPDefLex.InitLex(); 45 // GPDefSyn.Interpret(); 44 46 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 //} 58 60 } 59 61 -
branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/GPDef.atg
r9430 r9724 1 $namespace=HeuristicLab.Problems.GPDL 2 3 using System.Text; 4 using System.Collections.Generic; 5 using IEnumerableConstraintNode = System.Collections.Generic.IEnumerable<ConstraintNode>; 6 1 7 COMPILER GPDef 2 SEM <<3 8 static StringBuilder srcText; 4 9 public static HeuristicLab.Optimization.IProblem problem; 5 >> 6 7 8 CHARACTER SETS 10 static string lastSrc; 11 12 CHARACTERS 9 13 letter = 'A'..'Z' + 'a'..'z'. 10 14 digit = '0'..'9'. 11 whiteSpace = CHR(9) + EOL IGNORE. /* ' ' ignored by default */ 15 16 TOKENS 17 ident = letter {letter | digit} . 12 18 13 19 COMMENTS 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 22 IGNORE '\t' + '\r' + '\n' 23 24 25 PRODUCTIONS 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 = (. 77 34 string identStr = ""; 78 35 RuleNode ruleNode = null; … … 82 39 TerminalNode tNode = null; 83 40 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}; .) 87 45 ] 88 [ 'INIT' /* SourceText */ SEM << SourceReader.WithNext((src) => gpDef.InitCodeNode = new CodeNode{SrcCode = src}); >>46 ["INIT" SourceCode<out src> (. gpDef.InitCodeNode = new CodeNode{SrcCode = src}; .) 89 47 ] 90 48 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(); 98 56 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; .) 102 60 ) 103 /* SourceText */ SEM << SourceReader.WithNext((src) => fitnessFunNode.SrcCode = src); >>104 'END' ident<<out identStr>> '.' SEM <<105 SourceReader.Handle(GPDefSem.srcText.ToString()); // flush the source reader61 SourceCode<out src> (. fitnessFunNode.SrcCode = src; .) 62 "END" ident (. 63 // SourceReader.Handle(GPDefSem.srcText.ToString()); // flush the source reader 106 64 var gen = new ProblemGenerator(); 107 65 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> (. 115 74 myAction = new RuleActionNode(); 116 SourceReader.WithNext((src) => {myAction.SrcCode = src;});75 myAction.SrcCode = src; 117 76 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> (. 124 84 var myNtNode = new NonTerminalNode(); 125 85 ntNode = myNtNode; 126 86 myNtNode.Ident = identStr; 127 SourceReader.WithNext((src) => {myNtNode.FormalParameters = src;});128 >>87 myNtNode.FormalParameters = src; 88 .) 129 89 '.' 130 90 . 131 91 132 92 /******************************************************/ 133 TerminalDecl< <out TerminalNode tNode>> = LOCAL <<93 TerminalDecl<out TerminalNode tNode> = (. 134 94 string identStr = ""; 135 95 tNode = null; 136 96 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> (. 140 102 myTNode = new TerminalNode(); 141 103 tNode = myTNode; 142 104 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; .) 150 109 ] 151 110 '.' … … 154 113 155 114 /******************************************************/ 156 ConstraintDef< <out IEnumerable<ConstraintNode> constraints>> = LOCAL <<115 ConstraintDef<out IEnumerableConstraintNode constraints> = (. 157 116 List<ConstraintNode> constraintsList = new List<ConstraintNode>(); 158 117 ConstraintNode n = null; 159 118 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> = (. 168 127 string identStr = null; 169 128 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> = (. 188 148 RuleExprNode expr = null; 189 149 string identStr = null; 190 150 RuleNode myRule = null; 191 151 rule = null; 192 >> 193 ident<<out identStr>> /* FormalAttrList */ '=' SEM << 152 string src = ""; 153 .) 154 ident (. identStr = t.val; .) 155 SourceCode<out src> '=' (. 194 156 myRule = new RuleNode(); 195 157 rule = myRule; 196 158 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 .) 201 163 ] 202 SynExpr< <out expr>> '.' SEM <<164 SynExpr<out expr> '.' (. 203 165 myRule.RuleExpr = expr; 204 >>205 . 206 207 /******************************************************/ 208 SynExpr< <out RuleExprNode expr >> = LOCAL <<166 .) 167 . 168 169 /******************************************************/ 170 SynExpr<out RuleExprNode expr > = (. 209 171 expr = null; 210 172 AlternativesNode alt = null; 211 >>212 SynTerm< <out expr>> SEM <<173 .) 174 SynTerm<out expr> (. 213 175 alt = new AlternativesNode(); 214 176 alt.Add(expr); 215 >>177 .) 216 178 { 217 '|' SynTerm< <out expr>> SEM << alt.Add(expr); expr = alt; >>179 '|' SynTerm<out expr> (. alt.Add(expr); expr = alt; .) 218 180 } 219 181 . 220 182 221 183 /******************************************************/ 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> (. 224 186 seq = new SequenceNode(); 225 187 seq.Add(expr); 226 >>188 .) 227 189 { 228 SynFact< <out expr>> SEM << seq.Add(expr); expr = seq; >>190 SynFact<out expr> (. seq.Add(expr); expr = seq; .) 229 191 } 230 192 . 231 193 232 194 /******************************************************/ 233 SynFact< <out RuleExprNode expr>> = LOCAL <<195 SynFact<out RuleExprNode expr> = (. 234 196 string identStr = ""; 235 197 RuleActionNode action = null; 236 198 expr = null; 237 >> 238 ident<<out identStr>> /* ActualAttrList */ SEM << 199 string src = ""; 200 .) 201 (ident (. identStr = t.val; .) 202 SourceCode<out src> (. 239 203 var callNode = new CallSymbolNode{Ident = identStr}; 240 SourceReader.WithNext((src) => {callNode.ActualParameter = src;});204 callNode.ActualParameter = src; 241 205 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 ) 248 213 . 249 214 -
branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/HeuristicLab.Problems.GPDL-3.4.csproj
r9528 r9724 194 194 <Compile Include="InterpreterBuilder.cs" /> 195 195 <Compile Include="MethodBuilder.cs" /> 196 <Compile Include="Parser.cs" /> 196 197 <Compile Include="ProblemGenerator.cs" /> 198 <Compile Include="Scanner.cs" /> 197 199 <Compile Include="SourceReader.cs" /> 198 200 <Compile Include="SymbolBuilder.cs" /> 199 201 <None Include="GPDef.atg" /> 200 202 <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" />207 203 <Compile Include="Plugin.cs" /> 208 204 <Compile Include="Properties\AssemblyInfo.cs" /> … … 227 223 </BootstrapperPackage> 228 224 </ItemGroup> 229 <ItemGroup>230 <Content Include="GPDef.pgt.lst" />231 <Content Include="GPDef.sg.lst" />232 </ItemGroup>233 225 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 234 226 <!-- 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 1 3 COMPILER GPDefSyntaxAnalyzer 2 4 3 CHARACTER SETS5 CHARACTERS 4 6 letter = 'A'..'Z' + 'a'..'z'. 5 7 digit = '0'..'9'. 6 whiteSpace = CHR(9) + EOL IGNORE. /* ' ' ignored by default */ 8 9 TOKENS 10 ident = letter {letter | digit} . 7 11 8 12 COMMENTS 9 FROM '/*' TO '*/' NESTED.13 FROM "/*" TO "*/" NESTED 10 14 11 KEYWORDS 12 'PROBLEM'. 'END'. 'EPS'. 13 'LOCAL'. 'NONTERMINALS'. 'RULES'. 14 'SEM'. 'MAXIMIZE'. 'MINIMIZE'. 'TERMINALS'. 'CONSTRAINTS'. 'INIT'. 'CODE'. 15 'IN'. 'SET'. 'RANGE'. 15 IGNORE '\t' + '\r' + '\n' 16 16 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 17 PRODUCTIONS 56 18 GPDefSyntaxAnalyzer = 57 'PROBLEM'ident58 ['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 '.'. 65 27 66 28 67 SemDecl = 'LOCAL' /* SourceText */29 SemDecl = "LOCAL" "<<" {ANY} ">>" 68 30 . 69 31 70 SemAction = 'SEM' /* SourceText */32 SemAction = "SEM" "<<" {ANY} ">>" 71 33 . 72 34 73 NonterminalDecl = ident /* FormalAttrList */'.'35 NonterminalDecl = ident "<<" {ANY} ">>" '.' 74 36 . 75 37 76 TerminalDecl = ident /* FormalAttrList */77 [ 'CONSTRAINTS'ConstraintDef ]38 TerminalDecl = ident "<<" {ANY} ">>" 39 [ "CONSTRAINTS" ConstraintDef ] 78 40 '.' 79 41 . 80 42 81 43 ConstraintDef = { ConstraintRule }. 82 ConstraintRule = ident 'IN'SetDefinition .44 ConstraintRule = ident "IN" SetDefinition . 83 45 SetDefinition = 84 'SET' /* SourceText */85 | 'RANGE' /* SourceText */ '..' /* SourceText */46 "SET" "<<" {ANY} ">>" 47 | "RANGE" "<<" {ANY} ">>" ".." "<<" {ANY} ">>" 86 48 . 87 49 88 RuleDef = ident /* FormalAttrList */'=' [SemDecl] SynExpr '.'50 RuleDef = ident "<<" {ANY} ">>" '=' [SemDecl] SynExpr '.' 89 51 . 90 52 91 SynExpr = SynTerm { '|' SynTerm}53 SynExpr = SynTerm { '|' SynTerm } 92 54 . 93 55 94 SynTerm = SynFact { SynFact}56 SynTerm = SynFact { SynFact } 95 57 . 96 58 97 59 SynFact = 98 ident /* ActualAttrList */99 | 'EPS'60 ident "<<" {ANY} ">>" 61 | "EPS" 100 62 | '(' SynExpr ')' 101 63 | '[' SynExpr ']' -
branches/HeuristicLab.Problems.GPDL/SyntaxAnalyzer/SyntaxAnalyzer.csproj
r9430 r9724 42 42 </ItemGroup> 43 43 <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" /> 53 46 <Compile Include="Properties\AssemblyInfo.cs" /> 47 <Compile Include="Scanner.cs" /> 54 48 </ItemGroup> 55 49 <ItemGroup> … … 57 51 </ItemGroup> 58 52 <ItemGroup> 59 <Content Include="GPDef.pgt.lst" /> 60 <Content Include="GPDef.sg.lst" /> 53 <Folder Include="Coco-2\" /> 61 54 </ItemGroup> 62 55 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Note: See TracChangeset
for help on using the changeset viewer.