#region License Information
/* HeuristicLab
* Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class GPDefNode {
public string Name { get; set; }
public CodeNode ClassCodeNode { get; set; }
public CodeNode InitCodeNode { get; set; }
public List NonTerminals { get; private set; }
public List Terminals { get; private set; }
public List Rules { get; private set; }
public FitnessFunctionNode FitnessFunctionNode { get; set; }
public GPDefNode() {
this.NonTerminals = new List();
this.Terminals = new List();
this.Rules = new List();
this.ClassCodeNode = new CodeNode();
this.InitCodeNode = new CodeNode();
}
public bool IsSymbolDefined(SymbolNode n) {
return NonTerminals.Any(s => s.Ident == n.Ident) ||
Terminals.Any(s => s.Ident == n.Ident);
}
public bool IsNonTerminalDefined(string ntIdent) {
return NonTerminals.Any(s => s.Ident == ntIdent);
}
public bool IsRuleDefined(RuleNode n) {
return IsRuleDefined(n.NtSymbol);
}
public bool IsRuleDefined(string ntSymbol) {
return Rules.Any(r => r.NtSymbol == ntSymbol);
}
public string UndefinedNonTerminals() {
var sb = new StringBuilder();
foreach (var nt in NonTerminals) {
if (!IsRuleDefined(nt.Ident)) {
sb.AppendFormat("{0} ", nt.Ident);
}
}
return sb.ToString();
}
}
public class CodeNode {
public string SrcCode { get; set; }
}
public class FitnessFunctionNode {
public bool Maximization { get; set; }
public string SrcCode { get; set; }
}
public class SymbolNode {
public string Ident { get; set; }
public string FormalParameters { get; set; }
}
public class NonTerminalNode : SymbolNode {
}
public class TerminalNode : SymbolNode {
public class FieldDefinition {
private readonly string refOrOut;
private readonly string type;
private readonly string identifier;
public FieldDefinition(string refOrOut, string type, string identifier) {
this.type = type;
this.identifier = identifier;
this.refOrOut = refOrOut;
}
public string RefOrOut { get { return this.refOrOut; } }
public string Type { get { return this.type; } }
public string Identifier { get { return this.identifier; } }
}
public IEnumerable Constraints { get; set; }
public IEnumerable FieldDefinitions { get; set; }
}
public enum ConstraintNodeType { Set, Range };
public class ConstraintNode {
public string Ident { get; set; }
public ConstraintNodeType Type { get; set; }
public string SetExpression { get; set; }
public string RangeMinExpression { get; set; }
public string RangeMaxExpression { get; set; }
public ConstraintNode(string ident) {
this.Ident = ident;
}
}
public class RuleNode {
public string NtSymbol { get; set; }
public string LocalCode { get; set; }
public AlternativesNode Alternatives { get; set; }
}
public class RuleExprNode { }
public class AlternativesNode : RuleExprNode {
private List alt;
public IEnumerable Alternatives { get { return alt; } }
public AlternativesNode() {
this.alt = new List();
}
public void Add(SequenceNode expr) {
alt.Add(expr);
}
}
public class SequenceNode : RuleExprNode {
private readonly List seq;
public IEnumerable Sequence { get { return seq; } }
public SequenceNode() {
seq = new List();
}
public void Add(RuleExprNode expr) {
seq.Add(expr);
}
}
public class CallSymbolNode : RuleExprNode {
public string Ident { get; set; }
public string ActualParameter { get; set; }
}
public class RuleActionNode : RuleExprNode {
public string SrcCode { get; set; }
}