Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/AST.cs

Last change on this file was 10067, checked in by gkronber, 11 years ago

#2026 worked on brute force solver for GPDL problems.

File size: 4.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Collections.Generic;
23using System.Linq;
24using System.Text;
25
26public class GPDefNode {
27  public string Name { get; set; }
28  public CodeNode ClassCodeNode { get; set; }
29  public CodeNode InitCodeNode { get; set; }
30  public List<SymbolNode> NonTerminals { get; private set; }
31  public List<SymbolNode> Terminals { get; private set; }
32  public List<RuleNode> Rules { get; private set; }
33  public FitnessFunctionNode FitnessFunctionNode { get; set; }
34
35  public GPDefNode() {
36    this.NonTerminals = new List<SymbolNode>();
37    this.Terminals = new List<SymbolNode>();
38    this.Rules = new List<RuleNode>();
39    this.ClassCodeNode = new CodeNode();
40    this.InitCodeNode = new CodeNode();
41  }
42
43  public bool IsSymbolDefined(SymbolNode n) {
44    return NonTerminals.Any(s => s.Ident == n.Ident) ||
45           Terminals.Any(s => s.Ident == n.Ident);
46  }
47  public bool IsNonTerminalDefined(string ntIdent) {
48    return NonTerminals.Any(s => s.Ident == ntIdent);
49  }
50  public bool IsRuleDefined(RuleNode n) {
51    return IsRuleDefined(n.NtSymbol);
52  }
53  public bool IsRuleDefined(string ntSymbol) {
54    return Rules.Any(r => r.NtSymbol == ntSymbol);
55  }
56  public string UndefinedNonTerminals() {
57    var sb = new StringBuilder();
58    foreach (var nt in NonTerminals) {
59      if (!IsRuleDefined(nt.Ident)) {
60        sb.AppendFormat("{0} ", nt.Ident);
61      }
62    }
63    return sb.ToString();
64  }
65}
66
67public class CodeNode {
68  public string SrcCode { get; set; }
69}
70
71public class FitnessFunctionNode {
72  public bool Maximization { get; set; }
73  public string SrcCode { get; set; }
74}
75
76public class SymbolNode {
77  public string Ident { get; set; }
78  public string FormalParameters { get; set; }
79
80}
81
82public class NonTerminalNode : SymbolNode {
83}
84
85public class TerminalNode : SymbolNode {
86  public class FieldDefinition {
87    private readonly string refOrOut;
88    private readonly string type;
89    private readonly string identifier;
90
91    public FieldDefinition(string refOrOut, string type, string identifier) {
92      this.type = type;
93      this.identifier = identifier;
94      this.refOrOut = refOrOut;
95    }
96    public string RefOrOut { get { return this.refOrOut; } }
97    public string Type { get { return this.type; } }
98    public string Identifier { get { return this.identifier; } }
99  }
100  public IEnumerable<ConstraintNode> Constraints { get; set; }
101  public IEnumerable<FieldDefinition> FieldDefinitions { get; set; }
102}
103
104
105public enum ConstraintNodeType { Set, Range };
106public class ConstraintNode {
107  public string Ident { get; set; }
108  public ConstraintNodeType Type { get; set; }
109  public string SetExpression { get; set; }
110  public string RangeMinExpression { get; set; }
111  public string RangeMaxExpression { get; set; }
112  public ConstraintNode(string ident) {
113    this.Ident = ident;
114  }
115}
116
117public class RuleNode {
118  public string NtSymbol { get; set; }
119  public string LocalCode { get; set; }
120  public AlternativesNode Alternatives { get; set; }
121}
122
123public class RuleExprNode { }
124
125public class AlternativesNode : RuleExprNode {
126  private List<SequenceNode> alt;
127  public IEnumerable<SequenceNode> Alternatives { get { return alt; } }
128  public AlternativesNode() {
129    this.alt = new List<SequenceNode>();
130  }
131  public void Add(SequenceNode expr) {
132    alt.Add(expr);
133  }
134}
135
136public class SequenceNode : RuleExprNode {
137  private readonly List<RuleExprNode> seq;
138  public IEnumerable<RuleExprNode> Sequence { get { return seq; } }
139  public SequenceNode() {
140    seq = new List<RuleExprNode>();
141  }
142  public void Add(RuleExprNode expr) {
143    seq.Add(expr);
144  }
145}
146
147public class CallSymbolNode : RuleExprNode {
148  public string Ident { get; set; }
149  public string ActualParameter { get; set; }
150}
151
152public class RuleActionNode : RuleExprNode {
153  public string SrcCode { get; set; }
154}
Note: See TracBrowser for help on using the repository browser.