$namespace=HeuristicLab.Problems.GPDL using System.Text; using System.Collections.Generic; using IEnumerableConstraintNode = System.Collections.Generic.IEnumerable; COMPILER GPDef public static HeuristicLab.Optimization.IProblem problem; CHARACTERS letter = 'A'..'Z' + 'a'..'z'. digit = '0'..'9'. TOKENS ident = letter {letter | digit} . COMMENTS FROM "/*" TO "*/" NESTED IGNORE '\t' + '\r' + '\n' PRODUCTIONS SourceCode = (. src = ""; .) "<<" (. int beg = la.pos; .) {ANY} (. int end = la.pos; .) ">>" (. if(end>beg) src = scanner.buffer.GetString(beg, end); .) . GPDef = (. RuleNode ruleNode = null; GPDefNode gpDef = new GPDefNode(); NonTerminalNode ntNode = null; FitnessFunctionNode fitnessFunNode = null; TerminalNode tNode = null; problem = null; string src = ""; .) "PROBLEM" ident (. gpDef.Name = t.val; .) ["CODE" SourceCode (. gpDef.ClassCodeNode = new CodeNode{SrcCode = src}; .) ] ["INIT" SourceCode (. gpDef.InitCodeNode = new CodeNode{SrcCode = src}; .) ] "NONTERMINALS" { NonterminalDecl (. gpDef.NonTerminals.Add(ntNode); .) } "TERMINALS" { TerminalDecl (. gpDef.Terminals.Add(tNode); .) } "RULES" { RuleDef (. gpDef.Rules.Add(ruleNode); .) } (. fitnessFunNode = new FitnessFunctionNode(); gpDef.FitnessFunctionNode = fitnessFunNode; .) ("MAXIMIZE" (. fitnessFunNode.Maximization = true; .) | "MINIMIZE" (. fitnessFunNode.Maximization = false; .) ) SourceCode (. fitnessFunNode.SrcCode = src; .) "END" ident (. // SourceReader.Handle(GPDefSem.srcText.ToString()); // flush the source reader var gen = new ProblemGenerator(); problem = gen.GenerateFromAst(gpDef); .) '.' . /******************************************************/ SemAction = (. RuleActionNode myAction = null; action = null; string src = ""; .) "SEM" SourceCode (. myAction = new RuleActionNode(); myAction.SrcCode = src; action = myAction; .) . /******************************************************/ NonterminalDecl = (. string identStr = ""; ntNode = null; string src = ""; .) ident (. identStr = t.val; .) [ SourceCode ] (. var myNtNode = new NonTerminalNode(); ntNode = myNtNode; myNtNode.Ident = identStr; myNtNode.FormalParameters = src; .) '.' . /******************************************************/ TerminalDecl = (. string identStr = ""; tNode = null; TerminalNode myTNode = null; IEnumerableConstraintNode constraints = null; string src = ""; .) ident (. identStr = t.val; .) [ SourceCode ] (. myTNode = new TerminalNode(); tNode = myTNode; myTNode.Ident = identStr; myTNode.FormalParameters = src; myTNode.FieldDefinitions = SourceReader.ExtractFormalParameters(src); .) [ "CONSTRAINTS" ConstraintDef (. myTNode.Constraints = constraints; .) ] '.' . /******************************************************/ ConstraintDef = (. List constraintsList = new List(); ConstraintNode n = null; constraints = null; .) { ConstraintRule (. constraintsList.Add(n); .) } (. constraints = constraintsList; .) . /******************************************************/ ConstraintRule = (. constraint = null; .) ident (. constraint = new ConstraintNode(t.val); .) "IN" SetDefinition // (. SourceReader.Handle(GPDefSem.srcText.ToString()); .) // flush the source reader . /******************************************************/ SetDefinition = (. string src = ""; .) ("SET" (. constraint.Type = ConstraintNodeType.Set; .) SourceCode (. constraint.SetExpression = src; .) | "RANGE" (. constraint.Type = ConstraintNodeType.Range; .) SourceCode (. constraint.RangeMinExpression = src; .) ".." SourceCode (. // SourceReader.Handle(GPDefSem.srcText.ToString()); // flush the source reader constraint.RangeMaxExpression = src; .) ) . /******************************************************/ RuleDef = (. RuleExprNode expr = null; string identStr = null; RuleNode myRule = null; rule = null; string src = ""; .) ident (. identStr = t.val; .) [ SourceCode ] '=' (. myRule = new RuleNode(); rule = myRule; myRule.NtSymbol = identStr; .) ["LOCAL" SourceCode (. myRule.LocalCode = src; .) ] SynExpr '.' (. myRule.RuleExpr = expr; .) . /******************************************************/ SynExpr = (. expr = null; AlternativesNode alt = null; .) SynTerm (. alt = new AlternativesNode(); alt.Add(expr); .) { '|' SynTerm (. alt.Add(expr); expr = alt; .) } . /******************************************************/ SynTerm = (. SequenceNode seq = null; expr = null; .) SynFact (. seq = new SequenceNode(); seq.Add(expr); .) { SynFact (. seq.Add(expr); expr = seq; .) } . /******************************************************/ SynFact = (. string identStr = ""; RuleActionNode action = null; expr = null; string src = ""; .) (ident (. identStr = t.val; .) [ SourceCode ] (. var callNode = new CallSymbolNode{Ident = identStr}; callNode.ActualParameter = src; expr = callNode; .) // not implemented | "EPS" // not implemented | '(' SynExpr ')' // not implemented | '[' SynExpr ']' // not implemented | '{' SynExpr '}' | SemAction (. expr = action; .) ) . END GPDef.