1 | using System.Collections.Generic;
|
---|
2 | using System;
|
---|
3 | using System.Text;
|
---|
4 |
|
---|
5 | public class GPDefNode {
|
---|
6 | public string Name { get; set; }
|
---|
7 | public CodeNode ClassCodeNode { get; set; }
|
---|
8 | public CodeNode InitCodeNode { get; set; }
|
---|
9 | public List<SymbolNode> NonTerminals { get; private set; }
|
---|
10 | public List<SymbolNode> Terminals { get; private set; }
|
---|
11 | public List<RuleNode> Rules { get; private set; }
|
---|
12 | public FitnessFunctionNode FitnessFunctionNode { get; set; }
|
---|
13 |
|
---|
14 | public GPDefNode() {
|
---|
15 | this.NonTerminals = new List<SymbolNode>();
|
---|
16 | this.Terminals = new List<SymbolNode>();
|
---|
17 | this.Rules = new List<RuleNode>();
|
---|
18 | this.ClassCodeNode = new CodeNode();
|
---|
19 | this.InitCodeNode = new CodeNode();
|
---|
20 | }
|
---|
21 | }
|
---|
22 |
|
---|
23 | public class CodeNode {
|
---|
24 | public string SrcCode { get; set; }
|
---|
25 | }
|
---|
26 |
|
---|
27 | public class FitnessFunctionNode {
|
---|
28 | public bool Maximization { get; set; }
|
---|
29 | public string SrcCode { get; set; }
|
---|
30 | }
|
---|
31 |
|
---|
32 | public class SymbolNode {
|
---|
33 | public string Ident { get; set; }
|
---|
34 | public string FormalParameters { get; set; }
|
---|
35 |
|
---|
36 | }
|
---|
37 |
|
---|
38 | public class NonTerminalNode : SymbolNode {
|
---|
39 | }
|
---|
40 |
|
---|
41 | public class TerminalNode : SymbolNode {
|
---|
42 | public class FieldDefinition {
|
---|
43 | private readonly string refOrOut;
|
---|
44 | private readonly string type;
|
---|
45 | private readonly string identifier;
|
---|
46 |
|
---|
47 | public FieldDefinition(string refOrOut, string type, string identifier) {
|
---|
48 | this.type = type;
|
---|
49 | this.identifier = identifier;
|
---|
50 | this.refOrOut = refOrOut;
|
---|
51 | }
|
---|
52 | public string RefOrOut { get { return this.refOrOut; } }
|
---|
53 | public string Type { get { return this.type; } }
|
---|
54 | public string Identifier { get { return this.identifier; } }
|
---|
55 | }
|
---|
56 | public IEnumerable<ConstraintNode> Constraints { get; set; }
|
---|
57 | public IEnumerable<FieldDefinition> FieldDefinitions { get; set; }
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 | public enum ConstraintNodeType { Set, Range };
|
---|
62 | public class ConstraintNode {
|
---|
63 | public string Ident { get; set; }
|
---|
64 | public ConstraintNodeType Type { get; set; }
|
---|
65 | public string SetExpression { get; set; }
|
---|
66 | public string RangeMinExpression { get; set; }
|
---|
67 | public string RangeMaxExpression { get; set; }
|
---|
68 | public ConstraintNode(string ident) {
|
---|
69 | this.Ident = ident;
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | public class RuleNode {
|
---|
74 | public string NtSymbol { get; set; }
|
---|
75 | public string LocalCode { get; set; }
|
---|
76 | public RuleExprNode RuleExpr { get; set; }
|
---|
77 | }
|
---|
78 |
|
---|
79 | public class RuleExprNode { }
|
---|
80 |
|
---|
81 | public class AlternativesNode : RuleExprNode {
|
---|
82 | private List<RuleExprNode> alt;
|
---|
83 | public IEnumerable<RuleExprNode> Alternatives { get { return alt; } }
|
---|
84 | public AlternativesNode() {
|
---|
85 | this.alt = new List<RuleExprNode>();
|
---|
86 | }
|
---|
87 | public void Add(RuleExprNode expr) {
|
---|
88 | alt.Add(expr);
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | public class SequenceNode : RuleExprNode {
|
---|
93 | private readonly List<RuleExprNode> seq;
|
---|
94 | public IEnumerable<RuleExprNode> Sequence { get { return seq; } }
|
---|
95 | public SequenceNode() {
|
---|
96 | seq = new List<RuleExprNode>();
|
---|
97 | }
|
---|
98 | public void Add(RuleExprNode expr) {
|
---|
99 | seq.Add(expr);
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | public class CallSymbolNode : RuleExprNode {
|
---|
104 | public string Ident { get; set; }
|
---|
105 | public string ActualParameter { get; set; }
|
---|
106 | }
|
---|
107 |
|
---|
108 | public class RuleActionNode : RuleExprNode {
|
---|
109 | public string SrcCode { get; set; }
|
---|
110 | } |
---|